简体   繁体   中英

How to read in c# oracle XmlType from store procedure

I'm trying to create a XML in stored procedure in this way:

PROCEDURE DeviceSearched(
   xml_out OUT XMLTYPE
)
IS
BEGIN

    SELECT 
      XMLELEMENT("Values", 
          XMLFOREST(de_brand)
    ) 
    INTO xml_out
    FROM 
      tbldevice de 
    ;  

END DeviceSearched;

And I trying to read xml_out in c# in this way:

...
OracleCommand command = new OracleCommand(name, conn);
command.CommandType = CommandType.StoredProcedure;
command.BindByName = true;
...
command.Parameters.Add(new OracleParameter("xml_out", OracleDbType.XmlType, ParameterDirection.Output));

With this approach the issues are two:

  1. Oracle exception: "ORA-01422: exact fetch returns more than requested number of rows"
  2. If I modify the query to obtain one row, the procedure is ok (I think), but in c# I don't have any result.

What am I doing wrong?

Thanks in advance

  • Running
    SELECT XMLELEMENT("Values",XMLFOREST(de_brand)) FROM tbldevice de In plsql will NOT result a single value, So trying to fetch the result in to single variable ( INTO xml_out ) will result run time error ORA-01422

  • Using a store procedure to select data in Oracle is not apperciated, its a SQL Server approch, why not using a simple select

  • Examples here and here will show how ODP.Net works with XML
    You may need to mix using ref corsur and XMLType to solve the matter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM