UTL_FILE.FOPEN in PL/SQL
Hi,
I want to use UTL_FILE.FOPEN in PL/SQL procedure. I keep getting an exception when I try to open the file.
FDebug := UTL_FILE.FOPEN('D:\SQL', 'debug.txt', 'w');
UTL_FILE.PUT_LINE(FDebug, 'Hello World');
UTL_FILE.FCLOSE(FDebug);
I believe the problem is that the directory is inaccessible.
I read in another post that the UTL_FILE_DIR must be set in the init.ora file. However, I do not have an init.ora file. I am willing to add one but do not know how.
Any help would be aprreciated.
Thank You,
Scott
null
Up to 8i, Oracle refused to access a file that is not pointed to in the utl_file_dir parameter in the init<sid>.ora file.
In Oracle 9i, in order to access a file, either the utl_file_dir parameter must be set, or one has to create a directory as create or replace directory dir_temp as 'c:\temp';
Similar Messages
-
PL/SQL package using utl_file.fopen gets invalid_path error
The init.ora file has utl_file_dir = * in it. When writing a package trying to utilize the utl_file.fopen the invalid_path error always occurs. What is the fix to resolve the path error?
create or replace package body TEST_UTL_FILE is
-- Purpose : Sample package that uses UTL_FILE procedure(s)
-- ===========================================================================================================
-- Process Request
-- ===========================================================================================================
procedure Process_Request is
-- Local Variable(s)
v_file_id sys.UTL_FILE.FILE_TYPE;
v_buffer varchar2(32767);
begin
v_file_id := sys.utl_file.FOPEN('D:\Oracle\XMLFiles',
'Sample1.xml',
'R');
sys.utl_file.GET_LINE(v_file_id, v_buffer);
return;
exception
-- Error number -29280
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_path');
-- Error number -29281
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_mode');
-- Error number -29282
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_filehandle');
-- Error number -29283
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_operation');
-- Error number -29284
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'read_error');
-- Error number -29285
WHEN UTL_FILE.WRITE_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'write_error');
-- Error number -29286
WHEN UTL_FILE.INTERNAL_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'internal_error');
-- Error number -29287
WHEN UTL_FILE.invalid_maxlinesize THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_maxlinesize');
-- Error number -29288
WHEN UTL_FILE.invalid_filename THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_filename');
-- Error number -29289
WHEN UTL_FILE.access_denied THEN
RAISE_APPLICATION_ERROR(-20001, 'access_denied');
-- Error number -29290
WHEN UTL_FILE.invalid_offset THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_offset');
-- Error number -29291
WHEN UTL_FILE.delete_failed THEN
RAISE_APPLICATION_ERROR(-20001, 'delete_failed');
-- Error number -29292
WHEN UTL_FILE.rename_failed THEN
RAISE_APPLICATION_ERROR(-20001, 'rename_failed');
-- Error number unknown
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, 'other_error');
end Process_Request;
end TEST_UTL_FILE;
Errors:
ORA-20001: invalid_path
ORA-06512: at "SYS.TEST_UTL_FILE", line 21
ORA-06512: at line 3 -
Hi everyone..
I am using utl_file to write delimited data into text files.In the utl_file.fopen i changed the default l "max line size" to 32767 when i got some error regarding the line size.After changing that that max line size paramaterer,I am getting lot of space after each line.
Does that max line size parameter means that every line "should" be that size? why i am getting lot of space after each line?
question1:
======
How to remove that empty spaces that i got after each line in my text file?
FILEHANDLE := UTL_FILE.FOPEN('TEST_UTL_FILE','file_name.txt', 'W',32767);And i am trying to find the length of the string that i am passing it utl_file.put_line
I am trying to insert that length to a "test" table ,so that i can check the max length of each line that is passing to the utl_file.
I have this insert command in my PL/SQL block
insert into test_number_char (num) values (dbms_lob.getlength(EXTRACTED_STRING)); and the data type of "num" column is number(20,0)
I am getting the following error .
ERROR getting members -1461 ORA-01461: can bind a LONG value only for insert into a LONG columnquestion 2:
=======
How to get the length of the string that i am writing into file?
Thanks
phaniHi Phani,
>
question1:
======
How to remove that empty spaces that i got after each line in my text file?
>
something like this,
string := Rtrim(string,' ');question 2:
=======
How to get the length of the string that i am writing into file?
>
look at this,
SQL> Set Serveroutput on
SQL> Create or Replace Directory SOME_DIR As 'C:\Temp';
Directory created
SQL> Create table Test_ As (Select dbms_random.string('X',10) as Txt From dual Connect by Level <= 2500);
Table created
SQL>
SQL> Declare
2 v_column Varchar2(30);
3 l_utl_dir Varchar2(30) := 'SOME_DIR';
4 l_utl_file Varchar2(30) := 'Some_File.txt';
5 l_header Varchar2(32767) := Null;
6 l_utl_id UTL_FILE.FILE_TYPE;
7 Begin
8 DBMS_OUTPUT.ENABLE(32767);
9
10 l_utl_id := UTL_FILE.FOPEN( location => l_utl_dir
11 , filename => l_utl_file
12 , open_mode => 'w'
13 , max_linesize => 32767);
14
15 For i IN (SELECT Rowid
16 FROM TEST_) Loop
17
18 For x IN (SELECT COLUMN_NAME
19 , TABLE_NAME
20 FROM ALL_TAB_COLS
21 WHERE TABLE_NAME = 'TEST_') Loop
22
23 Execute Immediate 'select ' || x.column_name || ' from ' ||
24 x.table_name || ' where rowid = :pi_input'
25 INTO v_column
26 Using IN i.Rowid;
27
28 l_header := l_header || v_column || ' ';
29
30 End Loop;
31 End Loop;
32
33 UTL_FILE.PUT_LINE( file => l_utl_id
34 , buffer => l_header );
35
36 UTL_FILE.FCLOSE(file => l_utl_id);
37
38 DBMS_OUTPUT.PUT_LINE( LENGTH( l_header ) );
39 End;
40 /
27500
PL/SQL procedure successfully completedHope this helps,
Christian Balz -
Cannot create a file using UTL_FILE.FOPEN
Dear All,
I am using this syntax for creating a file in window
i have declare this like this
l_file_id UTL_FILE.file_type;
l_file_name := 'DHL_'||110570284||'_'||TO_CHAR(SYSDATE,'ddmmyyyy')||'.txt'
l_file_id :=UTL_FILE.FOPEN('C:\D2R',l_file_name,'W');
Is this syntax work?
My database version is oralce 10g
ThanksFirst of all, UTL_FILE is PL/SQL package and is executed on database server side, not on client side. Therefore, it is trying to create file in directory C:\D2R on database sefrver. So if you want to create file in directory C:\D2R on your client box - you can't. Next point - you are specifying directory explicitly which old and obsolete syntax. It requires, for security reasons to add C:\D2R to init.ora parameter UTL_FILE_DIR, otherwise UTL_FILE will raise an error. You should use directory objects:
CREATE DIRECTORY dir AS 'C:\D2R';and grant READ/WRITE on it to users. Then use:
l_file_id :=UTL_FILE.FOPEN('DIR',l_file_name,'W'); -- use directory name in upper caseAnd keep in mind, as I already mentioned UTL_FILE is PL/SQL package and is executed on database server side which means it runs under OS user oracle. Therefore OS user oracle must have write permission on C:\D2R.
SY. -
Procedure using utl_file.fopen
Hi ,
I want to open a file ,read it line by line and if i find one particular word i want to display the whole line.
I tried writing a procedure but not getting desired output.
DECLARE
x utl_file.file_type;
y varchar2(200);
BEGIN
x:= utl_file.fopen('TRACE1',DB_ora_111_trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(x,y);
if x='select' then
dbms_output.put_line(x);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(x);
END;
Here i am opening a tkprof file and trying to grep for select word and if it is found,display the whole select query.The above is not showing any output.Kindly assist me since i am new to coding.
Thanksuser10698496 wrote:
Hi,
I am getting only these much as my output . I want to see entire select query.DECLARE
f utl_file.file_type;
s varchar2(2000);
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' then
dbms_output.put_line(s);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
SELECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
SELECTgroup,name,address1,state,country,fax_no,
PL/SQL procedure successfully completed.
Ok, so that is telling us that you have your queries split over multiple lines?
In that case you need to "switch on" the output of lines from the moment you find a "select" and then switch it off again when you get a line that indicates the end of the select. So let's assume your selects end with a ";" as the last character on the last line of the select, you can do something like this...
DECLARE
f utl_file.file_type;
s varchar2(2000);
in_select boolean;
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
in_select := false;
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' or in_select then
dbms_output.put_line(s);
in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
Also i attempted to cut only table name from the output select query.I tried something like o :=substr(s,instr(s,'from')+4);PFB the code and output.Pls let me know where am i going wrong.
DECLARE
2 f utl_file.file_type;
3 s varchar2(2000);
4 op varchar2(1000);
5 BEGIN
6 f := utl_file.fopen('TRACE_EXTRACT','DB_ora_1118250.trc.txt','R');
7 LOOP
8 BEGIN
9 UTL_FILE.GET_LINE(f,s);
10 if lower(s) like '%select%' then
11 op :=substr(s,instr(s,'from')+4);
12 dbms_output.put_line(op);
13 end if;
14
15 EXCEPTION
16 WHEN NO_DATA_FOUND THEN EXIT ;
17 END;
18 END LOOP;
19 utl_file.fclose(f);
20 END;
21 /
ECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
ECTgroup,name,address1,state,country,fax_no,
that's because there is no "from" on those lines, so the result of the instr is 0 and you are adding 4, so you are getting all characters from character 4 onwards.
What you need in conjunction with my above suggestion is something like this...
DECLARE
f utl_file.file_type;
s varchar2(2000);
in_select boolean;
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
in_select := false;
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' or in_select then
dbms_output.put_line(s);
if lower(s) like '%from%' then
dbms_output.put_line('TABLES: '||substr(s,instr(s,'from'+5))); -- +5 to get past the from and the space character after it.
end if;
in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
/ -
Invalid_path exception while using UTL_FILE.FOPEN
Hi
I am getting invalid_path exception while using the UTL_FILE.fopen subprogram. I tried finding out the reason but could not solve it. Please help.
Below is my piece of code.
create directory utldr as 'e:\utldir';
declare
f utl_file.file_type;
s varchar2(200);
begin
dbms_output.put_line('1');
f := utl_file.fopen('UTLDR','utlfil.txt','r');
dbms_output.put_line('2');
utl_file.get_line(f,s);
dbms_output.put_line('3');
utl_file.fclose(f);
dbms_output.put_line('4');
dbms_output.put_line(s);
exception
when utl_file.invalid_path then
dbms_output.put_line('invalid_path');
end;
the result is:
1
invalid_pathI am executing it from sys. The same user who created the directory.
The output is as below:
SELECT * FROM dba_directories
OWNER DIRECTORY_NAME DIRECTORY_PATH
SYS MEDIA_DIR d:\avale\rel4\demo\schema\product_media\
SYS LOG_FILE_DIR d:\avale\rel4\assistants\dbca\logs\
SYS DATA_FILE_DIR d:\avale\rel4\demo\schema\sales_history\
SYS EMP_DIR E:\Oracle Directory
SYS REMOTED \\10.1.1.12\oracle directory
SYS UTLDR e:\utldir
SELECT * FROM dba_tab_privs WHERE table_name='UTLDR'
GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTABLE HIERARCHY
PUBLIC SYS UTLDR SYS READ NO NO -
Broken korean characters while using utl_file.fopen
Hi,
I have korean data in a table and I need to extract it out.
Am using utl_file.fopen for this. It extracts, but korean characters are coming broken...
Is there some setting (NLS_LANG etc) that I need to do? I tried NLS_LANG korean_korea.KO16KSC5601 but didn't help...
Thanks,
SachinPlease post this question in the Database forum for an appropriate response: General Database Discussions
Regards,
OTN -
Error while using UTL_FILE.FOPEN
sir,
when i write procedure using utl_file.fopen i am getting error as it must be declared PLS-00201. what mistake, i am doing.
yours
dr.s.r.bhattachari was under the impression that there will be a moderator who will redirect the question even by mistake we post? is it not?Absolutely not. On the APEX forum we are in the fortunate position of having members of Oracle's APEX team actively involved, but neither they nor any of the other contributors perform the role of moderator or have administrative access to the forum system. The OTN team who do only really perform "moderation" when there has been a breach of the OTN Terms and Conditions.
If your question has obviously been posted in the wrong forum, or someone thinks you will get a better response elsewhere then generally they'll suggest this, as above. -
Problem in using UTL_FILE.FOPEN with filename containing accent characters
select value from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
VALUE
AL32UTF8
declare
l_output UTL_FILE.FILE_TYPE;
filename varchar2(100) := 'Avenue des Champs-Élysées.txt';
begin
l_output := UTL_FILE.FOPEN ('UPLOAD_DIR', filename, 'W');
utl_file.put_line (l_output, 'Testing');
utl_file.fclose(l_output);
end;
The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"
can anyone tell me what NLS settings I should use in order to create file with correct filename ?symplik wrote:
The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"And what does the o/s file system support and what is the operating system's NLS settings?
If there is a mismatch between what you do in your code in Oracle, and what the o/s is configured for, then this type of "+translation+" error is to be expected. -
Oracle 9i UTL_FILE.FOPEN throwing READ_ERROR
Hi
while running the package containg UTL_FILE.FOPEN
I am getting an error for reading the file on this statement :
v_file_handler := UTL_FILE.FOPEN(i_directory_path,i_file_name,'R');This happens in UNIX ,LINUX and windows NT server .
kindly suggest , whether this is an OS error (technical problem) or something else .
thanx in advance ,
Ashutosh .Hi
the UTL_FILE.FOPEN only opens an existing flat file on your OS , the UTL_FILE.GET_LINE reads from the file.
many reasons to generate a read error .
the file can be corrupted, the file doesn't exists or you havent configured the UTL_FIL_DIR parameter in the init.ora file which should be on the machine where the database is.
make sure you have the correct file name and the parameter is set.
also try to handle the exception.
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR (-20204, SQLCODE || ' ' || SQLERRM);
UTL_FILE.FCLOSE(v_filehandle);
like this you can get the exact error code and message.
Regards
Tony G. -
Query Regarding UTL_FILE.fopen() -
Guys hope you all doin well-
I am using Oracle 9i release 2 -
I am having problem while i am trying to open a file using the UTL_FILE builtin package -
I created the directory as well where the file is located, that i want to access
While i am executing the utl_file.fopen function returns record
location in varchar2 ,
filename in varchar2 ,
open_mode in varchar2 ,
max_linesize in binary_integer default
returns the following error ORA-29283: invalid file operation
The description of the error i found is:
ORA-29283: invalid file operation
Cause: An attempt was made to read from a file or directory that does not exist, or file or directory access was denied by the operating system.
Action: Verify file and directory access privileges on the file system, and if reading, verify that the file exists
The file exists and the user has the privileges to access the file too - but still having problems
please help -
if any buddy has the idea please share -
Thanks
Y.V.Hello Y.V.
Have you set the parameter utl_file_dir? Please check. In most of the cases the problem is because of this parameter
You can set it to directory that you want to access. Or else you can set it to * (which means) that UTL_FILE would be able to read from any directory on which Oracle Binary Owner has got access. Please be careful when setting this to *
To check the parameter use query:
select name,value from v$parameter
where name ='utl_file_dir';
Regards
Sudhanshu
OCP DBA -
Unable to create file using : =utl_file.fopen
Hi Team,
My issue is file is not getting created, i checked the permissions of the directory.
No error is received while executing the below script .
declare
f1 utl_file.file_type;
begin
f1:=utl_file.fopen('TAX_CODE_OUT_FILE_PATH','test.txt','W');
utl_file.put_line(f1,'memocan');
utl_file.fclose(f1);
end;
Any suggestion why file is not getting created ?i tried the following :
declare
V1 VARCHAR2(32767);
f1 utl_file.file_type;
begin
F1 := UTL_FILE.FOPEN('TAX_CODE_OUT_FILE_PATH','in.txt','R');
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
end;
Error is thrown as following ;
Error report:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 537
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 - "invalid file operation"
*Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.
*Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.
Any suggestions ?? -
UTL_FILE output from PL/SQL package
Hi,
Can any one tell me how I can generate a text file to see the variables of a package body. IS the following format correct where I have declared a file and then wrote a very simple statement. When I debug this package it generates an exception when it reached at
fileHandler := UTL_FILE.FOPEN('\users', 'myoutput', 'W');
I have initialised initDBNAME.ora file with utl_file_dir='Path to your directory' also. Any solution or correction in my code please.
PROCEDURE a1fdm_msql_admin_insert (
in_id IN NUMBER,
in_user IN VARCHAR2,
out_status OUT NUMBER
) IS
/* Declare criteria */
v_err_point VARCHAR2(10);
v_lIdAdmin NUMBER;
v_iStatus NUMBER;
v_sTimestamp DATE;
fileHandler UTL_FILE.FILE_TYPE;
/* Cursor to retrieve latest reading details. */
CURSOR c_get_admin_values IS
SELECT Status,
TO_DATE(Timestamp, 'DD:MM:YYYY HH24:MI:SS'),
id
FROM dbo_tbl_admin
WHERE id = v_lIdAdmin
AND status = 1;
BEGIN
v_lIdAdmin := in_id;
fileHandler := UTL_FILE.FOPEN('\users', 'myoutput', 'W');
UTL_FILE.PUTF(fileHandler, 'Look , I am writing to a file!!!\n');
UTL_FILE.FCLOSE(fileHandler);
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = "DD:MM:YYYY HH24:MI:SS" ';
OPEN c_get_admin_values;
FETCH c_get_admin_values INTO
v_iStatus,
v_sTimestamp,
v_lIdAdmin;
INSERT INTO dbo_tbl_admin@MSQL
VALUES
(v_iStatus,
v_sTimestamp,
v_lIdAdmin);
CLOSE c_get_admin_values;
v_err_point := '1';
out_status := 0;
EXCEPTION
WHEN OTHERS THEN
Unexpected error, make up error text string and call error handler.
DECLARE
v_err_stext t_error.err_stext%TYPE;
BEGIN
v_err_stext := 'p_a1fdm.a1fdm_msql_admin_insert point ' ||
v_err_point ||
' ORA' ||
to_char(SQLCODE);
p_error.log ( in_user, v_err_stext );
END; -- end nested block in when others exception handler
out_status := 99999;
END a1fdm_msql_admin_insert; -- procedure complete
Best regards,
GhulamTry the procedure with the additional exceptions I added and post the error you get
Create or Replace Procedure a1fdm_msql_admin_insert
(in_id IN NUMBER,
in_user IN VARCHAR2,
out_status OUT NUMBER ) IS
-- Declare criteria
v_err_point VARCHAR2(10);
v_lIdAdmin NUMBER;
v_iStatus NUMBER;
v_sTimestamp DATE;
fileHandler UTL_FILE.FILE_TYPE;
--Unexpected error, make up error text string and call error handler.
v_err_stext t_error.err_stext%TYPE;
-- Cursor to retrieve latest reading details.
CURSOR c_get_admin_values IS
SELECT Status, TO_DATE(Timestamp, 'DD:MM:YYYY HH24:MI:SS'), id
FROM dbo_tbl_admin
WHERE id = v_lIdAdmin
AND status = 1;
BEGIN
v_lIdAdmin := in_id;
fileHandler := UTL_FILE.FOPEN('\users', 'myoutput', 'W');
UTL_FILE.PUTF(fileHandler, 'Look , I am writing to a file!!!\n');
UTL_FILE.FCLOSE(fileHandler);
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = "DD:MM:YYYY HH24:MI:SS" ';
OPEN c_get_admin_values;
FETCH c_get_admin_values INTO
v_iStatus,
v_sTimestamp,
v_lIdAdmin;
INSERT INTO dbo_tbl_admin@MSQL
VALUES (v_iStatus, v_sTimestamp, v_lIdAdmin);
CLOSE c_get_admin_values;
v_err_point := '1';
out_status := 0;
EXCEPTION
-- It is a good idea to have the following in the exception block when using UTL_FILE
WHEN UTL_FILE.invalid_operation THEN
raise_application_error(-20011,'Could not open file') ;
WHEN UTL_FILE.invalid_filehandle THEN
raise_application_error(-20012,'Could not open file') ;
WHEN UTL_FILE.read_error THEN
raise_application_error(-20013,'Could not open file') ;
WHEN OTHERS THEN
v_err_stext := 'p_a1fdm.a1fdm_msql_admin_insert point ' ||
v_err_point ||' ORA' ||to_char(SQLCODE);
p_error.log ( in_user, v_err_stext );
out_status := 99999;
END a1fdm_msql_admin_insert; -- procedure complete -
How to run SQL from PL/SQL?
hi,
i want to run sql script from PL/SQL,
in my PL/SQL,i have given the path within the double quotes,
@"/usr/local/pbiace/current/bin/handle.sql" but while running the script im getting some exception.
pls guide me.....What is your OS.
First example, divide three part scritps and then
cat beforepart.sql account.sql afterpart.sql | sqlplus user/password@connectstring
type beforepart.sql+account.sql+afterpart.sql | sqlplus user/password@connectstring
Second example, divide two part scripts.
acc2.sql
declare HandleN varchar(20);
begin
select pbhandlenamelower INTO HandleN from pb_handle where pbhandleid in(select max(pbhandleid)
from pb_handle where ha_customerentityid in (select acct_customerentityid from account
where acct_accountid = &1 )) AND pbmainhandleflag=1 ;
do.pl('==============================') ;
do.pl('Handle Name: ' || HandleN ) ;
do.pl('==============================') ;
EXCEPTION
WHEN OTHERS THEN
do.pl('No rows selected');
END;
exit
main.sql
set serveroutput on
varaiable variable1 NUMBER
DECLARE
data varchar2(20);
BEGIN
data:='&1';
select BI_ACCOUNTID into :variable1 from pb_bill_info where PBBTN=data;
do.pl('BI_ACCOUNTID');
do.pl('------------');
do.pl(:variable1);
end;
@acc2 :variabl1
Third Example
create or replace directory SCRIPTS_DIR as 'path name'
acc3.sql (Only 1 statement, don't include into-clause and ';')
select pbhandlenamelower from pb_handle where pbhandleid in(select max(pbhandleid)
from pb_handle where ha_customerentityid in (select acct_customerentityid from account
where acct_accountid = :variable1 )) AND pbmainhandleflag=1
main.sql
set serveroutput on
DECLARE
data varchar2(20);
variable1 NUMBER;
HandleN varchar(20);
p_sql varchar2(32000) := '';
File_Handle UTL_FILE.FILE_TYPE;
Read_line varchar2(4000);
BEGIN
data:='&1';
select BI_ACCOUNTID into variable1 from pb_bill_info where PBBTN=data;
do.pl('BI_ACCOUNTID');
do.pl('------------');
do.pl(variable1);
File_Handle := UTL_FILE.FOPEN('SCRIPTS_DIR','acc3.sql','r');
loop
UTL_FILE.GET_LINE(File_Handle, Read_line);
exit when no_data_found;
p_sql := p_sql || Read_line || chr(32) ;
end loop;
UTL_FILE.FCLOSE(File_Handle);
execute imediate p_sql into HandleN using varaiable1;
do.pl('==============================') ;
do.pl('Handle Name: ' || HandleN ) ;
do.pl('==============================') ;
EXCEPTION
WHEN OTHERS THEN
do.pl('No rows selected');
END;
Or Some many other Examples and those are maybe more simple, only if you would analyze your business requirements. -
Problem in using CLOB Data from a Data and exporting into File
Hi,
UTL_FILE Error Occured while using UTL_FILE with CLOB Data.
UTL_FILE: A write error occurred.
The Below Code is for reference:
DECLARE
C_AMOUNT CONSTANT BINARY_INTEGER := 32767;
L_BUFFER VARCHAR2(32767);
L_CHR10 PLS_INTEGER;
L_CLOBLEN PLS_INTEGER;
L_FHANDLER UTL_FILE.FILE_TYPE;
L_POS PLS_INTEGER := 1;
BEGIN
FILE_NAME:=UTL_FILE.FOPEN('EXPORT_DIR','EXPORT_FILE'||'.sql','W');
FOR C1_EXP IN (SELECT INSERT_STRING FROM EXPORTED_DUMP) LOOP
L_CLOBLEN := DBMS_LOB.GETLENGTH(C1_EXP.INSERT_STRING);
DBMS_OUTPUT.PUT_LINE('THE CLOB LEN '||L_CLOBLEN);
DBMS_OUTPUT.PUT_LINE('THE POSITION '||L_POS);
WHILE L_POS < L_CLOBLEN LOOP
L_BUFFER := DBMS_LOB.SUBSTR(C1_EXP.INSERT_STRING, C_AMOUNT, L_POS);
DBMS_OUTPUT.PUT_LINE('THE BUFFER IS '||L_BUFFER);
EXIT WHEN L_BUFFER IS NULL;
UTL_FILE.PUT_LINE(FILE_NAME, C1_EXP.INSERT_STRING);
L_POS := L_POS + LEAST(LENGTH(L_BUFFER)+1,c_amount);
END LOOP;
END LOOP;
UTL_FILE.FCLOSE(FILE_NAME);
EXCEPTION
WHEN UTL_FILE.INTERNAL_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: An internal error occurred.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: The file handle was invalid.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_MODE THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: An invalid open mode was given.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_OPERATION THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: An invalid operation was attempted.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: An invalid path was give for the file.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: A read error occurred.');
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('UTL_FILE: A write error occurred.');
UTL_FILE.FCLOSE_ALL;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Some other error occurred.');
UTL_FILE.FCLOSE_ALL;
END;Hi user598986!
OK, I understood that there is a problem with your code. But please would you be so kindly to tell us here what error exactly happens (the errormessage). Mabay after that someone will be able to help you.
yours sincerely
Florian W.
P.S. If you enclose your code into tags it will be shown formated.
Maybe you are looking for
-
Does anyone know how to make a message display when a quiz question has been answered correctly (or a different message display when the question has been answered incorrectly)? I have created a movie that contains 5-10 quiz questions. Users take the
-
Hi all, I am sending email using this function module SO_NEW_DOCUMENT_ATT_SEND_API1 with smartform output as attachment. How can i modify sender's ID , right now the user id is appearing as sender in the mail. I want to use a generic send
-
Hello, Recently our FIM web service quit starting in our dev environment. I notice the change when the domain controllers were re-ip'd. When we try to start them manually we receive the following error. "The Forefront Identity Manager Service service
-
Hi Experts, I have got some transport request which are to be transported to production , but these transport requests belong to 2008, now client is writing to us like this in 3 points which are underlined 1) make sure we do not overwrite a more r
-
Adding D110a wireless printer to Mac
Hello, I've been working for hours trying to install my new D110a printer to my Mac, running OS 10.6.5. After researching other issues in the forums, I've still had no luck. • The printer is connected to my Linksys WRT110 router and is working with