Appending CLOBS variables in PL/SQL
242416Dec 6 2005 — edited Jan 16 2006Hi,
I am trying to write a stored procedure that that takes a clob from header_table and conatenates it with all related lines from lines_table. Then returns the complete (header + all lines) clob as an OUT argument of a stored procedure.
I tried so many things but I came with no complete solution yet. Here are some points to concider:
- I don't want to change the value of the clob column in either tables. I want to take the header clob value inself and not the clob locator (as I would with NUMBER type variable for example).
- Both tables from where I take the clobs are dinamically assigned so the solution should contain that flexibility.
The next code is the minimum that works fine but returns only the header.
If I remove the "RETURN" line, I get "ORA-22920: row containing the LOB value is not locked" because it's a clob locator and not the clob value.
btr_obj.get_docHeader is also included:
CREATE OR REPLACE PROCEDURE GetFullDoc (vDocID IN NUMBER, vBuyerCode IN VARCHAR2, vComplete OUT CLOB)
IS
vDocType DocIDTable.doctype%TYPE;
vMainTableName DocTypeTable.doctablename%TYPE;
vLinesTableName DocTypeTable.doctablename%TYPE;
vLob1 CLOB:=EMPTY_CLOB;
TYPE cLinesType Is REF CURSOR;
cLines cLinesType;
BEGIN
SELECT doctype
INTO vDocType
FROM docidtable
WHERE docid=vDocID;
SELECT doctablename
INTO vMainTableName
FROM DocTypeTAble
WHERE DocType=vDocType;
btr_obj.get_docHeader(vMainTableName,vDocID,vComplete);
RETURN;
SELECT linestabname
INTO vLinesTableName
FROM BuyerLinesTab
WHERE BuyerCode=vBuyerCode
AND DocType=vDocType;
OPEN cLines FOR 'SELECT linedoc FROM '||vLinesTableName||' WHERE docid='||vDocID||' ORDER BY LineNumber';
LOOP
FETCH cLines INTO vLob1;
DBMS_LOB.APPEND(vComplete,vLob1);
EXIT WHEN cLines%NOTFOUND;
END LOOP;
END GetFullDoc;
/
PROCEDURE get_docHeader (vTableName IN varchar2,vDocId IN NUMBER,vHeader OUT CLOB)
IS
sqlstring VARCHAR2(300);
BEGIN
sqlstring := 'SELECT docfile FROM '||vTableName||' WHERE docid='||vDocId;
EXECUTE IMMEDIATE sqlstring INTO vHeader;
END get_docHeader;
Regards,
Doody Atraktsi