Exec a procedure with a sequence?

Here is my code. And the error I get when trying to insert into a table using a sequence can't figure out what im doing wrong?
create or replace procedure basket_add_sp
(p_baskid IN number, p_prodid IN number,
p_price IN number, p_qua IN number,
p_sizecode IN number, p_formcode IN number)
IS
BEGIN
INSERT into bb_basketitem (idbasketitem,idproduct, price, quantity, idbasket, option1, option2)
VALUES (bb_idbasketitem_seq.nextval ,p_prodid, p_price, p_qua, p_baskid, p_sizecode, p_formcode);
END;
ERROR:
SQL> exec basket_add_sp(bb_idbasketitem_seq.nextval, 8, 10.80, 1, 15, 2, 4);
BEGIN basket_add_sp(bb_idbasketitem_seq.nextval, 8, 10.80, 1, 15, 2, 4); END;
ERROR at line 1:
ORA-06550: line 1, column 41:
PLS-00357: Table,View Or Sequence reference 'BB_IDBASKETITEM_SEQ.NEXTVAL' not allowed in this context
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

> you are correct justin. So when I do an exec it bombs
out. Maybe im calling it wrong? I tried with the (8,
10.80, 1, 15, 2, 4) and it does not work. If I put in
the actual sequence name it does not work. So what is
the right way to call the proc?
A comment. The PL/SQL engine is not the SQL engine. The PL/SQL language is a formal procedural language - it is not SQL. SQL is a totally different language than PL/SQL.
So why then the SQL part in the language name PL/SQL? That is because SQL is tightly integrated within the PL/SQL. This allows you to mix PL and SQL as if it these were a single language. But they are not.
Calling a sequence must be done from within the SQL engine. The PL/SQL engine cannot call a sequence. Just as the PL/SQL engine cannot execute a SELECT statement - it needs the SQL engine to do that. And when you code a SELECT in PL/SQL, that is passed to the SQL engine to execute.
However, when you directly refer to a sequence in PL/SQL, it does not know how to access the object. That sequence object resides in the database part of Oracle and requires the SQL engine to access it.
Thus:
declare
  i integer;
begin
  i := sequence.NextVal;  -- invalid as PL/SQL cannot directly reference the sequence
  select sequence.NextVal into i from dual; -- valid as SQL is used to reference the sequence
  insert into foo_tab values(
     sequence.NextVal,
     .. rest of the values
  );                      -- valid as SQL is used
end;

Similar Messages

  • Running SQL Procedure with dg4msql errors: Function sequence error HY010

    I am trying to execute a stored procedure on a SQL database and get the error Function sequence error HY010.
    A simple query on a table returns teh expected result.
    I have a single Win2008R2 server with MSSQL Express 2008 and Oracle 11gR2 (32bit not 64bit version of Oracle)
    Below is the gateway init, listener and tnsnames files and the query I am trying to run:
    -- initORIONWASP.ora --
    HS_FDS_CONNECT_INFO=INGRDB//waspForGIS
    HS_FDS_TRACE_LEVEL=OFF
    HS_FDS_RECOVERY_ACCOUNT=RECOVER
    HS_FDS_RECOVERY_PWD=RECOVER
    HS_CALL_NAME=dbo.spTest;dbo.spQueryAsset;dbo.spQueryAssetDetails
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    -- Listener.ora -- (partial)
    (SID_DESC =
    (SID_NAME = ORIONWASP)
    (ORACLE_HOME = C:\Oracle\product\11.2.0\dbhome_1)
    (PROGRAM=dg4msql)
    -- tnsnames.ora -- (partial)
    ORIONWASP =
    (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=INGRDB)(PORT=1521))
    (CONNECT_DATA=(SID=ORIONWASP))
    (HS=OK)
    -- Simple Query --
    Running select "Asset_ID" from asset@ORIONWASP; returns the correct result
    Running select * from sys.procedures@ORIONWASP; returns a list of procedures including the procedure I want to run
    -- This pl/sql block returns the error ******* identifier 'spTest@ORIONWASP' must be declared *******
    declare
    begin
    "spTest"@ORIONWASP;
    end;
    -- This passthrough pl/sql block returns ******** [Oracle][ODBC SQL Server Driver]Function sequence error {HY010} ********
    DECLARE
    CRS BINARY_INTEGER;
    RET BINARY_INTEGER;
    v_COL1 VARCHAR2(50);
    v_COL2 VARCHAR2(50);
    BEGIN
    CRS := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@ORIONWASP;
    DBMS_HS_PASSTHROUGH.PARSE@ORIONWASP(CRS, 'exec spTest');
    BEGIN
    RET := 0;
    WHILE (TRUE)
    LOOP
    ret := DBMS_HS_PASSTHROUGH.FETCH_ROW@ORIONWASP(CRS, FALSE);
    DBMS_HS_PASSTHROUGH.GET_VALUE@ORIONWASP(CRS, 1, v_COL1);
    DBMS_HS_PASSTHROUGH.GET_VALUE@ORIONWASP(CRS, 2, v_COL2);
    DBMS_OUTPUT.PUT_Line('Col1:'||v_COL1||' Col2:'||v_COL2);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    BEGIN
    DBMS_OUTPUT.PUT_LINE('End of Fetch');
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@ORIONWASP(CRS);
    END;
    END;
    END;
    /

    The gateway configuration file contains:
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    This setting commonly causes problems and you need to set
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=FALSE
    for normal procedure calls and
    HS_FDS_PROC_IS_FUNC=FALSE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    when calling the procedure with ref cursors.
    There's a note in My Oracle Support that gives you examples how to call remote SQl Server procedures
         Note.197192.1 Different Methods How To Call MS SQL Server Procedures Using TG4MSQL - DG4MSQL
    and another one for the Sybase gateway but this code is similar for the SQL Server:
    Article-ID: Note 351400.1
    Title: How to Call a Remote Sybase Procedure Using TG4SYBS

  • In SQLScript, how to use EXEC to call another procedure with parameters in procedure?

    Hi experts,
    In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very much

    Hi Sagar,
    thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
    create procedure ftest1(out sum_num bigint)
    as
    begin
    declare fa_output bigint;
    declare v_sql_drop varchar(200);
    declare v_sql varchar(500);
    declare cursor c_cursor1 for select num from TABLE1;
    --v_sql_drop := 'drop procedure fe';
    --exec v_sql_drop;
    v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
    v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
    v_sql := :v_sql || ' end';
    exec v_sql;
    open c_cursor1;
    for c_item as c_cursor1 do
    exec 'call fe(c_item.num,o_num=>fa_output)';
    if sum_num is null then
    sum_num := fa_output;
    else
    sum_num := :sum_num + fa_output;
    end if;
    end for;
    close c_cursor1;
    end;
    The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again!

  • Exec a stock procedure with sqlplus is very long

    Hi,
    I have a procedure named : maj_societe();
    when i wall it from sqldeveloper it takes 0,007 second to execute
    But when i call it from a msdos prompt through sqlplus (windows xp) nothings happen (i have to end the procedure with ctrl C)
    i call it like that :
    sqlplus toto/titi@EXTERNE
    exec maj_societe();The procedure :
    create or replace PROCEDURE maj_societe
    AS
    BEGIN
         MERGE INTO DM3_SOCIETE D
         USING
         (          SELECT      distinct  SOCIETE_ID,
                                         RAISON,
                                         SIGLE,
                                         AD1,
                                         AD2,
                                         AD3,
                                         CP,
                                         VILLE,
                                         TEL,
                                         FAX,
                                         EFF_ETS,
                                         EFF_FR,
                                         EFF_INFO,
                                         EFF_BE,
                                         EFF_PRO,
                                         NAF,
                                         TYPE,
                                         SIRET,
                                         APP,
                                         GRP,
                                         DELOC,
                                         CA,
                                         WEB,
                                         ANN,
                                         PC,
                                         NB_S_MICRO,
                                         PORT,
                                         SERV_TOT,
                                         POS_TOT,
                                         FICHE
                   FROM DM3_COMME_BACK_TMP
              ) T
                   ON      (D.societe_id = T.societe_id)
         WHEN MATCHED THEN
              UPDATE SET
              D.RAISON = T.RAISON,
              D.SIGLE = T.SIGLE,
              D.AD1 = T.AD1,
              D.AD2 = T.AD2,
              D.AD3 = T.AD3,
              D.CP = T.CP,
              D.VILLE = T.VILLE,
              D.TEL = T.TEL,
              D.FAX = T.FAX,
              D.EFF_ETS = T.EFF_ETS,
              D.EFF_FR = T.EFF_FR,
              D.EFF_INFO = T.EFF_INFO,
              D.EFF_BE = T.EFF_BE,
              D.EFF_PRO = T.EFF_PRO,
              D.NAF = T.NAF,
              D.ID_TYPE_ENT = decode(upper(T.TYPE),'SIEGE',0,'ETABLISSEMENT',2,'USINE',1,0),
              D.SIRET = T.SIRET,
              D.APP = T.APP,
              D.GRP = T.GRP,
              D.DELOC = T.DELOC,
              D.CA = TO_NUMBER(T.CA,'999999.99'),
              D.WEB = T.WEB,
              D.ANN = T.ANN,
              D.PC = T.PC,
              D.NB_S_MICRO = T.NB_S_MICRO,
              D.PORT = T.PORT,
              D.SERV_TOT = T.SERV_TOT,
              D.POS_TOT = T.POS_TOT,
              D.FICHE = T.FICHE,
                    D.DATE_MAJ = sysdate()
         WHEN NOT MATCHED THEN
              INSERT (
                        D.SOCIETE_ID,
                        D.RAISON,
                        D.SIGLE,
                        D.AD1,
                        D.AD2,
                        D.AD3,
                        D.CP,
                        D.VILLE,
                        D.TEL,
                        D.FAX,
                        D.EFF_ETS,
                        D.EFF_FR,
                        D.EFF_INFO,
                        D.EFF_BE,
                        D.EFF_PRO,
                        D.NAF,
                        D.ID_TYPE_ENT,
                        D.SIRET,
                        D.APP,
                        D.GRP,
                        D.DELOC,
                        D.CA,
                        D.WEB,
                        D.ANN,
                        D.PC,
                        D.NB_S_MICRO,
                        D.PORT,
                        D.SERV_TOT,
                        D.POS_TOT,
                        D.FICHE,
                                    D.DATE_MAJ
              VALUES (
                        T.SOCIETE_ID,
                        T.RAISON,
                        T.SIGLE,
                        T.AD1,
                        T.AD2,
                        T.AD3,
                        T.CP,
                        T.VILLE,
                        T.TEL,
                        T.FAX,
                        T.EFF_ETS,
                        T.EFF_FR,
                        T.EFF_INFO,
                        T.EFF_BE,
                        T.EFF_PRO,
                        T.NAF,
                        decode(upper(T.TYPE),'SIEGE',0,'ETABLISSEMENT',2,'USINE',1,0),
                        T.SIRET,
                        T.APP,
                        T.GRP,
                        T.DELOC,
                        TO_NUMBER(T.CA,'999999.99'),
                        T.WEB,
                        T.ANN,
                        T.PC,
                        T.NB_S_MICRO,
                        T.PORT,
                        T.SERV_TOT,
                        T.POS_TOT,
                        T.FICHE,
                                    sysdate()
    END;Thx

    Not sure why you have this difference between SQL*PLUS and Oracle SQL Developer. Maybe your NLS Settings are different and some implizit conversion is giving truoble. But I didn't find any hint for this in the statement.
    Did you commit/rollback inside the Oracle SQL Developer? Maybe one session is locking the updateed rows and your second merge in the other session can't finish because of that.
    Some sidenotes:
    - Consider to remove the distinct from the matching select.
    - sysdate() can be written as sysdate
    without the parenthesis

  • T-sql 2008 r2 place results from calling a stored procedure with parameters into a temp table

    I would like to know if the following sql can be used to obtain specific columns from calling a stored procedure with parameters:
    /* Create TempTable */
    CREATE TABLE #tempTable
    (MyDate SMALLDATETIME,
    IntValue INT)
    GO
    /* Run SP and Insert Value in TempTable */
    INSERT INTO #tempTable
    (MyDate,
    IntValue)
    EXEC TestSP @parm1, @parm2
    If the above does not work or there is a better way to accomplish this goal, please let me know how to change the sql?

    declare @result varchar(100), @dSQL nvarchar(MAX)
    set @dSQL = 'exec @res = TestSP '''+@parm1+''','' '''+@parm2+' '' '
    print @dSQL
      EXECUTE sp_executesql @dSQL, N'@res varchar(100) OUTPUT', @res = @result OUTPUT
    select @result
    A complicated way of saying
    EXEC @ret = TestSP @parm1, @parm2
    SELECT @ret
    And not only compliacated, it introduces a window for SQL injection.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Calling a package procedure with Date parameter only

    Hi All,
    Please help me to call a package procedure with Date parameter from sql prompt.
    Arif

    Check the below procedure.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure procdate (p_date_in date)
      2  is
      3  p_date_out date;
      4  begin
      5  p_date_out := add_months(p_date_in,6);
      6  dbms_output.put_line(p_date_out);
      7* end;
    SQL> /
    Procedure created.
    SQL> exec procdate('01-JAN-2010');
    01-JUL-10
    PL/SQL procedure successfully completed.
    SQL> exec procdate(to_date('01/01/2010','DD-MM-YYYY'));
    01-JUL-10
    PL/SQL procedure successfully completed.
    SQL> exec procdate('31-DEC-2010');
    30-JUN-11
    PL/SQL procedure successfully completed.

  • Calling Stored procedure with Parameters in PowerPivot DataModel

    Hi All,
    I wanted to call a SQL stored procedure from PowerPivot(Excel) on based on changing slicer's value. 
    Currently, we can call stored procedure wihtout any parameter from Data Model tab using 
    Exec stored_proc_name in Table Properties window.
    What if I want to call the same procedure with a parameter whouse value will come by changing slicer's value. I  meant, changing slicer value will act as a parameter to that stored procedure & it should return updated results. 
    Is this possible in PowerPivot?

    Hi Rameshwar,
    According to your description, you call a SQL Server stored procedure in PowerPivot data model, now the problem is that you need to pass a parameter to the stored procedure, right?
    Based on my research, it seems that we cannot achieve this requirement directly in current version of PowerPivot data model. Here is a similar thread for you reference.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5350228d-bc62-4a3b-a1a6-e847483e2858/powerpivot-for-excel-2013-call-execute-stored-procedure-with-parameters?forum=sqlkjpowerpivotforexcel
    If you have any concern about this behavior, you can submit a feedback at
    http://connect.microsoft.com/SQLServer/Feedback and hope it is resolved in the next release of service pack or product. Your feedback enables Microsoft to make software and services the best that they can be, Microsoft might consider to add this feature
    in the following release after official confirmation.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Procedure with in procedure

    Hi,
    i need to call a procedure with in another procedure and pass the main procedure values. when i am doing like this i am getting the error.
    Can any one tell me where the error is:
    the main procedure is xxxx( P_PHONE IN VARCHAR2,
    P_CLIENT IN VARCHAR2,
    P_MANAGER IN VARCHAR2,
    P_ACCOUNTANT IN VARCHAR2
    as
    x:=P_PHONE;
    y:= P_CLIENT;
    z:= P_MANAGER;
    n:= P_ACCOUNTANT;
    exec tlm_ar_string_to_table(x,y,z,n);
    end;
    my inner procedure is
    create or replace procedure tlm_ar_string_to_table(
    P_PHONE IN VARCHAR2,
    P_CLIENT IN VARCHAR2,
    P_MANAGER IN VARCHAR2,
    P_ACCOUNTANT IN VARCHAR2
    as
    p_string_c varchar2(500);
    P_PROCESSING_GROUP_C varchar2(10);
    P_client_C varchar2(10);
    P_manager_C varchar2(10);
    P_accountant_C varchar2(10);
    p_search_result_c varchar2(10);
    CURSOR psg_CURSOR IS
    SELECT distinct phone FROM SSRFUND.bank where phone>' ' ;
    cursor string_ex_cur is
    select substr( p_string_c
    , decode( level, 1, 1, instr(p_string_c,',',1,level-1)+1)
    , decode( instr(p_string_c,',',1,level), 0, length(p_string_c),
    instr(p_string_c,',',1,level) - decode( level, 1, 0, instr(p_string_c,',',1,level-1))-1)
    ) the_value
    from ( select p_string_c
    from dual)
    connect by level <= length(p_string_c)-length(replace(p_string_c,','))+1;
    cursor mgr_cursor is
    select distinct fax from ssrfund.bank;
    cursor client_cursor is
    select distinct swift_address from ssrfund.bank;
    cursor accountant_cursor is
    select distinct telex from ssrfund.bank;
    begin
    execute immediate 'Truncate table temp_processing_group';
    execute immediate 'Truncate table temp_accountant';
    execute immediate 'Truncate table temp_client';
    execute immediate 'Truncate table temp_manager';
    if (P_PHONE is null) then
    open psg_cursor;
    loop
    FETCH psg_cursor INTO P_PROCESSING_GROUP_C;
    EXIT WHEN (psg_cursor%NOTFOUND);
    insert into temp_PROCESSING_GROUP values(P_PROCESSING_GROUP_C);
    commit;
    end loop;
    close psg_cursor;
    else
    p_search_result_c:=instr(p_phone,',');
    if (p_search_result_c='TRUE') then
    p_string_c:=p_phone;
    open string_ex_cur;
    loop
    fetch string_ex_cur into P_PROCESSING_GROUP_C;
    insert into temp_PROCESSING_GROUP values(P_PROCESSING_GROUP_C);
    commit;
    end loop;
    close string_ex_cur;
    else
    insert into temp_PROCESSING_GROUP values(P_PROCESSING_GROUP_C);
    commit;
    end if;
    end if;
    if (P_client is null) then
    open client_cursor;
    loop
    FETCH client_CURSOR INTO P_client_C;
    EXIT WHEN (client_CURSOR%NOTFOUND);
    insert into temp_client values(P_client_C);
    commit;
    end loop;
    close client_cursor;
    else
    p_search_result_c:=instr(p_client,',');
    if (p_search_result_c='TRUE') then
    p_string_c:=p_client;
    open string_ex_cur;
    loop
    fetch string_ex_cur into P_client_C;
    insert into temp_client values(P_client_C);
    commit;
    end loop;
    close string_ex_cur;
    else
    insert into temp_client values(P_client_C);
    commit;
    end if;
    end if;
    if (P_manager is null) then
    open mgr_cursor;
    loop
    FETCH mgr_CURSOR INTO P_manager_C;
    EXIT WHEN (mgr_CURSOR%NOTFOUND);
    insert into temp_manager values(P_manger_C);
    commit;
    end loop;
    close mgr_cursor;
    else
    p_search_result_c:=instr(P_manager,',');
    if (p_search_result_c='TRUE') then
    p_string_c:=p_manager;
    open string_ex_cur;
    loop
    fetch string_ex_cur into P_manager_C;
    insert into temp_manager values(P_manager_C);
    commit;
    end loop;
    close string_ex_cur;
    else
    insert into temp_manager values(P_manager_C);
    commit;
    end if;
    end if;
    if (P_accountant is null) then
    open accountant_cursor;
    loop
    FETCH accountant_cursor INTO P_accountant_C;
    EXIT WHEN (accountant_cursor%NOTFOUND);
    insert into temp_accountant values(P_accountant_C);
    commit;
    end loop;
    close accountant_cursor;
    else
    p_search_result_c:=instr(P_accountant,',');
    if (p_search_result_c='TRUE') then
    p_string_c:=p_accountant;
    open string_ex_cur;
    loop
    fetch string_ex_cur into P_accountant_C;
    insert into temp_accountant values(P_accountant_C);
    commit;
    end loop;
    close string_ex_cur;
    else
    insert into temp_accountant values(P_accountant_C);
    commit;
    end if;
    end if;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR (-20001, SQLERRM);
    end;
    /

    user12852882 wrote:
    i need to call a procedure with in another procedure and pass the main procedure values. when i am doing like this i am getting the error.Ugly code. There's seldom the need to use PL logic when the source and destination data both resides in Oracle tables. SQL should be used.
    Also, why the the "+temp+" tables? I/O is single most expensive thing you can on a database platform. Why would one then want to create more I/O by creating temp tables? This approach may be needed in SQL-Server for example, but in Oracle it is usually just plain and horribly wrong.
    I suggest that you scrap this code, forget about coding procedures-in-procedures (use packages instead), forget about trying to process row-by-row in a slow-by-slow fashion in the PL language.
    SQL is not a mere I/O language to be used for reading and writing data (for PL code to process the row). SQL is a data processing language. Extremely capable. Extremely powerful. And can process Oracle data faster than any other language, including using the PL language component in the server.
    The basic rule for effective and scalable Oracle code is Maximize SQL. Minimize PL/Java/etc.
    Use the SQL language for its intended purpose and do not process rows needlessly in another language layer.

  • Stored procedure with cursor as output param

    It's the first time for me to test a stored procedure with a cursor as output parameter. I executed the following:
    SQL> VARIABLE user_cur REFCURSOR; VARIABLE ret_code VARCHAR2; exec TEST_API.SEARCH_USER( :ret_code, '', '', 'john', '', :user_cur); print ret_code;print user_cur;
    I got the following error:
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
    VARCHAR2 (n CHAR) | NCHAR | NCHAR (n) |
    NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR ] ]
    May I know what's the problem?
    The purpose of the stored procedure is to search for user with the name "john".
    The stored procudure input/output params declaration is as follows:
    PROCEDURE SEARCH_USER
    RETURN_CODE OUT VARCHAR2,
    USER_ID_IN IN VARCHAR2,
    POSITION_IN IN VARCHAR2,
    USERNAME_IN IN VARCHAR2,
    STATUS_IN IN VARCHAR2,
    USER_CUR_OUT OUT REFCURSOR
    Edited by: user7383310 on Oct 19, 2008 9:05 PM
    Edited by: user7383310 on Oct 19, 2008 9:05 PM

    for the usage of refcursors in pl/sql refer here..
    http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10807/06_ora.htm#sthref808
    You can code like..
    SQL> create or replace procedure p1(id number,csr out sys_refcursor) is
      2  begin
      3   open csr for select ename from emp where deptno = id;
      4  end;
      5  /
    Procedure created.
    SQL> var csr1 refcursor
    SQL> var n number
    SQL> exec :n := 30;
    PL/SQL procedure successfully completed.
    SQL> exec p1(:n,:csr1);
    PL/SQL procedure successfully completed.
    SQL> print csr1
    ENAME
    ALLEN
    WARD
    MARTIN
    BLAKE
    TURNER
    JAMES
    6 rows selected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Calling Oracle procedure with two OUT parameters

    Hi I am having an Oracle procedure which return ref cursor. I also want to result one more out parameter result. How Can I call the procedure in SQL. Below is the way I am calling my stored procedure with one parameter.
    proc_Test (p_resultset=> My_cursor)
    How can I call the procedure when I have one more OUT parameter. Second parameter returns 0 or 1.
    Thanks in adv

    Yes its possible to use multiple parameter as OUT type in procedure.
    SQL>set serveroutput on size 1000000;
    SQL>CREATE OR REPLACE PROCEDURE myproc(p_cv OUT SYS_REFCURSOR, p_num OUT NUMBER) AS
      2  BEGIN
      3    OPEN p_cv FOR SELECT 'Hello Oracle' sayhello FROM DUAL ;
      4    p_num := 1;
      5  END;
      6  /
    Procedure created.
    SQL>VAR cv REFCURSOR;
    SQL>VAR num NUMBER;
    SQL>EXEC myproc(:cv, :num);
    PL/SQL procedure successfully completed.
    SQL>PRINT cv;
    SAYHELLO
    Hello Oracle
    SQL>PRINT num;
           NUM
             1
    SQL>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Execute a procedure with a list of array in sql server 2008

    HI all,
    I have a procedure which has a list of values passed as an array . How can i execute my procedure with array list? how to implement this?Please help me.
    Thanks in advance
    Deepa

    Hi Deepa,
    basically Microsoft SQL Server does not support arrays as data types for procedures. What you can do is creating a type which represents a table definition. This type can than be used in a procedure as the following demo will show:
    The first script creates the environment which will be used for the execution
    -- 1. create the table as a type in the database
    CREATE TYPE OrderItems AS TABLE
    ItemId int PRIMARY KEY CLUSTERED
    GO
    -- 2. demo table for demonstration of results
    CREATE TABLE dbo.CustomerOrders
    Id int NOT NULL IDENTITY (1, 1) PRIMARY KEY CLUSTERED,
    CustomerId int NOT NULL,
    ItemId int
    GO
    -- 3. Insert a few records in demo table
    INSERT INTO dbo.CustomerOrders
    (CustomerId, ItemId)
    VALUES
    (1, 1),
    (2, 1),
    (3, 3),
    (1, 3);
    GO
    -- 4. Create the procedure which accepts the table variable
    CREATE PROC dbo.OrderedItemsList
    @Orders AS OrderItems READONLY
    AS
    SET NOCOUNT ON;
    SELECT o.*
    FROM dbo.CustomerOrders AS O INNER JOIN @Orders AS T_O
    ON (o.ItemId = T_O.ItemId);
    SET NOCOUNT OFF;
    GO
    The above script creates the table data type and a demo table with a few demo data. The procedure will accept the table data type as parameter. Keep in mind that table variable parameters have to be READONLY as parameter for procedures!
    The second script demonstrates the usage of the above scenario
    When the environment has been created the usage is a very simple one as you can see from the next script...
    -- 1. Fill the variable table with item ids
    DECLARE @o AS OrderItems;
    INSERT INTO @o (ItemId)
    VALUES
    (1), (3);
    -- 2. Get the list of customers who bought these items
    EXEC dbo.OrderedItemsList @Orders = @o;
    MCM - SQL Server 2008
    MCSE - SQL Server 2012
    db Berater GmbH
    SQL Server Blog (german only)

  • How to call a AS/400 Stored Procedure with a BigDecimal Value?

    Hi,
    Could you pls tell me how to call a stored procedure on the AS/400 which request an input value of packed decimal(10P 4) value.
    I have tried to convert it to a BigDecimal in Java and call the stored procedure as follows but it gave me a decimal point error on the AS/400.
    Could you pls show me where I'm wrong in the following code.
    Thanks
    Jan
    ========Java program to call AS/400 Stored procedure with setBigDecimal()===========
    //Assign the value to String
    string sBDVal = "30"
    //Convert the String value to BigDecimal
    BigDecimal bdAmt = new BigDecimal(sBDVal);
    //Call Stored Procedure with parameters,
    CallableStatement callSP = conn.prepareCall("{call OSCUPDLENS(?,?,?)}");
    // Set in parm values
    callSP.setString(1,"Value 1");
    callSP.setBigDecimal(2,bdAmt);
    callSP.setString(3,"");
    // Register out parameter
    callSP.registerOutParameter(3, Types.CHAR);
    // Execute call to stored procedure
    callSP.execute();
    // Retrieve out parameters
    sErrFlag = callSP.getString(3).trim();
    ========================Create Stored Procedure on AS/400===========================
    c/EXEC SQL
    c+ CREATE PROCEDURE TESTSPROC
    c+ (IN VAL1 CHAR ( 8),
    c+ IN BDAMT DEC (10, 4),
    C+ INOUT ERR CHAR ( 1))
    C+ LANGUAGE RPGLE NOT
    C+ DETERMINISTIC NO SQL EXTERNAL NAME TESTSPROC PARAMETER STYLE
    C+ GENERAL
    c/END-EXEC
    ======RPG program on AS/400 to accept the BigDecimal value to a Packed decimal======
    * Initialize the i/p parameter
    DP#VAL1 S 8A
    DP#AMT S 10P 4
    DP#ERR S 1A
    C*Input parameters
    C *ENTRY        PLIST                          
    C PARM P#VAL1
    C PARM P#AMT
    C PARM P#ERR

    Could you pls show me where I'm wrong in the following codeI don't know, you're doing a lot of things I have never tried. But "decimal data error" most likely means that the stored procedure is expecting packed data and the driver is giving it zoned data, or vice versa. You could confirm that by dumping your variables inside your RPG. If that is your problem, you could work around it by redefining your BDAMT parameter as integer or string and reformatting it in the RPG.

  • How to call a Store Procedure with IN PARAMETER

    Hi, im new using Oracle 10G with Oracle SQL Developer, my cuestion is how to call a Store Procedure with IN PARAMETER, I tried the following without results
    SELECT * FROM procedure_name(parameter);
    PROCEDURE procedure_name(parameter);
    EXEC procedure_name(parameter);
    CALL procedure_name(parameter);
    Please help me....

    Hi,
    As Beijing said,
    EXEC procedure_name(parameter);
    CALL procedure_name(parameter);work for me.
    So does
    BEGIN
        procedure_name(parameter);
    END;Can you be more specific about what you're doing? That is, are you testing it in SQL Developer? Where are you entering the commands? Where are you looking for output? Do you get error messages? Does anything else (like "SELECT SYSDATE FROM dual;") work?

  • Database procedure with IN/OUT parameters

    Hi,
    I have a procedure with multiple OUT parameters,
    but I do not know how to get the values of these out parameters in the calling procedure.
    What I mean is I can simply get the value of a function from a calling procedure as:-
    declare
    val1 number;
    begin
    val1 := func_get_num;
    end;
    How can I get the values of OUT parameters of a procedure in a similar way?

    like
    SQL> var ename_v varchar2(30);
    SQL> var empno_v number;
    SQL> create or replace procedure get_employee(empno out number, ename out varchar)
      2  as
      3  begin
      4     select empno, ename into empno, ename from emp where rownum <=1;
      5  end;
      6  /
    Procedure created.
    Elapsed: 00:00:00.51
    SQL> exec get_employee(:empno_v, :ename_v);
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.12
    SQL> print empno_v
       EMPNO_V
           666
    SQL> print ename_v;
    ENAME_V
    fdddfdf1
    SQL>

  • Procedure with in the procedure

    Hi,
    It is possible or not to write a procedure with in the procedure...?
    If it's Yes How?
    If it's No why?

    basha wrote:
    Hi,
    It is possible or not to write a procedure with in the procedure...?
    If it's Yes How?
    If it's No why?Sure, but it's a rather uncommon requirement.
    create or replace procedure proc1
    as
      procedure proc2
      is
      begin
        dbms_output.put_line('nested proc');
      end;
    begin
      proc2;
    end;
    exec proc1;Also, i've used a stand alone procedure to demonstrate, in real life you'd almost always want to use packages.

Maybe you are looking for