2017-03-24 49 views
0

我想在Oracle SQL Developer中爲我的存儲過程返回一個XML輸出,並且希望將其作爲CLOB數據類型返回(建議我是否有比CLOB更好的方法) 。 我試圖谷歌,但找不到任何有用的資源。如何在ORACLE存儲過程中將OUTO參數返回爲CLOB

在此先感謝。

+0

究竟是如何存儲你的數據?例如,您可以將XML存儲爲CLOB。作爲CLOB位的OUT參數非常簡單。將數據轉換爲CLOB也很容易,因爲有像getClobVal()這樣的函數 – thatjeffsmith

+0

是的,我將XML存儲爲CLOB並返回爲OUT參數。我對Oracle非常陌生,所以無法解決它 – Santosh

+0

你會發現這個資源也很有價值我認爲https://community.oracle.com/community/development_tools/xml/pl_sql_xml_programming – thatjeffsmith

回答

1

下面是一個簡單的例子。

CREATE TABLE "XML_STUFF" 
    ( "COLUMN1" NUMBER(*,0) NOT NULL ENABLE, 
    "XML_STUFF" "SYS"."XMLTYPE" , 
    CONSTRAINT "XML_STUFF_PK" PRIMARY KEY ("COLUMN1") 
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 
    BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
    TABLESPACE "USERS" ENABLE 
    ) SEGMENT CREATION IMMEDIATE 
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
NOCOMPRESS LOGGING 
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 
    BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
    TABLESPACE "USERS" 
XMLTYPE COLUMN "XML_STUFF" STORE AS SECUREFILE CLOB (
    TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 
    NOCACHE LOGGING NOCOMPRESS KEEP_DUPLICATES 
    STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
    PCTINCREASE 0 
    BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) ; 

-- insert some XML/records into your table 

CREATE OR REPLACE PROCEDURE OUT_XML 
(
    PARAM1 IN INTEGER 
, PARAM2 OUT CLOB 
) AS 
xml_bits xmltype; 
BEGIN 
    select xml_stuff into xml_bits 
    from demo.xml_stuff 
    where column1 = param1; 

    param2 := xml_bits.getclobval(); 
    dbms_output.put_line(param2); -- this is just here to make it easier to 'see' 
END OUT_XML; 

--run it! 

DECLARE 
    PARAM1 NUMBER; 
    PARAM2 CLOB; 
BEGIN 
    PARAM1 := 1; 

    DEMO.OUT_XML(
    PARAM1 => PARAM1, 
    PARAM2 => PARAM2 
); 
    /* Legacy output: 
DBMS_OUTPUT.PUT_LINE('PARAM2 = ' || PARAM2); 
*/ 
    :PARAM2 := PARAM2; 
--rollback; 
END; 

enter image description here

+0

非常感謝@thatjeffsmith ...這工作對我來說 – Santosh

+0

如何處理表格中的列數據類型(我的XML存儲在其中)是clob(在這個示例中,XML數據保存在xmltype數據類型列XML_STUFF中)。 – Santosh

+0

它爲CLOB數據類型拋出一個錯誤:錯誤(9,10):PL/SQL:ORA-00932:不一致的數據類型:預計NUMBER獲得CLOB – Santosh

相關問題