.net 调用oracle存储过程返回多个记录集

    1. CREATEORREPLACEPROCEDUREp_query_cs(
    2. p_infotypeINVARCHAR2,
    3. p_fromareacodeINVARCHAR2,
    4. p_toareacodeINVARCHAR2,
    5. p_keytypeINNUMBER,
    6. r_cursor1OUTsys_refcursor,--结果集
    7. r_cursor2OUTsys_refcursor--结果集
    8. )
    9. IS
    10. BEGIN
    11. OPENr_cursor1FOR
    12. SELECT*
    13. FROMpermit_menu;
    14. OPENr_cursor2FOR
    15. SELECT*
    16. FROMpermit_privilege;
    17. EXCEPTION
    18. WHENNO_DATA_FOUND
    19. THEN
    20. NULL;
    21. WHENOTHERS
    22. THEN
    23. RAISE;
    24. ENDp_query_cs;
    25. /
    using
    System.Data.OleDb;
  1. usingSystem.Data.OracleClient;
  2. protectedvoidcs1()
  3. {
  4. DataSetds=newDataSet();
  5. using(OleDbConnectionconn=newOleDbConnection("Provider=OraOLEDB.Oracle.1;Password=***;UserID=***;DataSource=***;PersistSecurityInfo=True;PLSQLRSet=1;"))
  6. {
  7. OleDbCommandcomm=newOleDbCommand();
  8. comm.Connection=conn;
  9. comm.CommandText="p_query_cs";
  10. comm.CommandType=CommandType.StoredProcedure;
  11. OleDbDataAdapterda=newOleDbDataAdapter(comm);
  12. //da.TableMappings.Add("table1","PERMIT_MENU");
  13. //da.TableMappings.Add("table2","PERMIT_PRIVILEGE");
  14. da.Fill(ds);
  15. for(intj=0;j<ds.Tables.Count;j++)
  16. {
  17. for(inti=0;i<ds.Tables[j].Rows.Count;i++)
  18. {
  19. for(intk=0;k<ds.Tables[j].Columns.Count;k++)
  20. {
  21. Response.Write(ds.Tables[j].Rows[i][k].ToString()+"|");
  22. }
  23. Response.Write("<br/>");
  24. }
  25. }
  26. }
  27. }
  28. protectedvoidcs3()
  29. {
  30. OracleConnectionconn=newOracleConnection("DataSource=***;UserId=***;Password=***");
  31. OracleCommandcmd=newOracleCommand();
  32. cmd.Connection=conn;
  33. cmd.CommandText="p_query_cs";
  34. cmd.Parameters.Add("r_cursor",OracleType.Cursor).Direction=ParameterDirection.Output;
  35. cmd.Parameters.Add("r_cursor1",OracleType.Cursor).Direction=ParameterDirection.Output;
  36. cmd.CommandType=CommandType.StoredProcedure;
  37. OracleDataAdapterda=newOracleDataAdapter(cmd);
  38. da.TableMappings.Add("Table","PERMIT_MENU");
  39. da.TableMappings.Add("Table1","PERMIT_PRIVILEGE");
  40. DataSetds=newDataSet();
  41. da.Fill(ds);
  42. for(intj=0;j<ds.Tables.Count;j++)
  43. {
  44. for(inti=0;i<ds.Tables[j].Rows.Count;i++)
  45. {
  46. for(intk=0;k<ds.Tables[j].Columns.Count;k++)
  47. {
  48. Response.Write(ds.Tables[j].Rows[i][k].ToString()+"|");
  49. }
  50. Response.Write("<br/>");
  51. }
  52. }
  53. }

你可能感兴趣的:(oracle,.net,J#)