How to convert XMLTYPE in VARCHAR in ORACLE?

左心房为你撑大大i 提交于 2021-01-26 19:28:24

问题


I have two columns in my table(TRANSACTION) in ORACLE which are XMLTYPE(XML_IN and XML_OUT). My procedure is not working because I don't know how to convert them to VARCHAR or something(I just think that this is the error). My procedure is:

PROCEDURE SEARCH_XML
(
    P_ID_TRANSACTION IN TRANSACTION.ID_TRANSACTION%TYPE,

    P_CURSOR OUT T_CURSOR
)
IS
BEGIN

    OPEN P_CURSOR FOR

    SELECT T.XML_IN, T.XML_OUT
    FROM TRANSACTION T
    WHERE T.ID_TRANSACTION = P_ID_TRANSACTION;

END SEARCH_XML;

When I call this procedure error message in VisualStudio2008 is: "Unsupported oracle data type USERDEFINED encountered." Any idea how is this working?


回答1:


XMLType has two methods: getStringVal() and getClobVal() which will convert the XML structure to their string representations (as a VARCHAR2 and CLOB respectively). Unless you know that your XML output is going to always be less than 4000 characters (bytes) then you will probably want to use getClobVal() like this:

PROCEDURE SEARCH_XML
(
    P_ID_TRANSACTION IN TRANSACTION.ID_TRANSACTION%TYPE,

    P_CURSOR OUT T_CURSOR
)
IS
BEGIN
  OPEN P_CURSOR FOR
    SELECT T.XML_IN.getClobVal() AS XML_IN,
           T.XML_OUT.getClobVal() AS XML_OUT
    FROM TRANSACTION T
    WHERE T.ID_TRANSACTION = P_ID_TRANSACTION;
END SEARCH_XML;


来源:https://stackoverflow.com/questions/35039363/how-to-convert-xmltype-in-varchar-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!