Error in UTL_FILE
Hi,
I am working in oracle9i . I am using UTL_FILE to read and write a file in oracle.
If i use the procedure means.
SQL> CREATE OR REPLACE PROCEDURE test_utl IS
2 id UTL_FILE.FILE_TYPE;
3 BEGIN
4 id := UTL_FILE.FOPEN('/oracle/data',
5 'test.txt',
6 'W');
7 UTL_FILE.FCLOSE(id);
8 END test_utl;
9 /
Warning: Procedure created with compilation errors
its showing error as.
SQL> show errors;
Errors for PROCEDURE GETR_ERECS.TEST_UTL:
LINE/COL ERROR
2/6 PLS-00201: identifier 'UTL_FILE' must be declared
2/6 PL/SQL: Item ignored
4/3 PLS-00320: the declaration of the type of this expression is incomplete or malformed
4/3 PL/SQL: Statement ignored
7/19 PLS-00320: the declaration of the type of this expression is incomplete or malformed
7/3 PL/SQL: Statement ignored
SQL>
Kindly provide me the solutions
rgds,
In addition,
You need to have DIRECT access to utl_file, not via a role.
Normally, UTL_FILE is granted to public. Your DBA must have revoked it. You need to ask them to grant it to you.
Similar Messages
-
Runtime error using utl_file package
Hi Friends,
This is the procedure for reading sample data from flat file , but it won't work.
create or replace procedure test_utl_file
is
ftype utl_file.file_type;
ch varchar2(200);
begin
ftype := utl_file.FOPEN('C:\oracle\temp','data.txt,R');
utl_file.get_line(ftype,ch);
dbms_output.put_line(ch);
end;
This code is compiled succesfully , but at runtime it shows an error msg
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 33
ORA-06512: at "SYS.UTL_FILE", line 436
ORA-06512: at "SCOTT.TEST_UTL_FILE", line 7
ORA-06512: at line 1
I had entered the directory entry in int.ora file
utl_file_dir=C:\oracle\temp
& i used another way also,
by using alter set utl_file_dir=C:\oracle\temp scope=spfile;
Can anyone help me to resolve this problem.
Rgrds,
AnandWhat database version are you using?
The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
The correct thing to do is to create a directory object e.g.:
CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';
Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
Then, grant permission to the users who require access e.g....
GRANT READ,WRITE ON DIRECTORY mydir TO myuser;
Then use that directory object inside your FOPEN statement e.g.
fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');
Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default. -
Writetofile error -- SYS.UTL_FILE
I get below error when I use "dbms_xmldom.writetofile(doc,'output.xml')"
ORA-04067: not executed, package body "SYS.UTL_FILE" does not exist
Is this because the read-from and write-to directories in the initialization.ora file hasn't been specified? Thanks.Yes, and permissions to use UTL_FILE have been tightened up.
-
Hi,
Can someone please tell me what is the max. number of characters that can be written using UTL_FILE in Oracle 8.1.7?Perhaps I should have been more specific; I wanted to know how many characters can PUT_LINE or PUT function take at one time to write. Well, in 8.1.7, it is only 1000 characters on UNIX platform. Though it is not mentioned anywhere so I am not sure if this is OS limitation. However I had to do a lot of trial and error before e finding this out. Hope this would help people on the forum.
Thanks guys for your help. I know I can always count on you all.
Here is the sample code. In this, although, I had defined a buffer of 4000, but it consistently gave me 'WRITE_ERROR' for PUT_LINE or PUT function, until I reduced the buffer size used with these functions to 1000. Alternatively now I will use PUT function recursively and add NEW_LINE character after the entire buffer is read.
declare
vstr varchar(4000);
file_handle UTL_FILE.FILE_TYPE;
begin
select rpad('Testiing',990,'xyz') into vstr from dual;
file_handle := UTL_FILE.FOPEN ('/usr/users/cornwas/workplace', 'a.txt', 'w');
for i in 1..20 loop
UTL_FILE.PUT_LINE(file_handle, vstr);
UTL_FILE.FFLUSH(file_handle);
end loop;
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20100,'Invalid Path');
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20101,'Invalid Mode');
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20102,'Invalid Filehandle');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20103,'Invalid Operation -- May signal a file locked by the OS');
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20104,'Read Error');
WHEN UTL_FILE.WRITE_ERROR THEN
RAISE_APPLICATION_ERROR(-20105,'Write Error');
WHEN UTL_FILE.INTERNAL_ERROR THEN
RAISE_APPLICATION_ERROR(-20106,'Internal Error');
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20107,'No Data Found');
WHEN VALUE_ERROR THEN
RAISE_APPLICATION_ERROR(-20108,'Value Error');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20109,'Unknown UTL_FILE Error');
end; -
Unable to read the file using UTL_FILE Dir
I need to read/write a file from/to the operating system through PLSQL Package. I used UTL_FILE package to do the same. In the application server the utl_file_dir(/usr/tmp in my system) is created as a softlink to database server.
oI want to run this package through the application server. However I am unable to read and write the file to the operating system.
I just wondering it is not reading/opening the file from the server. Please suggest me how to modify my code.Hi,
How to check if it is end of file or not? I have the following function which is working fine in my win2003 server std 32bit and Oracle10g Database R2 Standard Edition one 32bit. HOwever, when I deploy to production server which is 64bit OS and database, it gives error at UTL_FILE.GET_LINE(fptr, tmp);
Any idea why it behaves like that?
FUNCTION readFile (
inHTML OUT CLOB,
path IN VARCHAR2,
htmlFile IN VARCHAR2
) RETURN BOOLEAN IS
fptr utl_file.file_type;
tmp VARCHAR2(5023);
bufferlen BINARY_INTEGER;
BEGIN
fptr := UTL_FILE.FOPEN(path, htmlFile, 'r');
DBMS_LOB.CREATETEMPORARY(inHTML, TRUE);
DBMS_LOB.OPEN(inHTML, DBMS_LOB.LOB_READWRITE);
LOOP
UTL_FILE.GET_LINE(fptr, tmp);
if tmp is not null then
tmp := tmp || CHR(10);
bufferlen := LENGTH(tmp);
DBMS_LOB.WRITEAPPEND(inHTML, bufferlen, tmp);
end if;
END LOOP;
WHEN NO_DATA_FOUND THEN
DBMS_LOB.CLOSE(inHTML);
UTL_FILE.FCLOSE(fptr);
RETURN TRUE;
WHEN OTHERS THEN
DBMS_LOB.CLOSE(inHTML);
DBMS_LOB.FREETEMPORARY(inHTML);
RETURN FALSE;
END readFile; -
Hi,
I am struck with one error in opening the xml file. Pls provide me your inputs.
I am using the pl/sql script for outbounding the data in .xml format. But after creating the file successfully I am not able to open it in the explorer. The data having '&' in one of the columns and it will be available in data in many areas. Where as if I try to create it the same with Oracle report by using 'xml' as output, then I am not getting this issue. And I am able to open the same in explorer perfectly.
Here I am pasting the script which I've created
create or replace PROCEDURE GETXML_TAG(ERRBUT OUT VARCHAR2,
RETCODE OUT VARCHAR2,
P_DIR_NAME VARCHAR2)
IS
v_record_data varchar2(4000) := null;
v_order_id varchar2(50) := null;
v_order_date varchar2(50) := null;
v_order_mode varchar2(50) := null;
v_order_total varchar2(50) := null;
v_file_dir varchar2(100):= '/usr/tmp';
CURSOR cur_hdr IS
SELECT DISTINCT MINISTRY_CODE, DEPT_CODE, ''ENTITY_CODE
FROM XGBZ_FIN_STAGE_ACS
WHERE tx_timestamp IS NULL;
CURSOR cur_line(p_min_code IN VARCHAR2,
p_dept_code IN VARCHAR2) IS
SELECT seg_no,
seg_code,
to_char(seg_description) seg_description,
start_date,
end_date,
status,
disable_flag
FROM xgbz_fin_stage_acs
WHERE tx_timestamp IS NULL
AND ministry_code =p_min_code
AND dept_code = p_dept_code;
BEGIN
v_filename := 'GEBIZ_EPO'||TO_CHAR(SYSDATE,'DDMMYYYYHH24MI')||'.xml';
f_xml_file := UTL_FILE.FOPEN(v_file_dir, v_filename, 'W');
v_record_data := '<?xml version="1.0" encoding="UTF-8"?>';
UTL_FILE.put_line(f_XML_FILE, v_RECORD_DATA);
UTL_FILE.put_line(f_XML_FILE, '<GEBIZ_ACCOUNT_SEGMENT>');
dbms_output.put_line('step 1 '||v_file_dir||'-'||v_filename);
FOR cur_hdr_rec IN cur_hdr
LOOP
dbms_output.put_line('step 2 ');
UTL_FILE.put_line(f_XML_FILE, '<HEADER>');
UTL_FILE.put_line(f_XML_FILE,'<MINISTRY_CODE>' || cur_hdr_rec.ministry_code || '</MINISTRY_CODE>');
UTL_FILE.put_line(f_XML_FILE,'<DEPT_CODE>' || cur_hdr_rec.dept_code || '</DEPT_CODE>');
UTL_FILE.put_line(f_XML_FILE,'<ENTITY_CODE>' || cur_hdr_rec.entity_code || '</ENTITY_CODE>');
UTL_FILE.put_line(f_XML_FILE, '</HEADER>');
FOR cur_line_rec IN cur_line(cur_hdr_rec.ministry_code, cur_hdr_rec.dept_code)
LOOP
dbms_output.put_line('step 3 ');
UTL_FILE.put_line(f_XML_FILE, '<DETAILS>');
UTL_FILE.put_line(f_XML_FILE, '<SEGEMENT>');
UTL_FILE.put_line(f_XML_FILE,'<NUMBER>' || cur_line_rec.seg_no|| '</NUMBER>');
UTL_FILE.put_line(f_XML_FILE,'<CODE>' || cur_line_rec.seg_no|| '</CODE>');
UTL_FILE.put_line(f_XML_FILE,'<DESCRIPTION>' || cur_line_rec.seg_description|| '</DESCRIPTION>');
UTL_FILE.put_line(f_XML_FILE,'<START_DATE>' || cur_line_rec.start_date|| '</START_DATE>');
UTL_FILE.put_line(f_XML_FILE,'<END_DATE>' || cur_line_rec.end_date|| '</END_DATE>');
UTL_FILE.put_line(f_XML_FILE,'<STATUS>' || cur_line_rec.status|| '</STATUS>');
UTL_FILE.put_line(f_XML_FILE,'<DELETE_FLAG>' || cur_line_rec.disable_flag|| '</DELETE_FLAG>');
UTL_FILE.put_line(f_XML_FILE, '</SEGEMENT>');
UTL_FILE.put_line(f_XML_FILE, '</DETAILS>');
END LOOP;
END LOOP;
dbms_output.put_line('step 4 ');
UTL_FILE.put_line(f_XML_FILE, '</GEBIZ_ACCOUNT_SEGMENT>');
UTL_FILE.FCLOSE(f_XML_FILE);
EXCEPTION
WHEN UTL_FILE.INVALID_OPERATION THEN
dbms_output.put_line('Invalid Operation For '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_PATH THEN
dbms_output.put_line('Invalid Path For '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_MODE THEN
dbms_output.put_line('Invalid Mode For '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
dbms_output.put_line('Invalid File Handle '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.WRITE_ERROR THEN
dbms_output.put_line('Invalid Write Error '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.READ_ERROR THEN
dbms_output.put_line('Invalid Read Error '|| v_filename);
UTL_FILE.FCLOSE_ALL;
WHEN UTL_FILE.INTERNAL_ERROR THEN
dbms_output.put_line('Internal Error');
UTL_FILE.FCLOSE_ALL;
WHEN OTHERS THEN
dbms_output.put_line('Other Error '||'SQL CODE: '||SQLCODE||' Messg: '||SQLERRM);
UTL_FILE.FCLOSE_ALL;
END GETXML_TAG;
The file I am generating at the server level:
EPO150320111915.xml
<?xml version="1.0" encoding="UTF-8"?>
<GEBIZ_ACCOUNT_SEGMENT>
<HEADER>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPT_CODE>000</DEPT_CODE>
<ENTITY_CODE></ENTITY_CODE>
</HEADER>
<DETAILS>
<SEGEMENT>
<NUMBER>1</NUMBER>
<CODE>1</CODE>
<DESCRIPTION>Republic Polytechnic</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Operating Grant</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-Renovation to Temp Campus Temp</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-Renovation to Temp Campus Main</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-IT for Temp Campus</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-Land Premium for Woodlands Campus</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-Pre-construction of Woodlands Campus</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Dev Grant-FE</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Tax Exempt-Student Dev Welfare Fund</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>Tax Exempt-Dev Project Fund</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>2</NUMBER>
<CODE>2</CODE>
<DESCRIPTION>For Finance Use ONLY</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Library</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Academic Affairs</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Corporate Communications</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Deputy Principal</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Estates</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Finance</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Human Resource</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
<DETAILS>
<SEGEMENT>
<NUMBER>3</NUMBER>
<CODE>3</CODE>
<DESCRIPTION>Office of Industrial & International Services</DESCRIPTION>
<START_DATE></START_DATE>
<END_DATE></END_DATE>
<STATUS>A</STATUS>
<DELETE_FLAG></DELETE_FLAG>
</SEGEMENT>
</DETAILS>
</GEBIZ_ACCOUNT_SEGMENT>
------ end of file
I am able to edit it correctly in notepad, when tried to open at explorer level its not allowing me because of '&'.
Pls confirm what might be the issue.
Regards
NagendraThis is the output:
<?xml version="1.0" encoding="UTF-8" ?>
- <GEBIZ_PO_FUND_STATUS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000086</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>306</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>RM</UNIT_OF_MEASURE>
<QUANTITY>100</QUANTITY>
<TOTAL_AMOUNT>306</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>100</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>100</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1ODP/000/220702/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000090</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>4950</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>CQ</UNIT_OF_MEASURE>
<QUANTITY>9000</QUANTITY>
<TOTAL_AMOUNT>4950</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>2</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>3</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>CQ</UNIT_OF_MEASURE>
<QUANTITY>9000</QUANTITY>
<TOTAL_AMOUNT>4950</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>2</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>3</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>CQ</UNIT_OF_MEASURE>
<QUANTITY>9000</QUANTITY>
<TOTAL_AMOUNT>4950</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>2</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
- <LOCATION>
<LINE_NUMBER>3</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000097</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>160</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>EA</UNIT_OF_MEASURE>
<QUANTITY>2</QUANTITY>
<TOTAL_AMOUNT>80</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>2</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>2</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/3SIT/000/221103/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000097</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>240</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>2</LINE_NUMBER>
<UNIT_OF_MEASURE>EA</UNIT_OF_MEASURE>
<QUANTITY>3</QUANTITY>
<TOTAL_AMOUNT>120</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>3</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/3SIT/000/221103/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000099</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>1000</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>EA</UNIT_OF_MEASURE>
<QUANTITY>1000</QUANTITY>
<TOTAL_AMOUNT>1000</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>1000</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>1000</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OCC/000/221001/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000112</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>7450</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>EA</UNIT_OF_MEASURE>
<QUANTITY>50</QUANTITY>
<TOTAL_AMOUNT>7450</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>50</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>50</QUANTITY>
<CHART_OF_ACCOUNT>1/D03/1OIS/000/220308/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
- <HEADER>
<ORDER_CODE>RPO000EPO03000115</ORDER_CODE>
<EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
<AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
<VARIATION_NUMBER>0</VARIATION_NUMBER>
- <TOTAL_AMOUNT>
<CURRENCY_CODE>SGD</CURRENCY_CODE>
<CURRENCY_AMOUNT>175</CURRENCY_AMOUNT>
</TOTAL_AMOUNT>
<MINISTRY_CODE>RPO</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</HEADER>
- <ITEMS>
- <ITEM>
<LINE_NUMBER>1</LINE_NUMBER>
<UNIT_OF_MEASURE>LT</UNIT_OF_MEASURE>
<QUANTITY>1</QUANTITY>
<TOTAL_AMOUNT>175</TOTAL_AMOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <LOCATIONS>
- <LOCATION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>1</QUANTITY>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
- <DISTRIBUTIONS>
- <DISTRIBUTION>
<LINE_NUMBER>1</LINE_NUMBER>
<QUANTITY>1</QUANTITY>
<CHART_OF_ACCOUNT>1/G01/1OPT/000/220702/0000/0000/0000</CHART_OF_ACCOUNT>
<FUND_STATUS>COMMITTED</FUND_STATUS>
<FUND_REJECT_REASON />
</DISTRIBUTION>
</DISTRIBUTIONS>
</LOCATION>
</LOCATIONS>
</ITEM>
</ITEMS>
</GEBIZ_PO_FUND_STATUS>
<FUND_REJECT_REASON /> is one of the element where some times I can have data and some times I won't.
This is the script I used for generating that data
SELECT xmlserialize(document
xmlelement("GEBIZ_PO_FUND_STATUS"
, xmlagg(
xmlconcat(hdr, dtls)
as clob indent size = 2
INTO lv_out
FROM (
SELECT xmlelement("HEADER"
, xmlelement("ORDER_CODE", po_cont_code)
, xmlelement("EXTERNAL_SYSTEM_CODE", ext_system_code)
, xmlelement("AMENDMENT_NUMBER", amendment_no)
, xmlelement("VARIATION_NUMBER", variation_no)
, xmlelement("TOTAL_AMOUNT"
, xmlelement("CURRENCY_CODE", currency_code)
, xmlelement("CURRENCY_AMOUNT", total_amount)
, xmlelement("MINISTRY_CODE",ministry_code)
, xmlelement("DEPARTMENT_CODE",dept_code)
, xmlelement("FUND_STATUS", hdr_fund_status)
, xmlelement("FUND_REJECT_REASON", hdr_fund_reject_res)
) hdr
, xmlagg(
xmlelement("ITEMS"
, xmlelement("ITEM"
, xmlelement("LINE_NUMBER", line_no)
, xmlelement("UNIT_OF_MEASURE", uom_code)
, xmlelement("QUANTITY", line_quantity)
, xmlelement("TOTAL_AMOUNT", line_total_amount)
, xmlelement("FUND_STATUS", line_fund_status)
, xmlelement("FUND_REJECT_REASON", line_fund_reject_res)
,xmlelement("LOCATIONS"
,xmlelement("LOCATION"
,xmlelement("LINE_NUMBER", shipment_num)
,xmlelement("QUANTITY",line_location_quantity)
,xmlelement("FUND_STATUS",loc_fund_status)
,xmlelement("FUND_REJECT_REASON",loc_fund_reject_res)
,xmlelement("DISTRIBUTIONS"
,xmlelement("DISTRIBUTION"
,xmlelement("LINE_NUMBER", distribution_num)
,xmlelement("QUANTITY", quantity_ordered)
,xmlelement("CHART_OF_ACCOUNT",chart_account)
,xmlelement("FUND_STATUS", dist_fund_status)
,xmlelement("FUND_REJECT_REASON", dist_fund_reject_res)
) dtls
FROM xgbz_fin_stage_pof_v
GROUP BY po_cont_code,ext_system_code,amendment_no,variation_no,currency_code,total_amount,
ministry_code, dept_code, hdr_fund_status,hdr_fund_reject_res);
When ever, for any of the above columns does not have data that time it is coming like this for eg:
<FUND_REJECT_REASON />
instead of this can I have output like this
<FUND_REJECT_REASON > </FUND_REJECT_REASON>
for those non data elements.
Is that possible .
Thanks for your help.
Regards
Nagendra -
Hi,
I am using UTL file to export data to an external file and getting an error which i am unable to reslove... Can anyone help me with this
SQL> create or replace
2 procedure MEXICO_NAFTA_CERTIFICATE_EXT (
3 f_org_id varchar2,
4 f_customer_nbr_base varchar2,
5 f_customer_nbr_sufx varchar2,
6 f_year VARCHAR2)
7 is
8 output_file utl_file.file_type;
9 o_filename VARCHAR2(50):= 'MEXICO_NAFTA_CERTIFICATE_EXT.txt';
10 o_DataDir CONSTANT VARCHAR2 (30) := '/d014/oradata/temp';
11 v_CERTIFICATE_NBR fta.SAP_CERTIFICATES_EXTRACT_VIEW.CERTIFICATE_NBR%type;
12 v_PART171 fta.SAP_CERTIFICATES_EXTRACT_VIEW.PART171%type;
13 v_INACTIVE_IND fta.SAP_CERTIFICATES_EXTRACT_VIEW.INACTIVE_IND%type;
14 v_HTS_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.HTS_CDE%type;
15 v_ORIGINATING_IND fta.SAP_CERTIFICATES_EXTRACT_VIEW.ORIGINATING_IND%type;
16 v_ISO_COUNTRY_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.ISO_COUNTRY_CDE%type;
17 v_BASIS_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.BASIS_CDE%type;
18 v_PRODUCER_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.PRODUCER_CDE%type;
19 v_CERT_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.CERT_CDE%type;
20 v_REGIONAL_VALUE_CONTENT_CDE fta.SAP_CERTIFICATES_EXTRACT_VIEW.REGIONAL_VALUE_CONTENT_CDE%type;
21 v_PART_NBR fta.SAP_CERTIFICATES_EXTRACT_VIEW.PART_NBR%type;
22 v_EFFECTIVE_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_DATE%type;
23 v_EFFECTIVE_FROM_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_FROM_DATE%type;
24 v_EFFECTIVE_TO_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.EFFECTIVE_TO_DATE%type;
25 v_TRANSACTION_DATE fta.SAP_CERTIFICATES_EXTRACT_VIEW.TRANSACTION_DATE%type;
26
27
28 CURSOR Cert_ext IS select certificate_nbr ,
29 part171,
30 inactive_ind,
31 hts_cde,
32 originating_ind,
33 iso_country_cde,
34 basis_cde,
35 producer_cde,
36 cert_cde,
37 regional_value_content_cde,
38 part_nbr,
39 effective_date,
40 effective_from_date,
41 effective_to_date,
42 transaction_date
43 from fta.SAP_CERTIFICATES_EXTRACT_VIEW
44 where org_id= f_org_id AND
45 customer_nbr_base= f_customer_nbr_base AND
46 customer_nbr_sufx = f_customer_nbr_sufx AND
47 to_char(effective_from_date, 'yy') = f_year AND
48 to_char(effective_to_date, 'yy') = f_year;
49
50 begin
51
52 output_File := UTL_FILE.FOPEN (o_DataDir, o_FileName, 'w');
53
54 OPEN Cert_ext;
55 loop
56
57 fetch Cert_ext into v_CERTIFICATE_NBR ,
58 v_PART171 ,
59 v_INACTIVE_IND,
60 v_HTS_CDE ,
61 v_ORIGINATING_IND ,
62 v_ISO_COUNTRY_CDE ,
63 v_BASIS_CDE ,
64 v_PRODUCER_CDE ,
65 v_CERT_CDE ,
66 v_REGIONAL_VALUE_CONTENT_CDE ,
67 v_PART_NBR,
68 v_effective_date,
69 v_effective_from_date,
70 v_effective_to_date,
71 v_transaction_date ;
72
73 UTL_FILE.PUT_LINE (output_File, v_CERTIFICATE_NBR || ' '||
74 v_PART171 || ' '||
75 v_INACTIVE_IND || ' '||
76 v_HTS_CDE || ' '||
77 v_ORIGINATING_IND || ' '||
78 v_ISO_COUNTRY_CDE || ' '||
79 v_BASIS_CDE || ' '||
80 v_PRODUCER_CDE || ' '||
81 v_CERT_CDE || ' '||
82 v_REGIONAL_VALUE_CONTENT_CDE || ' '||
83 v_PART_NBR || ' '||
84 to_char(v_EFFECTIVE_DATE, 'mm-dd-yy') || ' '||
85 to_char(v_EFFECTIVE_FROM_DATE, 'mm-dd-yy') || ' '||
86 to_char(v_EFFECTIVE_TO_DATE, 'mm-dd-yy') || ' '||
87 to_char(v_TRANSACTION_DATE, 'mm-dd-yy'));
88
89 UTL_FILE.FCLOSE (output_File);
90 DBMS_OUTPUT.PUT_LINE ('Data Extracted');
91 end loop;
92 close Cert_ext;
93 END MEXICO_NAFTA_CERTIFICATE_EXT;
94 /
Procedure created.
SQL> declare
2 begin
3 MEXICO_NAFTA_CERTIFICATE_EXT('0048', '00254101', '11', '03');
4 end;
5 /
Data Extracted
declare
ERROR at line 1:
ORA-29282: invalid file ID
ORA-06512: at "SYS.UTL_FILE", line 774
ORA-06512: at "FTA_SOURCE.MEXICO_NAFTA_CERTIFICATE_EXT", line 72
ORA-06512: at line 3what is the datatype of your column org_id for the table fta.SAP_CERTIFICATES_EXTRACT_VIEW? also try to put this exceptions to see what might be the exact cause of the error.
EXCEPTION
WHEN utl_file.invalid_mode THEN
RAISE_APPLICATION_ERROR (-20051, 'Invalid Mode Parameter');
WHEN utl_file.invalid_path THEN
RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
WHEN utl_file.invalid_filehandle THEN
RAISE_APPLICATION_ERROR (-20053, 'Invalid Filehandle');
WHEN utl_file.invalid_operation THEN
RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation');
WHEN utl_file.read_error THEN
RAISE_APPLICATION_ERROR (-20055, 'Read Error');
WHEN utl_file.internal_error THEN
RAISE_APPLICATION_ERROR (-20057, 'Internal Error');
WHEN utl_file.charsetmismatch THEN
RAISE_APPLICATION_ERROR (-20058, 'Opened With FOPEN_NCHAR But Later I/O Inconsistent');
WHEN utl_file.file_open THEN
RAISE_APPLICATION_ERROR (-20059, 'File Already Opened');
WHEN utl_file.invalid_maxlinesize THEN
RAISE_APPLICATION_ERROR(-20060,'Line Size Exceeds 32K');
WHEN utl_file.invalid_filename THEN
RAISE_APPLICATION_ERROR (-20061, 'Invalid File Name');
WHEN utl_file.access_denied THEN
RAISE_APPLICATION_ERROR (-20062, 'File Access Denied By');
WHEN utl_file.invalid_offset THEN
RAISE_APPLICATION_ERROR (-20063,'FSEEK Param Less Than 0');
WHEN others THEN
RAISE_APPLICATION_ERROR (-20099, 'Unknown UTL_FILE Error'); -
Samples using UTL_FILE package
hello;
I would like to use the utl_file package: fopen, put_line ...
can you send me some samples using this package.
thanks to your help
mam
nulldeclare
T1 UTL_FILE.FILE_TYPE;
begin
begin
T1:= UTL_FILE.FOPEN
('/u02/applmgr/10.7p161/eye/3.3.1/out','filename.dat','w');
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('Invalid Path');
WHEN UTL_FILE.INVALID_MODE THEN
DBMS_OUTPUT.PUT_LINE('Invalid Mode');
WHEN UTL_FILE.INVALID_OPERATION THEN
DBMS_OUTPUT.PUT_LINE('Invalid Operation');
end;
UTL_FILE.PUT(T1,'PROD DATE ');
UTL_FILE.PUT(T1,'PRODUCT ');
UTL_FILE.PUT_LINE(T1,'INTEREST TYPE ');
UTL_FILE.PUT(T1,'LEASE NUMBER ');
begin
UTL_FILE.FCLOSE(T1);
EXCEPTION
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('write error');
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
DBMS_OUTPUT.PUT_LINE('Invald File Handle');
end;
END;
mamoudou (guest) wrote:
: hello;
: I would like to use the utl_file package: fopen, put_line ...
: can you send me some samples using this package.
: thanks to your help
: mam
null -
UTL_FILE.get_line won't read large files ?
I am trying to read a large fixed length flat file. If I cut the file down to really small it will read it but it reads it as a single line. If I try to read a larger file > 32k I get a READ_ERROR. I am pretty sure it has to do with the end of line marker but I saw nothing about that in the UTL_FILE documentation. This is on UNIX, new line character after each record in the file. Standard unix flat file.
Any ideas on what to do?
Thanks in advance
Matt
[email protected]
my code:
BEGIN
BEGIN
std_file := UTL_FILE.FOPEN('&4','&1','r',32767);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20011,'Invalid Path for STD file, &4/&1');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20014,'Other Error trying to open STD file, &4/&1');
END;
IF UTL_FILE.is_open(std_file) = FALSE THEN
RAISE_APPLICATION_ERROR(-20015,'Could not open STD file, &4/&1');
END IF;
-- READ STD FILE HEADER
BEGIN
UTL_FILE.get_line(std_file,hdr_text);
EXCEPTION
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20017,'STD read file handle not valid');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20018,'STD read invalid operation error');
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20019,'STD read error');
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20020,'STD read no data found');
WHEN VALUE_ERROR THEN
RAISE_APPLICATION_ERROR(-20021,'STD read value error');
END;
-- PROCESS TRANSACTIONS
LOOP
BEGIN
tran_text := NULL;
UTL_FILE.get_line(std_file,tran_text);
EXCEPTION
WHEN no_data_found THEN EXIT; -- EOF
WHEN value_error THEN
RAISE_APPLICATION_ERROR(-20010,'STD record too long.');
END;
std_rowcount := std_rowcount + 1;
END LOOP;
UTL_FILE.FCLOSE(std_file);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20001,'No Data Found.');
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20002,'Invalid Path ');
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20003,'Invalid Mode ');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20004,'Invalid Operation ');
END;
nullWe are still hung up on this. I tried implementing the code from STEVE'S XML book but still haven't resovled it.
The clob is being created via XSU see below. The new char[8192] appeasr to force the output file to 8K
with trailing characters on small clobs but adds a carraige return each 8K on larger ones.
As usual any input is appreciated from all. Doese anyone know of a good JAVA forum like this one?
Thanks
PROCEDURE BuildXml(v_return OUT INTEGER, v_message OUT VARCHAR2,string_in VARCHAR2,xml_CLOB OUT NOCOPY CLOB) IS
queryCtx DBMS_XMLquery.ctxType;
Buffer RAW(1024);
Amount BINARY_INTEGER := 1024;
Position INTEGER := 1;
sql_string VARCHAR2(2000) := string_in;
BEGIN
v_return := 1;
v_message := 'BuildXml completed succesfully.';
queryCtx := DBMS_XMLQuery.newContext(sql_string);
xml_CLOB := DBMS_XMLQuery.getXML(queryCtx);
DBMS_XMLQuery.closeContext(queryCtx);
EXCEPTION WHEN OTHERS THEN
v_return := 0;
v_message := 'BuildXml failed - '||SQLERRM;
END BuildXml;
create or replace and compile java source named sjs.write_CLOB as
import java.io.*;
import java.sql.*;
import java.math.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class write_CLOB extends Object
public static void pass_str_array(oracle.sql.CLOB p_in,java.lang.String f_in)
throws java.sql.SQLException, IOException
File target = new File(f_in);
FileWriter fw = new FileWriter(target);
BufferedWriter out = new BufferedWriter(fw);
Reader is = p_in.getCharacterStream();
char buffer[] = new char[8192];
int length;
while( (length=is.read(buffer)) != -1) {
out.write(buffer);
is.close();
fw.close();
/ -
PL/SQL : Error: invalid path ORA-29280
I'm trying to get this work but what can I do ? does anybody know how to resolv this problem
code : (for the exemple)
DECLARE
fich UTL_FILE.FILE_TYPE;
BEGIN
fich := UTL_FILE.FOPEN('e:\','test.lst','W');
UTL_FILE.PUT(fich,'something');
UTL_FILE.FCLOSE(fich);
EXCEPTION
WHEN utl_file.invalid_path THEN
DBMS_OUTPUT.PUT_LINE('Error: invalid path ' || SQLERRM);
UTL_FILE.FCLOSE(fich);
WHEN utl_file.write_error THEN
DBMS_OUTPUT.PUT_LINE('Error: write error ' || SQLERRM);
UTL_FILE.FCLOSE(fich);
WHEN others then
DBMS_output.put_line('other error : '||SQLERRM);
UTL_FILE.FCLOSE(fich);
END;
Always return :
ERROR at ligne 1 :
ORA-29280: invalid path
ORA-06512: at "SYS.UTL_FILE", line 18
ORA-06512: at "SYS.UTL_FILE", line 424
ORA-06512: at line 4
If someone can tell me where's the fault. thanks in advanceAlso note, that directories you want to have access to should be listed in UTL_FILE_DIR server parameter (you edit it in your init.ora and restart the server for changes to take effect.) Setting it to * (everything everywhere) is NOT recommended as it opens whole file system for access and may lead to security problems.
-
I have written a following procedure and it complies successfully.
create or replace procedure utl_file_test_write (
path in varchar2,
filename in varchar2,
firstline in varchar2,
secondline in varchar2)
is
output_file utl_file.file_type;
begin
output_file := utl_file.fopen (path,filename, 'W');
utl_file.put_line (output_file, firstline);
utl_file.put_line (output_file, secondline);
utl_file.fclose(output_file);
end;
I have create the directory using the following command
SQL> CREATE DIRECTORY log_dir AS 'd:\oracle\oraclelog_dir';
Directory created
SQL> GRANT READ ON DIRECTORY log_dir TO DBA;
Grant succeeded
SQL> CREATE DIRECTORY out_dir AS 'd:\oracle\oracleout_dir';
Directory created
SQL> GRANT READ ON DIRECTORY out_dir TO DBA;
Grant succeeded
SQL> COMMIT;
But when I execute this then it gives the following error.
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 98
ORA-06512: at "SYS.UTL_FILE", line 157
ORA-06512: at "UTL_FILE_TEST_WRITE", line 9
ORA-06512: at line 1
I am using the following version.
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
PL/SQL Release 8.1.5.0.0 - Production
CORE Version 8.1.3.0.0 - Production
TNS for Solaris: Version 8.1.5.0.0 - Production
NLSRTL Version 3.4.0.0.0 - Production
Can anybody help me how can I solve the problem.
Thanks in advanceI think you are not handeling the exceptions. First you add the exceptions and it will tell you what kind of exception is raised.
Try:
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20100,'Invalid Path');
WHEN utl_file.invalid_mode THEN
raise_application_error(-20101,'Invalid Mode');
WHEN utl_file.invalid_operation THEN
raise_application_error(-20102,'Invalid Operation');
WHEN utl_file.invalid_filehandle THEN
raise_application_error(-20103,'Invalid Filehandle');
WHEN utl_file.write_error THEN
raise_application_error(-20104, 'Write Error');
WHEN utl_file.read_error THEN
raise_application_error(-20105,'Read Error');
WHEN utl_file.internal_error THEN
raise_application_error(-20106,'Internal Error');
WHEN others THEN
utl_file.fclose(v_file_id);
raise_application_error (-20007, sqlerrm);HTH
Ghulam -
제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532 -
Hi,
In utl file i have a reqruriment as " if file doesnt exit or unable to open the file for write "
For that i have coded below for checking a file is exit or not,
how to do the coding for " a file is been unable to open the file for write".
please advice.
BEGIN
var_out_file_name_1 BFILE := BFILENAME('path', 'x.rpt');
IF DBMS_LOB.FILEEXISTS (var_out_file_name_1) = 1 THEN
DBMS_OUTPUT.PUT_LINE ('File exists.');
ELSIF DBMS_LOB.FILEEXISTS (var_out_file_name_1) = 0 THEN
DBMS_OUTPUT.PUT_LINE ('File does not exist');
ELSE
DBMS_OUTPUT.PUT_LINE ('Unable to test existence for x.rpt');
END IF;
ENDoracle version : 8i
thanks in advance :-) Edited by: USER_X on Sep 10, 2008 3:26 PMmaybe exceptions might help if you will use the <a href="http://www.psoug.org/reference/utl_file.html" target="_blank">UTL_FILE</a> function.
BEGIN
EXCEPTION
WHEN utl_file.invalid_mode THEN
dbms_output.put_line ('Invalid Mode Parameter');
WHEN utl_file.invalid_path THEN
dbms_output.put_line ('Invalid File Location');
WHEN utl_file.invalid_filehandle THEN
dbms_output.put_line ('Invalid Filehandle');
WHEN utl_file.invalid_operation THEN
dbms_output.put_line ('Invalid Operation');
WHEN utl_file.read_error THEN
dbms_output.put_line ('Read Error');
WHEN utl_file.internal_error THEN
dbms_output.put_line ('Internal Error');
WHEN utl_file.charsetmismatch THEN
dbms_output.put_line ('Opened With FOPEN_NCHAR But Later I/O Inconsistent');
WHEN utl_file.file_open THEN
dbms_output.put_line ('File Already Opened');
WHEN utl_file.invalid_maxlinesize THEN
dbms_output.put_line('Line Size Exceeds 32K');
WHEN utl_file.invalid_filename THEN
dbms_output.put_line ('Invalid File Name');
WHEN utl_file.access_denied THEN
dbms_output.put_line ('File Access Denied By');
WHEN utl_file.invalid_offset THEN
dbms_output.put_line ('FSEEK Param Less Than 0');
WHEN others THEN
dbms_output.put_line ('Unknown UTL_FILE Error');
END; -
UTL_FILE help/samples
Hello Folks,
I need to write a routine to read in a CSV file parse it and inser the data into a table.
Does anybody have examples?
TIAUse this as a skeleton:
set serveroutput on size 1000000 format word_wrapped
set verify off
DECLARE
EOF CONSTANT VARCHAR2(30) := '~~+~~+~~';
iCount NUMBER;
sEOF VARCHAR2(30);
sPath VARCHAR2(2000);
sRecord VARCHAR2(2000);
sSQLCode NUMBER;
sSQLErrM VARCHAR2(255);
pFileHandle utl_file.file_type;
BEGIN
dbms_output.enable(1000000);
iCount := 0;
sEOF := '';
sPath := 'C:\Data';
pFileHandle := utl_file.fopen(sPath, 'file.cvs', 'r');
loop
BEGIN
utl_file.get_line(pFileHandle, sRecord);
EXCEPTION
when NO_DATA_FOUND then sEOF := EOF;
END;
exit when sEOF = EOF;
iCount := iCount + 1;
dbms_output.put_line(sRecord);
end loop;
commit;
dbms_output.put_line("Records read: "| |iCount);
utl_file.fclose(pFileHandle);
EXCEPTION
when UTL_FILE.INVALID_OPERATION then
utl_file.fclose(pFileHandle);
raise_application_error(-20001, 'Invalid Operation');
when UTL_FILE.INVALID_FILEHANDLE then
utl_file.fclose(pFileHandle);
raise_application_error(-20002, 'Invalid File Handle');
when UTL_FILE.WRITE_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20003, 'Write Error');
when UTL_FILE.INTERNAL_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20004, 'Internal Error');
when UTL_FILE.INVALID_PATH then
utl_file.fclose(pFileHandle);
raise_application_error(-20005, 'Invalid Path ['| |sPath| |']');
when UTL_FILE.INVALID_MODE then
utl_file.fclose(pFileHandle);
raise_application_error(-20006, 'Invalid Mode');
when UTL_FILE.READ_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20007, 'Read Error');
when OTHERS then
utl_file.fclose(pFileHandle);
sSQLCode := SQLCODE;
sSQLErrM := substr(SQLERRM, 1, 255);
raise_application_error(-20008, sSQLCode| |' - '| |sSQLErrM);
END;
To chop the record into separate fields you must use something like:
iStart := instr(sRecord, '|', 1, 2) + 1;
iLen := instr(sRecord, '|', 1, 3) - iStart;
if iLen = 0 then
sField := '#NULL#';
else
sField := substr(sRecord, iStart, iLen);
null -
Data formatting and reading a CSV file without using Sqlloader
I am reading a csv file to an Oracle table called sps_dataload. The table is structured based on the record type of the data at the beginning of
each record in the csv file. But the first two lines of the file are not going to be loaded to the table due to the format.
Question # 1:
How can I skip reading the first two lines from my csv file?
Question # 2:
There are more fields in the csv file than there are number of columns in my table. I know I can add filler as an option, but then there are
about 150 odd fields which are comma-separated in the file and my table has 8 columns to load from the file. So, do I really have to use filler
for 140 times in my script or, there is a better way to do this?
Question # 3:
This is more of an extension of my question above. The csv file has fields with block quotes - I know this could be achieved in sql loader when we mention Occassionally enclosed by '"'.
But can this be doable in the insert as created in the below code?
I am trying to find the "wrap code" button in my post, but do not see it.
Heres my file layout -
PROSPACE SCHEMATIC FILE
; Version 2007.7.1
Project,abc xyz Project,,1,,7,1.5,1.5,1,1,0,,0,1,0,0,0,0,3,1,1,0,1,0,0,0,0,2,3,1,0,1,0,0,0,0,3,3,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Subproject,25580-1005303.pst,,102,192,42,12632256,1,1,102,192,42,1,12632256,0,6,1,0,32896,1,0,0,0,0,,,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,0,1,1,,,,,,1
Segment, , , 0, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, , , , , , , , , , , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, , , 1
Product,00093097000459,26007,2X4 MF SF SD SOLR,,28.25,9.5,52.3, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.60,0,0,0,0,00,-1,0
Product,00093097000329,75556,"22""X22"" BZ CM DD 1548",,27,7,27, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,,345.32
Product,00093097000336,75557,"22""X46"" BZ CM XD 48133",,27,7.5,51, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,0
Product,00093097134833,75621,"22""X22"" BZ CM/YT DD 12828",,27,9,27, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,,1
This is my table structure -
desc sps_dataload;
File_Name Varchar2 (50) Not Null,
Record_Layer Varchar2 (20) Not Null,
Level_Id Varchar2 (20),
Desc1 Varchar2 (50),
Desc2 Varchar2 (50),
Desc3 Varchar2 (50),
Desc4 Varchar2 (50)
Heres my code to do this -
create or replace procedure insert_spsdataloader(p_filepath IN varchar2,
p_filename IN varchar2,
p_Totalinserted IN OUT number) as
v_filename varchar2(30) := p_filename;
v_filehandle UTL_FILE.FILE_TYPE;
v_startPos number; --starting position of a field
v_Pos number; --position of string
v_lenstring number; --length of string
v_record_layer varchar2(20);
v_level_id varchar2(20) := 0;
v_desc1 varchar2(50);
v_desc2 varchar2(50);
v_desc3 varchar2(50);
v_desc4 varchar2(50);
v_input_buffer varchar2(1200);
v_delChar varchar2(1) := ','
v_str varchar2(255);
BEGIN
v_Filehandle :=utl_file.fopen(p_filepath, p_filename, 'r');
p_Totalinserted := 0;
LOOP
BEGIN
UTL_FILE.GET_LINE(v_filehandle,v_input_buffer);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
-- this will read the 1st field from the file --
v_Pos := instr(v_input_buffer,v_delChar,1,1);
v_lenString := v_Pos - 1;
v_record_layer := substr(v_input_buffer,1,v_lenString);
v_startPos := v_Pos + 1;
-- this will read the 2nd field from the file --
v_Pos := instr(v_input_buffer,v_delChar,1,2);
v_lenString := v_Pos - v_startPos;
v_desc1 := substr(v_input_buffer,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
-- this will read the 3rd field from the file --
v_Pos := instr(v_input_buffer,v_delChar,1,3);
v_lenString := v_Pos - v_startPos;
v_desc2 := substr(v_input_buffer,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
-- this will read the 4th field from the file --
v_Pos := instr(v_input_buffer,v_delChar,1,4);
v_lenString := v_Pos - v_startPos;
v_desc3 := substr(v_input_buffer,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
-- this will read the 5th field from the file --
v_Pos := instr(v_input_buffer,v_delChar,1,5);
v_lenString := v_Pos - v_startPos;
v_desc4 := substr(v_input_buffer,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
v_str := 'insert into table sps_dataload values('||v_filename||','||v_record_layer||','||v_level_id||','||v_desc1||','||v_desc2||','||v_desc3||','||v_desc4||')';
Execute immediate v_str;
p_Totalinserted := p_Totalinserted + 1;
commit;
END LOOP;
UTL_FILE.FCLOSE(v_filehandle);
EXCEPTION
WHEN UTL_FILE.INVALID_OPERATION THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20051, 'sps_dataload: Invalid Operation');
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20052, 'sps_dataload: Invalid File Handle');
WHEN UTL_FILE.READ_ERROR THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20053, 'sps_dataload: Read Error');
WHEN UTL_FILE.INVALID_PATH THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20054, 'sps_dataload: Invalid Path');
WHEN UTL_FILE.INVALID_MODE THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20055, 'sps_dataload: Invalid Mode');
WHEN UTL_FILE.INTERNAL_ERROR THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20056, 'sps_dataload: Internal Error');
WHEN VALUE_ERROR THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE_APPLICATION_ERROR(-20057, 'sps_dataload: Value Error');
WHEN OTHERS THEN
UTL_FILE.FCLOSE(v_FileHandle);
RAISE;
END insert_spsdataloader;
/Justin, thanks. I did happen to change my pl sql procedure using utl_file.get_file and modifying the instr function based on position of ',' in the file, but my procedure is getting really big and too complex to debug. So I got motivated to use external tables or sql loader as plan b.
As I was reading more about creating an external table as an efficient way and thus believe I can perhaps build an extern table with my varying selection from the file. But I am still unclear if I can construct my external table by choosing different fields in a record based on a record identifier string value (which is the first field of any record). I guess I can, but I am looking for the construct as to how am I going to use the instr function for selecting the field from the file while creating the table.
PROSPACE SCHEMATIC FILE
; Version 2007.7.1
Project,abc xyz Project,,1,,7,1.5,1.5,1,1,0,,0,1,0,0,0,0,3,1,1,0,1,0,0,0,0,2,3,1,0,1,0,0,0,0,3,3,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Subproject,25580-1005303.pst,,102,192,42,12632256,1,1,102,192,42,1,12632256,0,6,1,0,32896,1,0,0,0,0,,,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,0,1,1,,,,,,1
Segment, , , 0, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, , , , , , , , , , , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, , , 1
Product,00093097000459,26007,2X4 MF SF SD SOLR,,28.25,9.5,52.3, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.60,0,0,0,0,00,-1,0
Product,00093097000329,75556,"22""X22"" BZ CM DD 1548",,27,7,27, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,,345.32
Product,00093097000336,75557,"22""X46"" BZ CM XD 48133",,27,7.5,51, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,0
Product,00093097134833,75621,"22""X22"" BZ CM/YT DD 12828",,27,9,27, 8421504,,0,,xyz INC.,SOLAR,,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,1,000000.20,0,0,0,0,0,0,0,,1For example, if I want to create an external table like this -
CREATE TABLE extern_sps_dataload
( record_layer VARCHAR2(20),
attr1 VARCHAR2(20),
attr2 VARCHAR2(20),
attr3 VARCHAR2(20),
attr4 VARCHAR2(20)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY dataload
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE dataload:'sps_dataload.bad'
LOGFILE dataload:'sps_dataload.log'
DISCARDFILE dataload:'sps_dataload.dis'
SKIP 2
VARIABLE 2 FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' LRTRIM
MISSING FIELD VALUES ARE NULL
+LOAD WHEN RECORD_LAYER = 'PROJECT' (FIELD2, FIELD3,FIELD7,FIELD9)+
+LOAD WHEN RECORD_LAYER= 'PRODUCT' (FIELD3,FIELD4,FIELD8,FIELD9)+
+LOAD WHEN RECORD_LAYER= 'SEGMENT' (FIELD1,FIELD2,FIELD4,FIELD5)+ LOCATION ('sps_dataload.csv')
REJECT LIMIT UNLIMITED;
{code}
While I was reading the external table documentation, I thought I could achieve similar things by using position_spec option, but I am not getting behind its parameters. I have highlighted italics in the code above(from LOAD WHEN....FIELDS....), the part I think I am going to use, but not sure of it's construct.
Thank you for your help!! Appreciate your thoughts on this..
Sanders.
Maybe you are looking for
-
USDA direct- my process-CLEAR TO CLOSE!
There is quite a bit of info out there on various mortgage processes but very little to be found by googling USDA direct. I figured I would share my experience so others might have some more info going into this process. I started rebuilding (in hone
-
How to revert file associations in Win8 back to CS6?
I have tried out CC. I am not convinced of its merits and worth the money, so I let the subscription end.No problem. I have CS6. But how can I revert file associations for example for .PNG or .JPG files back to PS CS6, instead of PS CC? Everytime I c
-
Parallelogram images showing up on exported PDF
I'm exporting a PDF (map) from ArcGIS Desktop. I've worked with Desktop for quite a number of years, and have exported hundreds of similar PDFs. During a print test I noticed what appears to be a white band running from one edge of the data frame to
-
I need a Query for BOM items to get, Inventory item Category, Inventory Item type and approved supplier, if any, for each item in BOM. for this I wrote a query, but i am getting Duplicate item. when I join MTL_SYSTEM_ITEMS_B, MTL_ITEM_CATEGORIES and
-
Audio Input Gain Too High - Line Input
Using GarageBand, I'm trying to record audio on the line level input. It records, but it's always too high. I can hear the distortion and see the clipping in GB. Using System Preferences Sound, I set the input level all the way to 0 and it makes no d