PL / SQL Array for CLOB

im using Oracle 9i.

I am collecting data from the cursor into an array:

FETCH contract_cur 
        BULK COLLECT INTO l_contract ;

But now I want to "convert" this l_contract to a CLOB variable l_clob

Is there an easy way to do this?

Or else, how to convert the rows from a SELECT statement to a single CLOB variable?

thank

EDIT: I forgot to mention the array array% ROWTYPE, not just one column.

+3
source share
2 answers

What an ugly thing.

Is this all personal data, or do you have numeric and / or date / time values ​​there too? If so, what format do you want to use for these data types when converting them to strings.

.

XML?

declare 
 v_clob clob;
 v_xml xmltype;
begin
 select xmlagg(XMLELEMENT("test",xmlforest(id,val)))
 into v_xml
 from test;
 select v_xml.getclobval
 into v_clob
 from dual;
 dbms_output.put_line(v_clob);
end;
/
+2

CLOB :

SQL> DECLARE
  2     TYPE tab_vc IS TABLE OF VARCHAR2(4000);
  3     l_contract tab_vc;
  4     l_clob CLOB;
  5  BEGIN
  6     dbms_lob.createtemporary (l_clob, TRUE);
  7     SELECT to_char(dbms_random.STRING('a', 1000)) BULK COLLECT
  8       INTO l_contract
  9       FROM dual
 10     CONNECT BY LEVEL <= 100;
 11     FOR i IN 1..l_contract.count LOOP
 12        dbms_lob.writeappend(l_clob,
 13                             length(l_contract(i)),
 14                             l_contract(i));
 15     END LOOP;
 16     -- your code here
 17     dbms_lob.freetemporary(l_clob);
 18  END;
 19  /

PL/SQL procedure successfully completed

l_contract - , CLOB , , , :

SQL> DECLARE
  2     l_clob CLOB;
  3  BEGIN
  4     dbms_lob.createtemporary (l_clob, TRUE);
  5     FOR cc IN ( SELECT to_char(dbms_random.STRING('a', 1000)) txt
  6                   FROM dual
  7                 CONNECT BY LEVEL <= 100) LOOP
  8        dbms_lob.writeappend(l_clob,
  9                             length(cc.txt),
 10                             cc.txt);
 11     END LOOP;
 12     -- your code here
 13     dbms_lob.freetemporary(l_clob);
 14  END;
 15  /

PL/SQL procedure successfully completed
+2

Source: https://habr.com/ru/post/1733549/


All Articles