Estou precisando gerar em um arquivo XML os dados de determinada tabela, utilizando para isso PL/SQL.
Porém como nunca fiz isso via PL, comecei a pesquisar uns tutoriais de como fazer, porém não estou tendo sucesso.
O que ocorre é que ao seguir algumas instruções (tenho o 11g Express) sempre acusa estar faltando alguma declaração.
O UTL_FILE consegui solucionar, pois anteriormente informava que deveria ser declarado.
O erro agora é: PLS-00201: identifier 'DBMS_XMLQUERY.GETXML' must be declared
Segue código que estou tentando:
create or replace procedure p_geraxml
is
v_file Utl_File.File_Type;
v_xml CLOB;
v_more BOOLEAN := TRUE;
BEGIN
-- cria doc xml a partir da consulta
v_xml := DBMS_XMLQuery.GetXML('select * from emp');
-- gerar saída
v_file := Utl_File.FOpen('DIR_XML', 'test1.xml', 'w');
WHILE v_more LOOP
Utl_File.Put(v_file, Substr(v_xml, 1, 32767));
IF Length(v_xml) > 32767 THEN
v_xml := Substr(v_xml, 32768);
ELSE
v_more := FALSE;
END IF;
END LOOP;
Utl_File.FClose(v_file);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(Substr(SQLERRM,1,255));
Utl_File.FClose(v_file);
END;
/
Obrigado.