DBMS_LOB.WRITEAPPEND - HELP!
Why is my code failing? All I am doing is reading text from an external file (UTL_FILE package) and appending it onto an NCLOB variable, but the WRITEAPPEND to the NCLOB variable is failiing. I know the WRITEAPPEND is failinb because I instrumented the code with DBMS_OUTPUT statement. I get the following error message with the following code:
DECLARE
ERROR at line 1:
ORA-22275: invalid LOB locator specified
ORA-06512: at "SYS.DBMS_LOB", line 328
ORA-06512: at line 39
ORA-22275: invalid LOB locator specified
CODE
====
DECLARE
the_val NCLOB;
filehdl UTL_FILE.FILE_TYPE;
buf VARCHAR2(32765);
still_reading BOOLEAN := TRUE;
BEGIN
filehdl := UTL_FILE.FOPEN('/tmp','reqmnt.txt','r',32765);
DBMS_LOB.CREATETEMPORARY(the_val, TRUE);
DBMS_LOB.OPEN(the_val, DBMS_LOB.LOB_READWRITE);
SELECT empty_clob() INTO the_val
FROM DUAL;
WHILE ( still_reading ) LOOP
BEGIN
UTL_FILE.GET_LINE(filehdl, buf);
-- Append the line to the variable.
-- THE FOLLOWING WRITEAPPEND STATEMENT IS FAILING AT RUNTIME
DBMS_LOB.WRITEAPPEND(the_val, 32765, TRANSLATE( buf USING NCHAR_CS ));
EXCEPTION
WHEN NO_DATA_FOUND THEN
still_reading := FALSE;
UTL_FILE.FCLOSE(filehdl);
WHEN OTHERS THEN
UTL_FILE.FCLOSE(filehdl);
RAISE;
END;
END LOOP;
DBMS_LOB.CLOSE(the_val);
DBMS_LOB.FREETEMPORARY(the_val);
-- <NOW DO SOME SORT OF INSERT STATEMENT WITH the_val>
EXCEPTION
WHEN OTHERS THEN
DBMS_LOB.CLOSE(the_val);
DBMS_LOB.FREETEMPORARY(the_val);
RAISE;
END;
null
You can use the returning clause to store the generated sequence value that was inserted into id into a variable, then reference that variable in the rest of your code, as demonstrated below.
SCOTT@10gXE> CREATE TABLE soundtable
2 (id NUMBER,
3 sound BLOB DEFAULT EMPTY_BLOB ())
4 /
Table created.
SCOTT@10gXE> CREATE SEQUENCE your_sequence
2 /
Sequence created.
SCOTT@10gXE> VARIABLE g_id_seq NUMBER
SCOTT@10gXE> INSERT INTO soundtable (id)
2 VALUES (your_sequence.NEXTVAL)
3 RETURNING id INTO :g_id_seq
4 /
1 row created.
SCOTT@10gXE> COMMIT
2 /
Commit complete.
SCOTT@10gXE> CREATE OR REPLACE DIRECTORY auddir AS 'C:\WINDOWS\Media'
2 /
Directory created.
SCOTT@10gXE> SET SERVEROUTPUT ON
SCOTT@10gXE> DECLARE
2 f_lob BFILE := BFILENAME ('AUDDIR', 'chimes.wav');
3 b_lob BLOB;
4 Lob BLOB;
5 Length INTEGER;
6 BEGIN
7
8 SELECT sound
9 INTO b_lob
10 FROM soundtable
11 WHERE id = :g_id_seq
12 FOR UPDATE;
13
14 dbms_lob.open (f_lob, dbms_lob.file_readonly);
15 dbms_lob.open (b_lob, dbms_lob.lob_readwrite);
16 dbms_lob.loadfromfile
17 (b_lob, f_lob, dbms_lob.getlength (f_lob));
18 dbms_lob.close(b_lob);
19 dbms_lob.close(f_lob);
20 COMMIT;
21
22 SELECT sound
23 INTO Lob
24 FROM soundtable
25 WHERE ID = :g_id_seq;
26 length := DBMS_LOB.GETLENGTH (Lob);
27 IF length IS NULL THEN
28 DBMS_OUTPUT.PUT_LINE ('LOB is null.');
29 ELSE
30 DBMS_OUTPUT.PUT_LINE ('The length is '|| length);
31 END IF;
32 END;
33 /
The length is 55776
PL/SQL procedure successfully completed.
SCOTT@10gXE>
Similar Messages
-
DBMS_LOB.WRITEAPPEND Max buffer size exceeded
Hello,
I'm following this guide to create an index using Oracle Text:
http://download.oracle.com/docs/cd/B19306_01/text.102/b14218/cdatadic.htm#i1006810
So I wrote something like this:
CREATE OR REPLACE PROCEDURE CREATE_INDEX(rid IN ROWID, tlob IN OUT NOCOPY CLOB)
IS
BEGIN
DBMS_LOB.CREATETEMPORARY(tlob, TRUE);
FOR c1 IN (SELECT ID_DOCUMENT FROM DOCUMENT WHERE rowid = rid)
LOOP
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('<DOCUMENT>'), '<DOCUMENT>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('<DOCUMENT_TITLE>'), '<DOCUMENT_TITLE>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH(NVL(c1.TITLE, ' ')), NVL(c1.TITLE, ' '));
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('</DOCUMENT_TITLE>'), '</DOCUMENT_TITLE>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('</DOCUMENT>'), '</DOCUMENT>');
FOR c2 IN (SELECT TITRE,TEXTE FROM PAGE WHERE ID_DOCUMENT = c1.ID_DOCUMENT)
LOOP
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('<PAGE>'), '<PAGE>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('<PAGE_TEXT>'), '<PAGE_TEXT>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH(NVL(c2.TEXTE, ' ')), NVL(c2.TEXTE, ' '));
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('</PAGE_TEXT>'), '</PAGE_TEXT>');
DBMS_LOB.WRITEAPPEND(tlob, LENGTH('</PAGE>'), '</PAGE>');
END LOOP;
END LOOP;
END;
Issue is that some page text are bigger than 32767 bytes ! So I've got an INVALID_ARGVAL...
I can't figure out how can I increase this buffer size and how to manage this issue ??
Can you please help me :)
Thank you,
Ben
Edited by: user10900283 on 9 févr. 2009 00:05Hi ben,
I'm afraid, that doesn't help much, since you have obviously rewritten your procedure based on the advise given here.
Coluld you please post your new procedure, as formatted SQL*Plus, embedded in {noformat}{noformat} tags, like this:SQL> CREATE OR REPLACE PROCEDURE create_index(rid IN ROWID,
2 IS
3 BEGIN
4 dbms_lob.createtemporary(tlob, TRUE);
5
6 FOR c1 IN (SELECT id_document
7 FROM document
8 WHERE ROWID = rid)
9 LOOP
10 dbms_lob.writeappend(tlob, LENGTH('<DOCUMENT>'), '<DOCUMENT>');
11 dbms_lob.writeappend(tlob, LENGTH('<DOCUMENT_TITLE>')
12 ,'<DOCUMENT_TITLE>');
13 dbms_lob.writeappend(tlob, LENGTH(nvl(c1.title, ' '))
14 ,nvl(c1.title, ' '));
15 dbms_lob.writeappend(tlob
16 ,LENGTH('</DOCUMENT_TITLE>')
17 ,'</DOCUMENT_TITLE>');
18 dbms_lob.writeappend(tlob, LENGTH('</DOCUMENT>'), '</DOCUMENT>');
19
20 FOR c2 IN (SELECT titre, texte
21 FROM page
22 WHERE id_document = c1.id_document)
23 LOOP
24 dbms_lob.writeappend(tlob, LENGTH('<PAGE>'), '<PAGE>');
25 dbms_lob.writeappend(tlob, LENGTH('<PAGE_TEXT>'), '<PAGE_TEXT>');
26 dbms_lob.writeappend(tlob
27 ,LENGTH(nvl(c2.texte, ' '))
28 ,nvl(c2.texte, ' '));
29 dbms_lob.writeappend(tlob, LENGTH('</PAGE_TEXT>'), '</PAGE_TEXT>')
30 dbms_lob.writeappend(tlob, LENGTH('</PAGE>'), '</PAGE>');
31 END LOOP;
32 END LOOP;
33 END;
34 /
Advarsel: Procedure er oprettet med kompileringsfejl.
SQL>
SQL> DECLARE
2 rid ROWID;
3 tlob CLOB;
4 BEGIN
5 rid := 'AAAy1wAAbAAANwsABZ';
6 tlob := NULL;
7 create_index(rid => rid, tlob => tlob);
8 dbms_output.put_line('TLOB = ' || tlob); -- Not sure, you can do this?
9 END;
10 /
create_index(rid => rid, tlob => tlob);
FEJL i linie 7:
ORA-06550: line 7, column 4:
PLS-00905: object BRUGER.CREATE_INDEX is invalid
ORA-06550: line 7, column 4:
PL/SQL: Statement ignored
SQL> -
Dbms_lob.writeappend is slow
I am having a table with number , float, double of 100 columns
need to read the table value and return as blob
so i have used utl_raw.CAST_FROM_
something like this
i have used loop to read each column data type and used bind variable to insert
TYPE varColtypelist is varray(100) of NUMBER(20);
collist varColtypelist;
TYPE varColLenlist is varray(100) of number(20);
byteLenList varColLenlist;
Select CASE WHEN data_type ='BINARY_FLOAT' THEN 1
WHEN data_type ='BINARY_DOUBLE' THEN 2
WHEN data_type ='NUMBER' THEN 3 END bulk collect into collist
from all_tab_columns where table_name=UPPER(Table_Name)
ORDER BY COLUMN_ID ;
v_cursor := DBMS_SQL.OPEN_CURSOR;
statment :='Select all columns from mytable order by c1 desc ' and rownum between 5000 to 10000
execute immediate 'Select byte_info from my_byte_info where id=1'
bulk collect into byteLenList ;
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.parse (v_cursor, statment, DBMS_SQL.native);
FOR col_ind IN 1 .. 100--(100 is 100 columns in that table)
LOOP
data_type := collist(col_ind);
if data_type =1 THEN
DBMS_SQL.define_column (v_cursor, col_ind, flid);
ELSIF data_type =2 THEN
DBMS_SQL.define_column (v_cursor, col_ind, dblid);
ELSIF data_type =3 THEN
DBMS_SQL.define_column (v_cursor, col_ind, nid);
END IF;
END LOOP;
dumy := DBMS_SQL.Execute (v_cursor);
LOOP
EXIT WHEN DBMS_SQL.FETCH_ROWS (v_cursor) = 0;
FOR i IN 1..l_max LOOP
data_type := collist(i);
ncollength := byteLenList(i);
if data_type =1 THEN
BEGIN
DBMS_SQL.column_value (v_cursor, i, flid);
value := utl_raw.cast_from_BINARY_FLOAT( flid);
END;
end if;
if data_type =2 THEN
BEGIN
DBMS_SQL.column_value (v_cursor, i, dblid);
value := utl_raw.cast_from_BINARY_DOUBLE( dblid);
END;
end if;
if data_type =3 THEN
BEGIN
DBMS_SQL.column_value (v_cursor, i, nid);
value := utl_raw.CAST_FROM_BINARY_INTEGER( nid);
END;
end if;
IF nNewRecord = 0 then
buffer1 := utl_raw.cast_to_varchar2(dbms_lob.substr(value));
dbms_lob.writeappend( l_out,ncollength,buffer1 );
End if;
IF nNewRecord = 1 then
nNewRecord := 0;
Select (utl_raw.cast_to_varchar2(dbms_lob.substr(var))) into l_out from dual;
end if;
end loop;
END LOOP;
DBMS_SQL.CLOSE_CURSOR (v_cursor);
it is something like
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.CAST_FROM_BINARY_INTEGER(int_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_DOUBLE(double_coulmn))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_FLOAT(float_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.CAST_FROM_BINARY_INTEGER(int_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_DOUBLE(double_coulmn))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_FLOAT(float_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_FLOAT(float_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.CAST_FROM_BINARY_INTEGER(int_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_FLOAT(float_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.CAST_FROM_BINARY_INTEGER(int_column))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_DOUBLE(double_coulmn))) from mytable
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(utl_raw.cast_from_BINARY_FLOAT(float_column))) from mytable
but it is time consuming taking more time to write and apennd
can we do it in alternate way.If you select a single concotenated result from table then how will you differentiate b/w datatypes of each column and how to convert them to blob.
Well that is the SAME question I ask you a month ago:
Also - if all you do is concatenate multiple values together how do you expect the result to be useful? No one will be able to tell where one value begins and the next ends.
I also ask you to do this:
Start over and tell us, in English, what BUSINESS PROBLEM you are trying to solve.
Provide a small amount (2 rows of 3 columns each) of sample data (in the form of INSERT statements, the DDL for a sample table (again - 3 columns) and show us what the result should be: 2 rows each having 1 CLOB, 1 row having 1 CLOB, etc.
What you say you are doing doesn't make much sense. That is why you were ask to explain it more fully. We can't help you if we don't know what you are really trying to do.
If you just string multiple VARCHAR2 values together that are different lengths without using some kind of delimiter it won't be meaningful.
And that seems to be just the problem you are asking about in your other thread:
https://community.oracle.com/thread/2614252?start=15&tstart=0
You caused the problem - we are asking you why are you doing that? -
Dbms_lob.writeappend in Oracle 11g
Hi,
we have this line of code
DBMS_LOB.writeappend(v_clob,doc_rec.seg_length,doc_rec.value) in our procedure.
when we run this code in oracle10g ,its not taking thath much time.But when we run in oracle 11g,its taking time.
I there any noncompatibility DBMS_LOB.writeappend for this function in oracle 11g.
Thanks in advancethanks abufazal...
actually after execution of below job, its not gathering the stats...
i have checked using select LAST_ANALYZED,TABLE_NAME from dba_tables where OWNER='XXXXX';
can anyone please suggest how to create job with scussful stats gather.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'example_job1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN
DBMS_STATS.gather_schema_stats("XXXXX", estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, cascade => TRUE);
END;',
start_date => TO_DATE('08-06-2013 18:00','DD-MM-YYYY HH24:MI'),
repeat_interval => 'FREQ=DAILY;BYDAY=TUE;BYHOUR=18;BYMINUTE=0;BYSECOND=0',
enabled => TRUE,
comments => 'Gather table statistics');
END;
Can you provide output of the following query
SQL> select job_name,job_action,start_date,last_start_date,last_run_duration,next_run_date,failure_count from dba_scheduler_jobs where job_name='EXAMPLE_JOB1';
If the failure_count is > 0, please do share the errors from alert log file. -
Dbms_lob.loadfromfile help
sorry in advance if this is basic - SQL developer virgin here . . .
Using the examples in this document
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10840/mm_uses.htm
specifically the code:
INSERT INTO soundtable(id, sound) VALUES (1, EMPTY_BLOB());
COMMIT;
DECLARE
f_lob BFILE := BFILENAME('AUDDIR','chimes.wav');
b_lob BLOB;
Lob BLOB;
Length INTEGER;
BEGIN
SELECT sound INTO b_lob FROM soundtable WHERE id=1 FOR UPDATE;
-- Open the LOBs.
dbms_lob.open(f_lob, dbms_lob.file_readonly);
dbms_lob.open(b_lob, dbms_lob.lob_readwrite);
dbms_lob.loadfromfile
(b_lob, f_lob, dbms_lob.getlength(f_lob));
-- Close the LOBs.
dbms_lob.close(b_lob);
dbms_lob.close(f_lob);
COMMIT;
-- Select the LOB:
SELECT sound INTO Lob FROM soundtable
WHERE ID = 1;
-- Opening the LOB is optional.
DBMS_LOB.OPEN (Lob, DBMS_LOB.LOB_READONLY);
-- Get the length of the LOB.
length := DBMS_LOB.GETLENGTH(Lob);
IF length IS NULL THEN
DBMS_OUTPUT.PUT_LINE('LOB is null.');
ELSE
DBMS_OUTPUT.PUT_LINE('The length is '|| length);
END IF;
-- Closing the LOB is mandatory if you have opened it.
DBMS_LOB.CLOSE (Lob);
END;
2 questions for anyone who has done this before or has an opinion:
1) In the initial insert -- INSERT INTO soundtable(id, sound) VALUES (1, EMPTY_BLOB()); -- if the value for the column "id" is sequence.next_val I could end up with an "id" of 3012 for example:
so how would I find out what value the "id" is before doing the next step:
SELECT sound INTO b_lob FROM soundtable WHERE id=1 FOR UPDATE;
I would have to do:
SELECT sound INTO b_lob FROM soundtable WHERE id=<whatever_was_generated_by_the_sequence> FOR UPDATE;
and if there are 10 people inserting at about the same time, how the heck am I supposed to know which "id" goes with which content file?
any help is appreciatedYou can use the returning clause to store the generated sequence value that was inserted into id into a variable, then reference that variable in the rest of your code, as demonstrated below.
SCOTT@10gXE> CREATE TABLE soundtable
2 (id NUMBER,
3 sound BLOB DEFAULT EMPTY_BLOB ())
4 /
Table created.
SCOTT@10gXE> CREATE SEQUENCE your_sequence
2 /
Sequence created.
SCOTT@10gXE> VARIABLE g_id_seq NUMBER
SCOTT@10gXE> INSERT INTO soundtable (id)
2 VALUES (your_sequence.NEXTVAL)
3 RETURNING id INTO :g_id_seq
4 /
1 row created.
SCOTT@10gXE> COMMIT
2 /
Commit complete.
SCOTT@10gXE> CREATE OR REPLACE DIRECTORY auddir AS 'C:\WINDOWS\Media'
2 /
Directory created.
SCOTT@10gXE> SET SERVEROUTPUT ON
SCOTT@10gXE> DECLARE
2 f_lob BFILE := BFILENAME ('AUDDIR', 'chimes.wav');
3 b_lob BLOB;
4 Lob BLOB;
5 Length INTEGER;
6 BEGIN
7
8 SELECT sound
9 INTO b_lob
10 FROM soundtable
11 WHERE id = :g_id_seq
12 FOR UPDATE;
13
14 dbms_lob.open (f_lob, dbms_lob.file_readonly);
15 dbms_lob.open (b_lob, dbms_lob.lob_readwrite);
16 dbms_lob.loadfromfile
17 (b_lob, f_lob, dbms_lob.getlength (f_lob));
18 dbms_lob.close(b_lob);
19 dbms_lob.close(f_lob);
20 COMMIT;
21
22 SELECT sound
23 INTO Lob
24 FROM soundtable
25 WHERE ID = :g_id_seq;
26 length := DBMS_LOB.GETLENGTH (Lob);
27 IF length IS NULL THEN
28 DBMS_OUTPUT.PUT_LINE ('LOB is null.');
29 ELSE
30 DBMS_OUTPUT.PUT_LINE ('The length is '|| length);
31 END IF;
32 END;
33 /
The length is 55776
PL/SQL procedure successfully completed.
SCOTT@10gXE> -
Hey Guys, I need some help here
Im doing some create view and create procedures for my work.
In creating view, its just done perfectly.
However with create procedures work, I got some problem with the result.
So here is the coding:
create or replace
PROCEDURE "USP_EDW_CASH_MARGIN"
result_cursor OUT TYPES.cursor_type
AS
CURSOR v_cursor IS
SELECT
to_char (CM100,'99999999999999.99'),
to_char (CM101,'99999999999999.99'),
to_char (CM200,'99999999999999.99'),
to_char (CM300,'99999999999999.99'),
to_char (CM301,'99999999999999.99'),
to_char (CM310,'99999999999999.99'),
to_char (CM320,'99999999999999.99'),
to_char (CM400,'99999999999999.99'),
to_char (CM401,'99999999999999.99'),
to_char (CM402,'99999999999999.99'),
to_char (CM500,'99999999999999.99'),
to_char (CM720,'99999999999999.99'),
to_char (CM730,'99999999999999.99'),
to_char (CM740,'99999999999999.99'),
to_char (CM999,'99999999999999.99')
FROM VW_CASH_MARGIN a;
v_id varchar2(100);
v_row varchar2(4000);
v_clob CLOB;
v_buffer varchar2(10000);
BEGIN
v_id := 'EDW_CASH_MARGIN';
DELETE FROM TBL_INTERFACE_DATA WHERE cd = v_id;
INSERT INTO TBL_INTERFACE_DATA (CD,INT_DATA,DT_CREATED)
VALUES (v_id,EMPTY_CLOB(),(SELECT CURR_PROC_DATE FROM TBL_PROC_DATE));
SELECT INT_DATA INTO v_clob
FROM TBL_INTERFACE_DATA
WHERE CD = v_id
FOR UPDATE;
OPEN v_cursor;
v_buffer := '';
dbms_output.put_line(LENGTH(v_buffer));
LOOP
FETCH v_cursor INTO v_row;
EXIT WHEN v_cursor%NOTFOUND;
if (length(v_buffer) + length(v_row)) < 10000 or v_buffer is null then
v_buffer := v_buffer || v_row;
else
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_buffer), v_buffer);
v_buffer := v_row;
end if;
END LOOP;
if LENGTH(v_buffer) > 0 then
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_buffer)-1, v_buffer);
end if;
CLOSE v_cursor;
OPEN result_cursor FOR
SELECT 'success' AS status FROM dual;
END;
After i run this coding.
I got these errors :
1)Error(46,5): PL/SQL: SQL Statement ignored.
2)Error(46,5): PLS-00394: wrong number of values in the INTO list of a FETCH statement
It says that the error is with this code "FETCH v_cursor INTO v_row;"
Can someone please help me.ok let me explain with emp table.
DECLARE
CURSOR c IS SELECT ename,sal FROM emp;
v_ename VARCHAR2(2000);
BEGIN
OPEN c;
LOOP
FETCH c INTO v_ename;
EXIT WHEN c%NOTFOUND;
Dbms_Output.put_line(v_name);
END LOOP;
CLOSE c;
END;Here i'm selecting 2 columns in the cursor and getting into one variable.
So i'm getting error like this
ORA-06550: line 7, column 1:
PLS-00394: wrong number of values in the INTO list of a FETCH statement
ORA-06550: line 7, column 1:
PL/SQL: SQL Statement ignored
DECLARE
CURSOR c IS SELECT ename,sal FROM emp;
v_ename VARCHAR2(2000);
v_sal NUMBER(10);
BEGIN
OPEN c;
LOOP
FETCH c INTO v_ename,v_sal;
EXIT WHEN c%NOTFOUND;
Dbms_Output.put_line(v_ename||v_sal);
END LOOP;
CLOSE c;
END;Here i'm selecting 2 columns in the cursor and getting into two different variables.so no error.
DECLARE
CURSOR c IS SELECT ename,sal FROM emp;
v_row c%rowtype; -->record type declaration
BEGIN
OPEN c;
LOOP
FETCH c INTO v_row;
EXIT WHEN c%NOTFOUND;
Dbms_Output.put_line(v_row.ename||v_row.sal);---> Here i'm mentioning which column to be printed
END LOOP;
CLOSE c;
END;Same thing i'm getting all columns variable into the records so no error.
and also pls read this
How to ask question
SQL and PL/SQL FAQ -
I have a table that holds multiple blobs i separate rows.
What i am trying to do is have a procedure that will combine all of these blobs in a certain order and insert into a new table.
I have the procedure below which does seem to work except for one major issue: it adds a null character ("00" in hex) between each append in the final blob.
So i end up with the following
[blob1_data]00[blob2_data]00[blob3_data]
I have been searching for a solution for a while and could use some expert help.
Here is what i have:
PROCEDURE INSERT_ATTACHMENT()
IS
CURSOR curATTACH IS
SELECT T.ATTACHMENT
FROM NEMS.NEMS_INET_ATTACH_TEMP T
WHERE T.ATTACH_KEY = pATTACH_KEY
ORDER BY T.ATTACH_SEQ;
blbATTACH NEMS.NEMS_ATTACHMENTS.ATTACHMENT%TYPE;
BEGIN
--combine blob seqments
dbms_lob.createtemporary(blbATTACH, false);
FOR lATTACH IN curATTACH LOOP
dbms_lob.writeappend(blbATTACH, length(lATTACH.Attachment), lATTACH.Attachment);
--dbms_lob.append(blbATTACH, lATTACH.Attachmnet);
END LOOP;
--insert into attachment table
INSERT INTO NEMS.NEMS_ATTACHMENTS
(ATTACHMENT)
VALUES
(blbATTACH);
END INSERT_ATTACHMENT;Ah yes the version,
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Also, i think i may have found a solution. I am going to test a few different files, but so far this looks promising:
--combine blob seqments
dbms_lob.createtemporary(blbATTACH, false);
FOR lATTACH IN curATTACH LOOP
dbms_lob.writeappend(blbATTACH, length(lATTACH.Attachment)-1, dbms_lob.substr(lATTACH.Attachment,length(lATTACH.Attachment)-1));
END LOOP; -
DBMS_lob Parameters/Arguments
Hello all!
Can anyone point me to the correct documentation that contains a list of parameters/arguments for DBMS_lob calls? I have the developers guide that deals with LOBs, but haven't found a list of arguments yet. In particular, I am looking for the following:
DBMS_lob.WRITE
DBMS_lob.WRITEAPPEND
DBMS_lob.APPEND
DBMS_lob.FILEOPEN
DBMS_lob.FILEGETNAME
DBMS_lob.SUBSTR
Any help would be greatly appreciated. Thank you!
Stevehttp://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_lob2.htm#998404
-
Error while creating AW using DBMS_LOB with XML..
Hi All,
I am trying to create AW using DBMS_LOB package with XML,
while creating AW,i am facing the following error.find the code also below :
declare
xml_awcreate_clob clob;
xml_awcreate_st varchar2(4000);
begin
DBMS_LOB.CREATETEMPORARY(xml_awcreate_clob,TRUE);
dbms_lob.open(xml_awcreate_clob, DBMS_LOB.LOB_READWRITE);
dbms_lob.writeappend(xml_awcreate_clob, 48, '<?xml version = ''1.0'' encoding = ''UTF-8'' ?>');
dbms_lob.writeappend(xml_awcreate_clob, 43, '');
dbms_lob.writeappend(xml_awcreate_clob, 63, '<AWXML version = ''1.0'' timestamp = ''Mon Feb 11 13:29:11 2002'' >');
dbms_lob.writeappend(xml_awcreate_clob, 15, '<AWXML.content>');
dbms_lob.writeappend(xml_awcreate_clob, 25, ' <Create Id="Action41">');
dbms_lob.writeappend(xml_awcreate_clob, 19, ' <ActiveObject >');
dbms_lob.writeappend(xml_awcreate_clob, 163, ' <AW Name="NEW_XML_AW" LongName="NEW_XML_AW" ShortName="NEW_XML_AW" PluralName="NEW_XML_AW" Id="NEW_XML.AW"/>');
dbms_lob.writeappend(xml_awcreate_clob, 19, ' </ActiveObject>');
dbms_lob.writeappend(xml_awcreate_clob, 11, ' </Create>');
dbms_lob.writeappend(xml_awcreate_clob, 16, '</AWXML.content>');
dbms_lob.writeappend(xml_awcreate_clob, 8, '</AWXML>');
dbms_lob.close(xml_awcreate_clob);
xml_awcreate_st := sys.interactionExecute(xml_awcreate_clob);
end;
ORA-21560: argument 2 is null, invalid, or out of range
ORA-06512: at "SYS.DBMS_LOB", line 833
ORA-06512: at line 12
Any idea or thought on this would be appreciable.
Thanks in advance.
AnwarDid you change any of the text in the lob write statements ?
I believe you get this error if you increase the number of characters without increasing the 1st argument which looks as though it represents the number of characters -
Using dbms_lob append to insert text how do you insert a new line inbetween
DBMS_LOB.APPEND (P_TEXT,'* Operator Phone,');
---- inbetween I need to insert new I am using DBMS_LOB.APPEND (P_TEXT,CHR(10)); IS there amy better method?
DBMS_LOB.APPEND (P_TEXT,'* Operator Email Address,');Sorry if the question was not clear ---
Lets say in the folowing example every write append needs to start on a new line followed by text. How do we do that?
Do we add another writeappend(cvar,22, chr(10)); inbetween?
dbms_lob.writeappend(cvar, 19, '<root><book><title>');
dbms_lob.writeappend(cvar, length(r.title), r.title);
dbms_lob.writeappend(cvar, 14, '</title><desc>');
dbms_lob.writeappend(cvar, length(r.description), r.description);
dbms_lob.writeappend(cvar, 27, '</desc></book><author_name>');
dbms_lob.writeappend(cvar, length(r.author_name), r.author_name);
dbms_lob.writeappend(cvar, 21, '</author_name></root>');
Edited by: user521218 on May 7, 2009 12:34 PM -
Dbms_lob , where did my time go ?
Hi all
After using 10046 to identify the sql that is causing the slowness in a program “ less commits cause my program to go slower” i realised that i am missing something ,
There was a lot of time missing in the tkprof file , and no sql or wait event allocate the missing time , so i put the following test case together in an attempt to understand where the time is going .
Version of test database : 11.1.0.6.0
Name of test database: stdby ( :-) used my standby database)
Database non-default values
# Parameter Value1
1: audit_file_dest /u01/app/oracle/admin/stdby/adump
2: audit_trail DB
3: compatible 11.1.0.0.0
4: control_files /u01/app/oracle/oradata/stdby/control01.ctl
5: control_files /u01/app/oracle/oradata/stdby/control02.ctl
6: control_files /u01/app/oracle/oradata/stdby/control03.ctl
7: db_block_size 8192
8: db_domain
9: db_name stdby
10: db_recovery_file_dest /u01/app/oracle/flash_recovery_area
11: db_recovery_file_dest_size 2147483648
12: diagnostic_dest /u01/app/oracle
13: dispatchers (PROTOCOL=TCP) (SERVICE=stdbyXDB)
14: memory_target 314572800
15: open_cursors 300
16: processes 150
17: remote_login_passwordfile EXCLUSIVE
18: undo_tablespace UNDOTBS1More accurately I used existing example from http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4084920819312
I hope Tom does not mind .
create table t ( x clob );
create or replace procedure p( p_open_close in boolean default false,
p_iters in number default 100 )
as
l_clob clob;
begin
insert into t (x) values ( empty_clob() )
returning x into l_clob;
if ( p_open_close )
then
dbms_lob.open( l_clob, dbms_lob.lob_readwrite );
end if;
for i in 1 .. p_iters
loop
dbms_lob.WriteAppend( l_clob, 5, 'abcde' );
end loop;
if ( p_open_close )
then
dbms_lob.close( l_clob );
end if;
commit;
end;I did the tracing and the run of the pkg with this
alter session set timed_statistics = true;
alter session set max_dump_file_size = unlimited;
alter session set tracefile_identifier = 'test_clob_commit';
alter session set events '10046 trace name context forever, level 12';
exec p(TRUE,20000);
exitDid the tkprof of the 10046 trace file with
tkprof stdby_ora_3656_test_clob_commit.trc stdby_ora_3656_test_clob_commit.trc.tkp sort=(prsela,exeela,fchela) aggregate=yes waits=yes sys=yesWith output of
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 0.02 0.02 0 0 0 0
Execute 1 46.89 147.81 38915 235267 492471 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 46.92 147.83 38915 235267 492471 1
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 0.00 0.00
latch: shared pool 24 0.05 0.07
latch: row cache objects 2 0.00 0.00
log file sync 1 0.01 0.01
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 117 0.11 0.10 0 0 2 0
Execute 426 0.37 0.40 6 4 9 2
Fetch 645 0.17 0.51 63 1507 0 1952
total 1188 0.65 1.03 69 1511 11 1954
Misses in library cache during parse: 22
Misses in library cache during execute: 22
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 19778 1.12 30.31
direct path write 19209 0.00 0.44
direct path read 19206 0.00 0.37
log file switch completion 8 0.20 0.70
latch: cache buffers lru chain 5 0.01 0.02
3 user SQL statements in session.
424 internal SQL statements in session.
427 SQL statements in session.And it’s here where the time is being lost.The time of the main pkg p(TRUE,2000) takes 147.83 sec, which is correct , but what is making this time up.
From sorted trace file
SQL ID : catnjk0zv6jz1
BEGIN p(TRUE,20000); END;
call count cpu elapsed disk query current rows
Parse 1 0.02 0.02 0 0 0 0
Execute 1 46.89 147.81 38915 235267 492471 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 46.92 147.83 38915 235267 492471 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 81
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
latch: shared pool 24 0.05 0.07
latch: row cache objects 2 0.00 0.00
log file sync 1 0.01 0.01
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.00 0.00
SQL ID : db78fxqxwxt7r
select /*+ rule */ bucket, endpoint, col#, epvalue
from
histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket
intresting , oracle is still using the rule hint in 11g ?
call count cpu elapsed disk query current rows
Parse 3 0.00 0.00 0 0 0 0
Execute 98 0.05 0.05 0 0 0 0
Fetch 98 0.04 0.17 28 294 0 1538
total 199 0.10 0.22 28 294 0 1538
Misses in library cache during parse: 0
Optimizer mode: RULE
Parsing user id: SYS (recursive depth: 3)
Rows Row Source Operation
20 SORT ORDER BY (cr=3 pr=1 pw=1 time=8 us cost=0 size=0 card=0)
20 TABLE ACCESS CLUSTER HISTGRM$ (cr=3 pr=1 pw=1 time=11 us)
1 INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=0 us)(object id 408)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 28 0.02 0.12
SQL ID : 5n1fs4m2n2y0r
select pos#,intcol#,col#,spare1,bo#,spare2,spare3
from
icol$ where obj#=:1
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0
Execute 19 0.03 0.03 0 0 0 0
Fetch 60 0.00 0.04 1 120 0 41
total 81 0.04 0.08 1 120 0 41
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: CHOOSE
Parsing user id: SYS (recursive depth: 2)
Rows Row Source Operation
1 TABLE ACCESS BY INDEX ROWID ICOL$ (cr=4 pr=0 pw=0 time=0 us cost=2 size=54 card=2)
1 INDEX RANGE SCAN I_ICOL1 (cr=3 pr=0 pw=0 time=0 us cost=1 size=0 card=2)(object id 42)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 1 0.04 0.04None of the parse , execute ,fetch and wait times makes up the 147.83 seconds.
So i turned to oracles trcanlzr.sql that Carlos Sierra wrote and parsed the same trace file to find the offending sql .
And it starts getting intrestting
Trace Analyzer 11.2.6.2 Report: trcanlzr_75835.html
stdby_ora_3656_test_clob_commit.trc (6970486 bytes)
Total Trace Response Time: 148.901 secs.
2009-MAY-03 20:03:51.771 (start of first db call in trace).
2009-MAY-03 20:06:20.672 (end of last db call in trace).
RESPONSE TIME SUMMARY
~~~~~~~~~~~~~~~~~~~~~
pct of pct of pct of
Time total Time total Time total
Response Time Component (in secs) resp time (in secs) resp time (in secs) resp time
CPU: 47.579 32.0%
Non-idle Wait: 0.467 0.3%
ET Unaccounted-for: 100.825 67.7%
Total Elapsed(1): 148.871 100.0%
Idle Wait: 0.001 0.0%
RT Unaccounted-for: 0.029 0.0%
Total Response(2): 148.901 100.0%
(1) Total Elapsed = "CPU" + "Non-Idle Wait" + "ET Unaccounted-for".
(2) Total Response = "Total Elapsed Time" + "Idle Wait" + "RT Unaccounted-for".
Total Accounted-for = "CPU" + "Non-Idle Wait" + "Idle Wait" = 148.872 secs.
Total Unccounted-for = "ET Unaccounted-for" + "RT Unaccounted-for" = 100.854 secs.{font:Courier}
{color:red}
{size:19}100.825 seconds Wow , that is a lot 67.7 % of the time is not accounted for {size}
{color}
{font}
I even used TVD$XTAT TriVaDis eXtended Tracefile Analysis Tool with the same conclution .
{font:Courier}
{color:green}
{size:19}Looking at the raw trace file i see a lot of lines like this{size}
{color}
{font}
WAIT #7: nam='direct path read' ela= 11 file number=4 first dba=355935 block cnt=1 obj#=71067 tim=1241337833498756
WAIT #7: nam='direct path write' ela= 12 file number=4 first dba=355936 block cnt=1 obj#=71067 tim=1241337833499153
WAIT #7: nam='db file sequential read' ela= 1095 file#=4 block#=399 blocks=1 obj#=71067 tim=1241337833501366{font:Courier}
{color:green}
{size:19}
What is even more interesting is the sql for "PARSING IN CURSOR #7" is not in the trace file !
The question is where is the time going or is the parser of the 10046 trace file just not putting the detail in ? How do i fix this, without speculating, if I do not know where the problem is ?
I thought of doing a strace on the process . Where else can i look for my 100 sec
Please point me in a direction where i can look for my 100,825 seconds as this is a test case with a production system that is loosing the same amount of time but with a lot more sql arround its dbms_lob.writeappend.
{size}
{color}
{font}
Edited by: user5174849 on 2009/05/16 11:17 PMuser5174849 wrote:
After using 10046 to identify the sql that is causing the slowness in a program “ less commits cause my program to go slower” i realised that i am missing something ,
There was a lot of time missing in the tkprof file , and no sql or wait event allocate the missing time , so i put the following test case together in an attempt to understand where the time is going .
Version of test database : 11.1.0.6.0
What is even more interesting is the sql for "PARSING IN CURSOR #7" is not in the trace file !
The question is where is the time going or is the parser of the 10046 trace file just not putting the detail in ? How do i fix this, without speculating, if I do not know where the problem is ?
I thought of doing a strace on the process . Where else can i look for my 100 sec
Please point me in a direction where i can look for my 100,825 seconds as this is a test case with a production system that is loosing the same amount of time but with a lot more sql arround its dbms_lob.writeappend.I guess that the separate cursor that is opened for the LOB operation is where the time is spent, and unfortunately this part is not very well exposed via the usual interfaces (V$SQL, 10046 trace file etc).
You might want to read this post where Kerry identifies the offending SQL via V$OPEN_CURSOR: http://kerryosborne.oracle-guy.com/2009/04/hidden-sql-why-cant-i-find-my-sql-text/
The waits of this cursor #7 are quite likely rather relevant since they probably show you what the LOB operation is waiting for.
The LOB is created with the default NOCACHE attribute therefore it's read and written using direct path operations.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Hi,
With regards to format the SQL trace files, could DBMS_LOB package helps us in order to format the SQL trace files instead of using TKPROF utility.
If so, could some one suggest how we use dbms_lob package in order to format the sql trace files.
Thanks
Kumarhi,
Should we read the SQL TRACE files USING DBMS_LOB?
I know in UTL_RAW package ,we can use utl_raw.cast_to_varchar2 to take a raw input and changes the data type from raw to varchar2.
But I don't have a sample code io order to test this.
Is that possible that via above point, we can read the sql trace files with out using TKPROF.
COuld some one have a little sample of it.
Thanks
Kumar -
Hi all
I am using dbms_lob.erase to delete part of data in my Clob
My question is does dbms_lob.erase also free up the space allocated by previous content of my clob?
If not is there someway to do it? After .erase i want to populate clob with different set of data and the amount of data is bigget than existing size of clob
Thanks for all your helpGalia,
I hope this example illustrates your question
completely:
SQL> declare
2 clb clob;
3 orig varchar2(10) := '1234567890';
4 adds varchar2(3) := '456';
5 amnt number := 3;
6 begin
7
8 dbms_lob.createtemporary(clb,true);
9 dbms_lob.write(clb,10,1,orig);
10 dbms_output.put_line('Original content: ' || clb);
11 dbms_lob.erase(clb,amnt,4);
12 dbms_output.put_line('After-erase content: ' || clb);
13 dbms_lob.writeappend(clb,3,adds);
14 dbms_output.put_line('After-writeappend content: ' || clb);
15 dbms_lob.write(clb,3,4,adds);
16 dbms_output.put_line('After-write content: ' || clb);
17 amnt := dbms_lob.getlength(clb);
18 dbms_lob.erase(clb,amnt);
19 dbms_output.put_line('After-complete erase content: ' || clb);
20 dbms_lob.write(clb,20,1,orig || orig);
21 dbms_output.put_line('New content: ' || clb);
22 end;
23 /
Original content: 1234567890
After-erase content: 123 7890
After-writeappend content: 123 7890456
After-write content: 1234567890456
After-complete erase content:
New content: 12345678901234567890
 
PL/SQL procedure successfully completed.Rgds. -
Dbms_lob and line size problem
Hi,
below is a simple function which returns a CLOB.
When I call this function from sqlplus and spool the result in a
file via the SPOOL command I get a line break after 80 characters.
When I replace in the function the CLOB type with a VARCHAR2 type
the whole TESTSTRING is printed on ONE line.
I do specify 'SET LINESIZE 200' in both cases and the length of
TESTSTRING is smaller than 200 characters.
How can I increase the line size for the CLOB case ?
CREATE OR REPLACE FUNCTION GetSimple (
RETURN CLOB
IS
RESULT CLOB;
TESTSTRING CONSTANT VARCHAR2(4000) := '123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_AFTER_LINEBREAK' ;
BEGIN
-- create CLOB for RETURN
dbms_lob.createtemporary(RESULT, TRUE);
dbms_lob.writeappend(RESULT, length(TESTSTRING), TESTSTRING);
RETURN RESULT;
END GetSimple;
/problem solved !
I had to add
SET LONGCHUNKSIZE 4096;
default is 80 -
Dbms_lob.copy vs. variable assignment
Cleanup of lob in java
Scenerio.
Java mid-tier application creates a CLOB variables to pass to Database PLSQL stored procedure One clob input, one output argument.
Input clob variable setup with dbms_lob.createtemporary(a,true,dbms_lob.call);
clob data taken from Front end written into with dbms_lob.writeappend.
Mid-tier app does NOT do a dbms_lob.createtemporary for second output variable.
Database stored procedure called to process data.
java call sp1(a in clob, b in out clob);
plsql sp on database...
procedure sp1(a in clob,b out clob)
is
lcl_clob clob;
begin
dbms_lob.createtemporary(lcl_clob,true,dbms_lob.call);
---- procedure process input clob data and when complete. filling lcl_clob with dbms_lob.copy
--When sp1 completes it does assignment to return data to java
b := lcl_clob; --this does deep copy
dbms_lob.freetemporary(lcl_clob);--free local temp clob
end;
Data gets back to JAVA midtier app. OK the Java app Read and Close clob.
Concern is about java's b defined clob and memory. How is java's defined b clob deep copy cleaned up?
Any memory/garbage issue on Java side with this? Mid tier server Weblogic on Win 2K
any ideas or issues. DB Environment: Oracle 8.1.7.3 on HPUX 11documentation says
There is also an interface to let you group temporary LOBs together into a logical bucket. The duration represents this logical store for temporary LOBs. Each temporary LOB can have separate storage characteristics, such as CACHE/ NOCACHE. There is a default store for every session into which temporary LOBs are placed if you don't specify a specific duration.
important part is below
Additionally, you are able to perform a free operation on durations, which causes all contents in a duration to be freed.
also
There is a default store for every session
i suppose its probably related with duration of lob u have used
Maybe you are looking for
-
How to hide username/password in JDBC program.
hi All, The support tat I get here is simply gr8. Can someone suggest or send me a link as to how I hide the username /password ....i.e database connection in the jdbc program so as to avoid changing the program everywhere in case username and passwd
-
Group Selected Items [Javascript / CS3]
This seems like it'd be an extremely easy thing to do, but I'm unable to figure it out after searching forums, google, and the scripting documentation. I'm trying to just group whatever items are selected when I run the script. Some of the things I'v
-
Why is Illustrator CS2 serial number not recognised in a new installation?
Dear Adobe Community I have deactivated CS 2 on my home computer in Oxford and I want to install it on my daughter's computer in Leeds for temporary use. The installation asks for a serial number. I have two, one that came with the software in 2007
-
10.6.4 iCal Server recently stopped updating 10.5 iCal clients
Mac mini OS X Server 10.6.4, iCal server has wiki groups with multiple calendars. Recently our 10.5.8 clients stopped reading/writing events to our 10.6 iCal server. Only the first calendar (the original auto-created when the group was created) is up
-
Delete obsolete not deleting archives
Hi, Platform : Windows 2003 Oracle : 10.2.0.4.0 We've following policy for RMAN : CONFIGURE RETENTION POLICY TO REDUNDANCY 1; CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACK