What i want do, is to generate a .log file that describes all my error, start time, end time, and so one. I found a way to have something like that but not in corect way.
I want to generate that file automaticaly, without being required to define it manually.
From what i have understood, is that UTL_FILE.FOPEN, when is not found that file, create one.
My app. is working. The question is, HOW TO GENERATE A FILE IN PLSQL (.log file) without create it manually.
create or replace procedure read_files(input varchar2) as
begin
declare
F2 UTL_FILE.FILE_TYPE;
F2 := UTL_FILE.FOPEN('FOLDER',input||'.log','w');
UTL_FILE.put_line(F2,'Start processing file at : ' || systimestamp);
UTL_FILE.put_line(F2,'End processing file at :'||systimestamp);
-- Close file
UTL_FILE.FCLOSE(F2);
END; --end begin
I found the probleme ! Where I stored my files, I had no right to create files / folders. THANKS all !
Related
Apologies, I am quite new with AHK.
Context: I am trying to build a small program (eventually with UI) which will clean data in .XLF files in order to be processed properly by a CAT tool interpreter (import into it).
By "clean" I mean to find HTML attributes and replace them with their respective Char Entities. This as a single script; writing the name of the file or path inside the script is working perfectly.
Problem: I would like to run my .ahk/.exe allowing the user to open the file manager/explorer and select the file that needs to be processed by the script (find/replace html attributes with char entities) selecting the file is not working. Nothing is populated (the final file/result is empty) I'm trying to sort out this with FileSelectFile function and store the output var value (selecting the file) in the first instruction "fileread, selectedfile".
But it's not working! If I don't do this and I only provide in the default directory "A_ScriptDir" an specific file name .xf -> this works fine.
This is my code so far w/comments:
SetWorkingDir, %A_ScriptDir%
FileEncoding, UTF-8
;NoEnv
;Open Window File Manager/Explorer and select a file .xlf file
FileSelectFile, SelectedFile, 8, , Open a file, , ,(*.xlf)
;--- > HTML attribute '&' must be replaced by its char entity first/overall otherwise this instruction will overwrite the amp entities from the rest of char entities corrupting the file;
;"SelectedFile" can be any filename such as "example.xlf" but this is not my scope
fileread, text, SelectedFile ;previously "text.xlf" with random html content to do tests
replace := "&"
newtext := strreplace(text, "&", replace, all)
sleep, 200
filedelete, newtest.xlf
fileappend, %newtext%, newtest.xlf
;--------------------------------- <b>
;here "fileread" must read the final appended file as solution to use "streplace" function multiple times (replace more than one desired string) running the script at the same time. (due to my lack of exp. with loop function)
fileread, text, newtest.xlf
replace := ">b<"
newtext := strreplace(text, "<b>", replace, all)
filedelete, newtest.xlf
fileappend, %newtext%, newtest.xlf
I've been thinking that other solution can be:
I am still new to understand apply Drag and Drop GUI but I am unsure how to modify my code in order to drag/drop a file onto the ahk.exe
Thanks for your time reading this! any tip and/or help would be super appreciated :)
The FileRead command expects text, not an input variable.
So if you add % around SelectedFile like this, it should work:
FileRead, text, %SelectedFile%
If that doesn't work, it means the file does not exist or an error occurred. In that, you'll want to look at FileRead's error handling section.
I have a folder in the server
/home/test/pictures
There are multiple .jpg files inside this pictures folder.
I want to delete these files from this pictures using plsql.
Is there a utility for this ?
you can use UTL_FILE.FREMOVE function this function will remove files from a directory, here is the parameters for the function UTL_FILE.FREMOVE (location IN VARCHAR2,filename IN VARCHAR2)
location should be in ALL_DIRECTORIES view
so calling a function would be like this:
begin
UTL_FILE.FREMOVE('C:\','TEXT.TXT');--this will remove text.txt from C drive
end;
you can read this article https://docs.oracle.com/cd/B28359_01/appdev.111/b28419/u_file.htm#BABEGHIG
I have a file in my D: drive of my computer and I want to copy this file to an SAP application server so that I am able to see my file with transaction AL11.
I know that I can create a file with AL11 but I want do this in ABAP.
Of course in my search I find this code but I cannot solve my problem with it.
data: unixcom like rlgrap-filename.
data: begin of tabl occurs 500,
line(400),
end of tabl.
dir =
unixcom = 'mkdir mydir'. "command to create dir
"to execute the unix command
call 'SYSTEM' id 'COMMAND' field unixcom
id 'TAB' field tabl[].
To upload the file to the application server, there are three steps to be followed. To open the file use the below statement:
Step1: OPEN DATASET file name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
To write into the application server use.
Step2: TRANSFER name TO file name.
Dont forget to close the file once it is transferred.
Step3: CLOSE DATASET file name.
Plese mark with correct answer, if it helps! :)
If you want to do this using ABAP you could create a small report that uses the function module GUI_UPLOAD to get the file from your local disk into an internal table and then write it to the application server with something like this:
lv_filename = '\\path\to\al11\directory\file.txt'.
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
LOOP AT lt_contents INTO lv_line.
TRANSFER lv_line TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.
I used CG3Z transaction and with this transaction I was able to copy a file in the application server directory.
I am trying to insert a clob from a xml file which is in my local file system. Below is the piece of pl/sql block.
declare
xmlClobFile BFILE := BFILENAME(BFILE_DIR, 'clob.xml');
tempClob CLOB;
begin
EXECUTE IMMEDIATE 'CREATE OR REPLACE DIRECTORY BFILE_DIR AS '||''''||'/home/abc/data/emp/clobs'||''''
--CLOB INSERT
DBMS_LOB.createtemporary(tempClob, TRUE);
DBMS_LOB.open(xmlClobFile, DBMS_LOB.lob_readonly);
DBMS_LOB.loadfromfile(tempClob, xmlClobFile, DBMS_LOB.lobmaxsize);
EXECUTE IMMEDIATE 'insert into emp_data (id, clob_data) values (1000, :1)' using tempClob;
end;
/
Here when I give absolute path (/home/abc/data/emp/clobs) it works. But when I give relative path(like data/emp/clobs) and run this sql from /home/abc, it doesn't work.
[exec] ERROR at line 1:
[exec] ORA-22285: non-existent directory or file for FILEOPEN operation
[exec] ORA-06512: at "SYS.DBMS_LOB", line 937
[exec] ORA-06512: at line 57
How to provide a relative path here, as I want this to be run in any machine and not just mine.
The relative path, if anything will derive from the directory that the Oracle "start" command was run, e.g. /home/oracle. One way to test this, and to verify that relative paths will work (not used them myself) is to create a directory pointing to ".", and run the test to create a file, then search for that file. The directory you find the find in will be your start path. However, I think this is unsafe, since Oracle could be started from any folder (potentially), depending on if its autostarted, or whichever DBA was on hand to start it.
It must be like this one:
xmlClobFile BFILE := BFILENAME('BFILE_DIR', 'clob.xml');
I am trying to write to a local file from a PL/SQL script. In order to do this, I am attempting to use the TEXT_IO package in PL/SQL.
DECLARE
file_out text_io.file_type;
len number;
blob_file blob;
my_var RAW(50);
bstart NUMBER := 1;
bytelen NUMBER := 50;
BEGIN
SELECT xxx
INTO blob_file
FROM yyy
WHERE zzz
dbms_lob.read(blob_file, bytelen, bstart, my_var);
file_out := text_io.fopen('local_file_path', 'w');
text_io.put_raw(file_out, my_var);
text_io.fflush(file_out);
text_io.fclose(file_out);
END;
/
quit
However, when I run this script I get the error,
PLS-00201: identifier 'TEXT_IO.FILE_TYPE' must be declared
Does anyone know how I can fix this error, and how I can write the contents of the blob to a file as I am attempting to do?
Thanks,
ktm
TEXT_IO exists only in Oracle Forms which had (in the old client/ server days) a client-side PL/SQL interpreter. If you are using SQL*Plus to execute PL/SQL, as it appears you are doing here, the TEXT_IO package will not be available and you will not be able to write to a file on the client machine (barring the odd setup where the server mounts a drive that your client is exposing and then proceeds to write to that mount).
Now, you can generally use SQL*Plus to directly write to a local file using the SPOOL command. Unfortunately, it's probably unlikely that you could do this for a BLOB in the general case.
If you want to create a file on the server UTL_FILE is a good choice.
This package can write files in any DIRECTORY specified in the database. A DIRECTORY is created in Oracle using CREATE DIRECTORY and can be linked to any writable directory accessible by the DBMS (server-side).
The general approach is: write a file on the server and download it. Or event better, don't write it down, just stream it. Quite complicated, yes.