Length of "out char" parameter in stored procedure

I call a SP with an output char parameter, the type is defined as a field in a table -- char(3),
but when calling from stored procedure, it throws an exception:
"ORA-01406: fetched column value was truncated"
the exception happens in line 4:
1. stmt->setSQL("call OUTPUT_CHAR1(:1)");
2. stmt->registerOutParam(1, OCCISTRING, 10);          
3. stmt->execute();
4. string result = stmt->getString(1);
One interesting thing is: if I use the same type as function return value(not output parameter), it works.
Friends, please give me some idea..

Just before commending about anyone it is good idea to go through Oracle Documentation .
Go through the following link
http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types
and
http://ora-01406.ora-code.com/ also
Basic difference is CHAR is fixed length and VARCHAR2 variable length which takes more buffer than a fixed length since the length is also stored.
Your error 'ORA-01406' is a common one in any place holder which does not have space to hold enough data. Thats why I told you to change to Varchar2 which is common fix in this case where exact data is not send to client unlike CHAR.
It is good that you are rude to me , so that I learned a lesson not help others much.
If you think the above explanation is also wrong , there are other experts in this forum , they will comment and not you alone

Similar Messages

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • Passing parameter into stored procedure

    Hi guys,
    I have a big problem here passing as a parameter in stored
    procedure.
    If i pass as a parameter in where clause it is working fine.
    Whenever i pass the parameter in order by it was not working..
    How to implement this issue????
    Here i am giving the example for package:
    PACKAGE XTRA.TEST_STATUS
    AS
    TYPE GenericCurTyp IS REF CURSOR;
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2,GENERAL_CUR IN OUT GenericCurTyp);
    END TEST_STATUS;
    PACKAGE BODY XTRA.TEST_STATUS
    AS
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2, GENERAL_CUR IN OUT GenericCurTyp
    ) AS
    BEGIN
    OPEN GENERAL_CUR FOR
    select last_name,first_name from applicant Order By insortgroup;
    END SP_MAIN;
    END TEST_STATUS;
    Passing as a parameter i am getting the below details.
    LAST_NAME FIRST_NAME
    ASFSDAF DASDFASF
    Ad DASD
    Adams John
    DANA WITEST
    If i hot code the parameter insortgroup to last_name
    i am getting the below values:
    LAST_NAME FIRST_NAME
    'ANNUNZIO GIANCOLA GABRIEL
    0'BRIEN ARMA
    0120453EZ ESTANISLAO
    082479 ELIZABETH
    Thanks,
    Rao

    CREATE OR REPLACE PACKAGE xtra.test_status
    AS
      TYPE GenericCurTyp IS REF CURSOR;
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp);
    END test_status;
    CREATE OR REPLACE PACKAGE BODY xtra.test_status
    AS
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp)
      AS
        select_statement VARCHAR2 (4000) := NULL;
      BEGIN
        select_statement :=
        'SELECT   last_name,
                  first_name
         FROM     applicant
         ORDER BY ' || insortgroup;
        DBMS_OUTPUT.PUT_LINE (select_statement);
        OPEN general_cur FOR select_statement;
      END sp_main;
    END test_status;

  • REF CURSOR as IN parameter to stored procedure

    Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
    Based on the project requirements it is necessary to pass
    multiple records to the stored procedure.
    In this case REF CURSOR as IN parameter is useful.
    What are the plans to implement REF CURSOR as IN parameter to stored procedure?
    What is the work around in case it is necessary to pass several different
    record types as arrays to stored procedure?

    ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
    An excerpt from Application Developer's Guide:
    "If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call".

  • How to use OUT variables in my stored procedure

    I'm wondering if I can get some help using OUT variables in my stored procedure. Here's my code...
    CREATE OR REPLACE PROCEDURE testProj.testProcedure (
         v_segment_id IN VARCHAR2,
         v_student_id OUT VARCHAR2,
         v_current_code OUT NUMBER,
         v_new_code OUT NUMBER
    ) AS
    BEGIN
         SELECT
              s.student_id,
              s.quad_code_id,
              nc.quad_code_id
         INTO
              v_student_id,
              v_current_quad_code,
              v_new_quad_code
         FROM testProj.students s
         INNER JOIN testProj.new_codes nc ON s.student_id = nc.student_id
         WHERE s.segment_id = v_segment_id ;
    END testProcedure ;
    EXECUTE testProj.testProcedure ('44') ;
    When I execute that stored procedure with the above execute statement, I get this error:
    Error report:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'testProcedure'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    +06550. 00000 - "line %s, column %s:\n%s"+
    *Cause:    Usually a PL/SQL compilation error.+
    *Action:+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Using Refcursor is one way you can do that ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.21
    satyaki>
    satyaki>
    satyaki>create or replace procedure r_arg(
      2                                      choice in number,
      3                                      b in out sys_refcursor
      4                                   )
      5  is  
      6    str   varchar2(500);
      7  begin   
      8     str := 'select * from emp';   
      9     open b for str;
    10  exception  
    11    when others then     
    12      dbms_output.put_line(sqlerrm);
    13  end;
    14  /
    Procedure created.
    Elapsed: 00:00:01.84
    satyaki>
    satyaki>
    satyaki>declare   
      2    rec_x emp%rowtype;   
      3    w sys_refcursor;
      4  begin  
      5    dbms_output.enable(1000000);  
      6    r_arg(1,w);  
      7    loop    
      8      fetch w into rec_x;     
      9        exit when w%notfound;             
    10        dbms_output.put_line('Employee No: '||rec_x.empno||' - '||                          
    11                             'Name: '||rec_x.ename||' - '||                          
    12                             'Job: '||rec_x.job||' - '||                          
    13                             'Manager: '||rec_x.mgr||' - '||                          
    14                             'Joining Date: '||rec_x.hiredate||' - '||                          
    15                             'Salary: '||rec_x.sal||' - '||                          
    16                             'Commission: '||rec_x.comm||' - '||                          
    17                             'Department No: '||rec_x.deptno);  
    18     end loop;  
    19     close w;    
    20  exception  
    21    when others then    
    22       dbms_output.put_line(sqlerrm);
    23  end;
    24  /
    Employee No: 9999 - Name: SATYAKI - Job: SLS - Manager: 7698 - Joining Date: 02-NOV-08 - Salary: 55000 - Commission: 3455 - Department No: 10
    Employee No: 7777 - Name: SOURAV - Job: SLS - Manager:  - Joining Date: 14-SEP-08 - Salary: 45000 - Commission: 3400 - Department No: 10
    Employee No: 7521 - Name: WARD - Job: SALESMAN - Manager: 7698 - Joining Date: 22-FEB-81 - Salary: 1250 - Commission: 500 - Department No: 30
    Employee No: 7566 - Name: JONES - Job: MANAGER - Manager: 7839 - Joining Date: 02-APR-81 - Salary: 2975 - Commission:  - Department No: 20
    Employee No: 7654 - Name: MARTIN - Job: SALESMAN - Manager: 7698 - Joining Date: 28-SEP-81 - Salary: 1250 - Commission: 1400 - Department No: 30
    Employee No: 7698 - Name: BLAKE - Job: MANAGER - Manager: 7839 - Joining Date: 01-MAY-81 - Salary: 2850 - Commission:  - Department No: 30
    Employee No: 7782 - Name: CLARK - Job: MANAGER - Manager: 7839 - Joining Date: 09-JUN-81 - Salary: 4450 - Commission:  - Department No: 10
    Employee No: 7788 - Name: SCOTT - Job: ANALYST - Manager: 7566 - Joining Date: 19-APR-87 - Salary: 3000 - Commission:  - Department No: 20
    Employee No: 7839 - Name: KING - Job: PRESIDENT - Manager:  - Joining Date: 17-NOV-81 - Salary: 7000 - Commission:  - Department No: 10
    Employee No: 7844 - Name: TURNER - Job: SALESMAN - Manager: 7698 - Joining Date: 08-SEP-81 - Salary: 1500 - Commission: 0 - Department No: 30
    Employee No: 7876 - Name: ADAMS - Job: CLERK - Manager: 7788 - Joining Date: 23-MAY-87 - Salary: 1100 - Commission:  - Department No: 20
    Employee No: 7900 - Name: JAMES - Job: CLERK - Manager: 7698 - Joining Date: 03-DEC-81 - Salary: 950 - Commission:  - Department No: 30
    Employee No: 7902 - Name: FORD - Job: ANALYST - Manager: 7566 - Joining Date: 03-DEC-81 - Salary: 3000 - Commission:  - Department No: 20
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.48
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • Find out if a certain Stored Procedure runs

    Hi all,
    i have to state that i dont have much oracle specific database knowledge but i've spend half a day now gathering information about a certain problem and didnt find any really working solution.
    What i want is to be able to find out if a certain stored procedure is currently running (executing) in the database. I need that to be able to prevent a user of my client application from executing a certain procedure more than once in the same time.
    I have found some interesting information about the oracle Call Stack (dbms_utility.format_call_stack) but its not as helpfull as i orginaly thought because as far as i can see it only shows which procedures where executed (and are still executing) while the procedure with the dbms_output.put_line(dbms_utility.format_call_stack) command is executing.
    But it doesnt show anything about procedures which are running in another instance of SQL*Plus, for example.
    I have no other idea at the moment ...
    So i hoped anybody in here maybe has an idea or maybe allready a solution.
    But ... thanx in anyway =).
    With greetings from germany,
    Oliver Bankel

    I'm sure there are several solutions.
    This is how we solve this problem, not elegant but it works.
    We have a table of procs that are running.
    Active_Jobs
    JOBNAME    VARCHAR2(35)
    USERNAME   VARCHAR2(30)
    STATUS     VARCHAR2(20)
    Then within the proc
    job_conflict               EXCEPTION;
    BEGIN
    select count(1) into v_status from ACTIVE_JOBS
    where username = USER and status = 1 ;
    if v_status > 1 then
       RAISE JOB_CONFLICT ;
    end if;
    INSERT INTO ACTIVE_JOBS (JOBNAME, USERNAME, STATUS)
       VALUES ('PROC NAME', USER, 1) ;
    COMMIT;
    DELETE FROM ACTIVE JOBS WHERE JOBNAME = 'PROC NAME' AND USERNAME = USER ;
    COMMIT;
    exception
       WHEN job_conflict THEN
         raise_application_error( -20010,'YOUR MESSAGE HERE');
    END;

  • Return a parameter through stored procedures

    Hello Experts
    I want to return parameter through stored procedures so as to ensure that the application has been executed properly.
    My source message format is
    <StatementName5>
    <storedProcedureName action=u201D EXECUTEu201D>
      <table>Summarize_prc</table>
    <empid  [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</empid>
    </storedProcedureName > 
    </StatementName5>
    Do i need to put some extra parameters for return values from the stored procedures?
    What would be the response message format to return the parameters from stored procedure.
    Thanks
    Sabyasachi

    Hi,
    If you wants to read the return values from stored procedure, the scanario should be designed as Sync.
    The format looks like thsi
    <Message Type Name>
          <STATEMENTNAME_response>
                      <Field1> </Field1>
       </STATEMENTNAME_response>
    </Message Type Name>

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Cannot get OUT parameter from stored procedure

    Hi,
    I am new to stored procedure programming. I wrote a simple java stored procedure as follows:
    package fvt;
    import java.sql.*;
    import java.io.*;
    public class FVTProcedures
    extends COM.ibm.db2.app.StoredProc {
    public void addRecord(int id, String name, int status)
    throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.Connection con = null;
    PrintWriter pw = null;
    try {
    status =3;
    pw = new PrintWriter(new FileWriter("c:/temp/fvtproc.txt"));
    pw.println("starting...");
    // get connection
    con =getConnection();
    pw.println("Got connection");
    stmt = con.createStatement();
    stmt.execute("INSERT INTO cmtest (id, name) values (" + id + ",'"+name+"')");
    pw.println("Inserted the record");
    if (!con.getAutoCommit()) {
    con.commit();
    pw.println("Committed the connection");
    catch (SQLException sqle) {
    pw.println(sqle.getMessage());
    catch (Exception e) {
    pw.println(e.getMessage());
    finally {
    status =2;
    pw.close();
    try {
    if (stmt != null) {
    stmt.close();
    catch (SQLException sqle) {}
    try {
    if (con != null) {
    con.close();
    catch (SQLException sqle) {}
    Then I use the following sql command to create this stored procedure, especially register status as OUT parameter.
    CREATE PROCEDURE addRecord (IN id INT, IN name VARCHAR(20), OUT status INTEGER)
    FENCED LANGUAGE JAVA EXTERNAL NAME 'fvt.FVTProcedures!addRecord' PARAMETER
    STYLE DB2GENERAL
    My java program calling this stored proc is as follows:
    import java.sql.*;
    import javax.sql.*;
    public class CallableStmtTest {
         COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource ds = null;
         public static void main(String args[]) {
              CallableStmtTest dt = new CallableStmtTest();
              try {
                   dt.test();
              } catch (Exception e) {
                   e.printStackTrace(System.out);
         public CallableStmtTest() {
              ds = new COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource();
              ds.setUser("username");
              ds.setPassword("password");
              ds.setDatabaseName("database");
    public void test() {
    java.sql.Connection conn = null;
    CallableStatement cs = null;
    String sql = "CALL ADDRECORD(?, ?, ?)" ;
    try {
    conn = ds.getPooledConnection().getConnection();
    conn.setAutoCommit(false);
    System.out.println("Got the connection");
    cs = conn.prepareCall( sql ) ; /* con is the connection */
    System.out.println("Callable statement is prepared");
    cs.registerOutParameter(3, java.sql.Types.INTEGER);
    cs.setInt(1, 1001 );
    cs.setString(2, "1001");
    cs.execute() ;
    System.out.println("Callable statement is executed, return status: "+cs.getInt(3));
    conn.commit();
    catch(SQLException sqle) {
    sqle.printStackTrace();
    finally {
    try {
    if (cs!=null) {cs.close();}
    catch (SQLException sqle1) {
    try {
    if (conn!=null) {conn.close();}
    catch (SQLException sqle1) {
    However, the out put is always
    Callable statement is executed, return status: 0
    while i expect to be
    Callable statement is executed, return status: 2
    Can anyone tell me what's wrong with that?
    thansk,
    JST

    public void addRecord(int id, String name, int status)
    throws SQLException {
    status =3;In regular java you are never going to see this value (3) outside of that method. Java doesn't work that way.
    So unless java inside the DB works really differently from regular java, you are going to have to pass something else.

  • Datetime parameter from stored procedure

    <p>I have a report written in CR10 which uses a stored procedure as the datasource. The stored procedure has 3 input parameters, two of which are datetime data types. When the crystal report is run, it prompts the user for the 3 parameters & runs just fine except...</p><p>For the date parameters, it prompts the user to enter a time as well. In previous versions of Crystal, parameters that were datetime data types in the stored procedure were just prompted for the date when the calling crystal report was run.</p><p>I attempted to edit the parameters in the report, but the "Value Type" is grayed out (I assume since the parameter is associated with the stored procedure, rather than being a user defined parameter within the report).  These date parameters are used in a BETWEEN statement in the stored proc, so if the user just enters a date but accepts the default time, the returned data gets flakey due to the addition of the time value passed by the parameter.</p><p> I tried setting a default value for the time, but I have to enter a date along with the time, which the report then uses as the default. The user then has to uncheck the "Pick from defaults" checkbox in order to enter their own date. This is really unwieldly for the end user, especially when they were previously able to just enter a date and not have to be concerned with a time at all.</p><p>Does anyone have suggestions on working around this issue? </p><p>Thanks in advance...</p>

    <p>You mention that you are using CRW version 10 for this.  What&#39;s the data source you are reporting against (you mention a stored procedure - but are you running against Oracle, SQL Server, DB2?).  Are you connecting natively or using ODBC? <br /></p>

  • How to fetch %ROWTYPE OUT param of  a stored procedure from Java program?

    I have a stored procedure that has IN / OUT parameter as table_name%ROWTYPE.
    From a java program how can I access this ROWTYPE variable?
    I tried all possible documentation and none of the explains whether or not this is supported.
    My use case expect exactly 1 record from the procedure and we would prefer not to use REF CURSOR.
    Is there a way to achieve this? If so, can someone help me with it by posting the sample code to achieve this?
    I tried all the possible OracleTypes to register the OutParameter and they all fail.
    Looks like there isn't any equivalent of %ROWTYPE in OracleTypes either.
    If you need, I can post my sample procedure that uses %ROWTYPE as OUT parameter.
    I really appreciate your help in this regard.
    - Karthik

    Hi,
    If "returning only 1 record" the showstopper for not using Ref Cursor, you might want to reconsider because as you probably know, the ref cursor is only a pointer and requires additional step to retrieve the data.
    Kuassi

  • IN Operator Parameter using stored procedure

    Hi Guys,
    I'm running a reporting services report using stored procedure and I'm facing a dilemma with the IN Operator in the stored procedure.
    Can someone please help me out debugging the statement below? (run it on AdventureWorks Database)
    Can I have the @Title Parameter based on another select statement something like this 
    Set @Title = SELECT Title FROM TableTitle
    DECLARE @Title varchar(1000)
    set @Title = 'Design Engineer', 'Tool Designer', 'Marketing Assistant'
    SELECT FirstName, LastName, e.Title
    FROM HumanResources.Employee AS e
    JOIN Person.Contact AS c
    ON e.ContactID = c.ContactID
    WHERE e.Title IN (@Title)
    Appreciate all the help on this.
    Thank you
    John

    Hi John,
    For your problem, we can use dynamical statement to solve the issue.
    Here are 2 options to be clarified:
             1. A multi-value parameter will return an array value.
             2. It is not able to pass an array in a stored procedure.
    To solve the issue, we can use the following steps:
    1.              Cconvert the array into string that delimited by “,” using the function “Join” in SQL Server Reporting Services.
    2.              Pass the string in the stored procedure.
    3.              Combine the parameter and the statement into one simply string.
    4.              Execute the simply string.
    Here are the detailed steps for your reference:
    1.       In Report Designer, create a new dataset as “SELECT Title FROM TableTitle”.
    2.       Create a new multi-value parameter, set the available value from the dataset above.
    3.       Set the query of the main dataset as :
    ="spSelect_Title "&Join(Parameters!para.Value, ",")
    4.       Change the stored procedure as:
    ALTER PROCEDURE [dbo].[spSelect_Title]
             -- Add the parameters for the stored procedure here
             --@Query NVarchar(Max),
             @Title NVarchar(MAX)
    AS
    BEGIN
             -- SET NOCOUNT ON added to prevent extra result sets from
             -- interfering with SELECT statements.
             SET NOCOUNT ON;
             DECLARE @Query Varchar(Max)
             SET @Query = 'SELECT FirstName, LastName, e.Title
             FROM HumanResources.Employee AS e
             JOIN Person.Contact AS c
             ON e.ContactID = c.ContactID
             WHERE e.Title IN (' + @Title+ ')'
    --       PRINT ' QUERY = '+ ISNULL(@Query,'NULL')
             Execute sp_executesql @Query
    END
    If you have any more questions, please feel free to ask.
    Thanks,
    Jin
    Jin Chen - MSFT

  • Passing parameter in stored procedure

    Hi, I am really new to using Oracle stored procedure. I have just tested a sample stored proc which should return multiple rows without passing any parameter.
    here is the stored proc I wrote
    create or replace procedure get_address
    as
    cur_table sys_refcursor;
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    when I execute it, I get a message "Procedure Created"
    then I executed the stored proc
    exec get_address;
    I again get a message "PL/SQL procedure successfully completed" and I do not see the records at all.
    so I decide to rewrite to the stored proc as such
    create or replace procedure get_address(cur_table out sys_refcursor)
    as
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    everthing is good so far.
    now when execute it
    exec get_address;
    I am getting the following error:
    "PLS-00306: wrong number or types of arguments in call to 'TESTCODEPROC'"
    I have searched so many places, but there is no document talks about this issue. I hope someone can help me to over come this. I need to call this stored proc from .NET 2.0 reporting viewer which is embedded in asp.net page.
    Thank you.

    so I decide to rewrite to the stored proc as such
    create or replace procedure get_address(cur_table out
    sys_refcursor)
    as
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    everthing is good so far.
    now when execute it
    exec get_address;
    I am getting the following error:
    "PLS-00306: wrong number or types of arguments in
    call to 'TESTCODEPROC'"
    From what you wrote I can assume that you have used SQL server before. Oracle does not automatically return the last opened cursor from a stored procedure like the query result, so you cannot just call exec get_address; (or just execute the procedure from .NET code). You will have to pass the cursor parameter and fetch it as an output parameter value in .NET, then use it to get the data reader etc.
    On the other hand, you can just execute the statement directly. I see a lot of folks coming from SQL server world using stored procedures like crazy even for things that are naturally suited to queries and views. Oracle view allows you to apply the same security restrictions you can put onto a stored procedure, and if you use statement caching and bound variables, you get precompilation benefits as well with a view. Using a view instead of a procedure in this case will require less code both in the database and in .NET, and will give you a more flexible interface in terms of retrieved columns and ordering.
    gojko adzic
    http://gojko.net

  • Passing parameter to stored procedure from windows form getting error

    I've written a procedure which shows the data in a table according to the table flag selected from the windows form. My code is:
    --- stored procedure ------
    CREATE PROC [dbo].[PROC_SELECT_TABLES]
    @TBL_FLAG INT
    AS
    BEGIN
    SET NOCOUNT ON;
    IF (@TBL_FLAG = 1)
    SELECT * FROM MHT_APPUSER ;
    IF (@TBL_FLAG = 2)
    SELECT * FROM MHT_ISA11 ;
    IF (@TBL_FLAG = 3)
    SELECT * FROM MHT_ISA22 ;
    SET NOCOUNT OFF;
    END
    GO
    Now, the module for calling the above procedure
    namespace DAL;
    public class DisplayData
    SqlLayer layer = new SqlLayer();
    public int tblFlag { get; set; }
    public DataTable GetData(int tblFlag)
    SqlParameter[] p = new SqlParameter[1];
    p[0] = new SqlParameter("@tblFlag", this.tblFlag);
    return layer.ExecuteDataSet("PROC_SELECT_TABLES", p).Tables[0];
    Now the SQL LAYER, containing the ExecuteDataSet and database connection code:
    namespace DAL;
    public class SqlLayer
    // sql connection code
    public DataSet ExecuteDataSet(string commandText, SqlParameter[] sqlParameter)
    SqlCommand cmd = new SqlCommand(commandText, this.conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddRange(sqlParameter);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    return ds;
    Now the windows form layer:
    using DAL;
    namespace BookKeepingSystem
    public partial class DisplayDataForm : Form
    DisplayData view = new DisplayData();
    private void GetData()
    view.tblFlag = 3;
    DataTable dt = view.GetData(view.tblFlag);
    dgvDisplayData.DataSource = dt;
    public DisplayDataForm()
    InitializeComponent();
    private void DisplayData_Load(object sender, EventArgs e)
    GetData();
    private void btnExit_Click(object sender, EventArgs e)
    Application.Exit();
    When I run the code I got the error:
    "Unhandled exception has occurred in your application...
    Procedure or function 'PROC_SELECT_TABLES' expects parameter @TBL_FLAG, which was not supplied"
    I can not figure what is missing with my code. Please can any one point out please.
    Thank You!!!

    Try something like this for starting -- do just this procedure to see if it works first.
    private DataTable GetDataTable(SqlConnection conn1)
    SqlDataAdapter daS1 = new SqlDataAdapter();
    daS1.SelectCommand = new SqlCommand();
    daS1.SelectCommand.Connection = conn1;
    if (conn1.State == ConnectionState.Closed) conn1.Open();
    daS1.SelectCommand.CommandType = CommandType.StoredProcedure;
    daS1.SelectCommand.CommandText = "yourStoredProcedureName";
    daS1.SelectCommand.Parameters.Add("@ParamName", SqlDbType.Int, 4);
    DataSet DS1 = new DataSet();
    daS1.Fill(DS1, "tbl1");
    return DS1.Tables["tbl1"];
    Note:  in the CommandText part place the name of your stored procedure.  In the Parameter part put the name of your parameter exactly as it is in the actual stored procedure.  Also, (if you have not done this already) make sure your stored
    procedure runs OK -- first -- test out your stored procedure in Sql Server Management Studio.  If the procedure runs OK in SSMS, then try it from you app.  Just create a simple form with one button .  Place GetDataTable() code under
    the button and call it something like this:
    private void button1_Click(object sender, EventArgs e)
    int i = GetDataTbl().Rows.Count;
    Console.WriteLine("i is {0}", i);
    Rich P

  • Getting the OUT of a MySQL stored procedure

    I'm using MySQL database to log results of execution in TestStand. Stored procedures are used for all results logging. The very first procedure logs the general execution specific information and returns an auto-incremented index for ExecutionID, that index is used by other procedures during the execution as an unique execution identifier. I had some troubles initially with getting this index into TestStand, but after upgrading to ODBC 5.3 driver it was resolved and I got the out parameter from my procedure and put it into propagated local in TestStand.
    Now the mistery. If executed once, everithing works fine, for the UUT Loop execution MySQL does not accept the same variable name again.
    The error I'm getting is:
    An error occurred calling 'LogMultipleResults' in 'ITSDBLog' of 'zNI TestStand Database Logging'
    An error occurred executing a statement.
    Statement: Insert_Execution.
    Description: [MySQL][ODBC 5.3(a) Driver][mysqld-5.6.16-enterprise-commercial-advanced-log]OUT or INOUT argument 14 for routine Results_Database.Insert_Execution is not a variable or NEW pseudo-variable in BEFORE trigger
    Number: -2147467259
    NativeError: 1414
    SQLState: S1000
    Reported by: Microsoft OLE DB Provider for ODBC Drivers
    Source: TSDBLog
     MySQL return such kind of error if you, say, provide a constant as an output parameter instead of a valid variable name. So, it does not want to use a "stale" variable which was already used once during the execution. I do not see such things when MySQL procedures with OUT parameters are used by other MySQL procedures, so I suppose this is something between MySQL and TestStand. I've tried to use an array to store my execution ids for different loops and to use a new element for each loop, but I get the same error. Any ideas?
    Sergey Kolbunov
    CLA, CTD

    Hi Sergey,
    What version of TestStand are you using? It may also be useful to include any portions of your application if possible
    I'm at a loss as to why you would be seeing this behavior. I doubt this will tell you anything helpful, but I threw in a couple of links to check out on the off chance you've configured something incorrectly:
    Preparing to Implement Database Logging:
    http://zone.ni.com/reference/en-XX/help/370052M-01/tsfundamentals/infotopics/database_logging/
    Database Known Issues:
    http://zone.ni.com/reference/en-XX/help/370052M-01/tsfundamentals/infotopics/database_known_issues/
    Adding TestStand Results to a MySQL Database (this one's pretty dated):
    http://www.ni.com/tutorial/3604/en/
    Throw out any contextual information that might help give away where/why the error is occuring.
    Neil
    Applications Engineering
    National Instruments
    www.ni.com/support

Maybe you are looking for