简体   繁体   English

Oracle的多个结果集

[英]Multiple Result Sets with Oracle

Simple Question: 简单问题:

My code looks like this: 我的代码看起来像这样:

        var con = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.20.10.8)(PORT=1521))(CONNECT_DATA=(SID=orcl12c)));");
        con.Open();

        var adp = new OracleDataAdapter("select * from adr;select * from person;", con);
        var ds = new DataSet();
        adp.Fill(ds);

Now I would expect to get two tables in the DataSet, but I rather get an exception telling me that the SQL Syntax is not correct... It seems the ; 现在我希望在DataSet中得到两个表,但是我得到一个例外,告诉我SQL语法不正确......似乎是; is not recognized that way..? 是不是承认那种方式..? Any Ideas? 有任何想法吗?

Edit #1: Also Adding BEGIN+END; 编辑#1: 还添加BEGIN + END; does not work (multiple variations) 不起作用(多种变化)

Edit #2: Wrapping the selects with execute immediate will run, but won't return a result set. 编辑#2: 使用execute immediate包装选择将运行,但不会返回结果集。

Solution : Combine the provided answer with Using Dapper with Oracle stored procedures which return cursors and enjoy. 解决方案 :将提供的答案与使用Dapper与Oracle存储过程相结合,后者返回游标并享受。

You should write an anonymous pl/sql block that returns ref cursors . 您应该编写一个返回ref cursors的匿名pl/sql块。

Try this in ADO.NET : ADO.NET试试这个:

    oraConnection = new OracleConnection();
    da = new OracleDataAdapter();
    ds = new DataSet();

    oraConnection.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.20.10.8)(PORT=1521))(CONNECT_DATA=(SID=orcl12c)));";
    cmdText = "begin open :1 for select * from adr; open :2 for select * from person; end;"; 
    cmd = new OracleCommand();
    cmd.CommandText = cmdText;
    cmd.Connection = oraConnection;
    cmd.CommandType = CommandType.Text; 

    OracleParameter refcur1 = cmd.Parameters.Add("Refcur", OracleDbType.RefCursor);
    refcur1.Direction = ParameterDirection.Output;
    OracleParameter refcur2 = cmd.Parameters.Add("Refcur", OracleDbType.RefCursor);
    refcur2.Direction = ParameterDirection.Output;

        da.SelectCommand = cmd;
        da.Fill(ds);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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