Note that there are some explanatory texts on larger screens.

plurals
  1. POC# OleDb Oracle function and Table Types
    primarykey
    data
    text
    <p>i'm trying to invoke an Oracle function that returns a type encapsulated in a Table</p> <p>Type Object</p> <pre><code>create or replace type Z_TBL_STRUCTURE_CODE AS OBJECT ( PROJ_ID varchar2(50 BYTE) ); </code></pre> <p>Type table</p> <pre><code>create or replace type Z_TABLE_STRUCTURE_CODE AS TABLE of Z_TBL_STRUCTURE_CODE; </code></pre> <p>Oracle Function</p> <pre><code>create or replace FUNCTION Z_TESTE_IN_FUNC ( var_teste in varchar2 ) return Z_TABLE_STRUCTURE_CODE AS tab Z_TABLE_STRUCTURE_CODE; BEGIN EXECUTE IMMEDIATE 'SELECT CAST( MULTISET( select count(*) into num from structure where structure_code in ('|| var_teste ||')) as Z_TABLE_STRUCTURE_CODE) into tab from dual;'; dbms_output.put_line(var_teste); return tab; END Z_TESTE_IN_FUNC; </code></pre> <p>NOTE: PLEASE IGNORE THE EXECUTE IMMEDIATE, ITS JUST FOR A TEST.</p> <p>NOTE2: I KNOW THERE IS AN OPTION TO AVOID TYPES (USING CURSORS) BUT I HAVE NOT YET BEEN ABLE TO UNDERSTAND THE TOPIC SO I WOULD ASK YOU TO IGNORE CURSOS WHEN ANSWERING, UNLESS ITS THE ONLY OPTION AVAILABLE.</p> <p>C# Code</p> <pre><code>public DataTable getTaskStartFinish() { OleDbConnection con = null; OleDbDataReader reader = null; try{ con = new OleDbConnection(ConfigurationManager.ConnectionStrings["OracleBD"].ConnectionString); OleDbCommand cmd = new OleDbCommand("", con); cmd.CommandText = "Z_TESTE_IN_FUNC"; cmd.CommandType = CommandType.StoredProcedure; OleDbParameter retval = new OleDbParameter("retval", OleDbType.VarChar, 10); retval.Direction = ParameterDirection.ReturnValue; OleDbParameter inval = new OleDbParameter("inval", OleDbType.Variant, 50); inval.Direction = ParameterDirection.Input; inval.Value = "1"; cmd.Parameters.Add(retval); cmd.Parameters.Add(inval); con.Open(); reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); return dt; } catch(Exception ex) { throw new Exception("getTaskStartFinish error: " + ex.Message); } finally { if(con != null) con.Close(); if(reader != null || !reader.IsClosed) reader.Close(); } } </code></pre> <p>The current Error i get is the following: ORA-06550: line 1, column 13: PLS-00382: expression is of wrong type ORA-06550: line 1, column 7: PL/SQL: Statement ignored</p> <p>I have seen in the net similar examples but all using ExecuteScalar() or some code for procedures or function returning singular values but not tables.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload