Need to add a check in between the stored procedure

Hi Team, I am new to pl/sql and need to add a check in between the below procedure such that, Only if the Insert is successfull the delete should execute, if not the loop should be ended.
Please help me.
CREATE OR REPLACE PROCEDURE Archive_psuser_grants AS
i NUMBER:=1;
CURSOR c IS SELECT * FROM ps_user_grants1 WHERE DATABASE = 'F90PRD';
BEGIN
FOR records IN c loop
INSERT INTO ps_user_grants_archive VALUES (records.DATABASE,records.username,records.level_type,records.privilege,records.grantable,records.owner,records.table_name,records.column_name,records.sr_number,records.initially_granted);
i := i+1;
IF mod(i, 1000) = 0 THEN -- Commit every 1000 records
dbms_output.put_line ( '1K records applied into archive table ');
COMMIT;
end if;
end loop;
COMMIT;
dbms_output.put_line ( 'Rows successfully Inserted into Archive Table ');
delete FROM ps_user_grants WHERE DATABASE = 'F90PRD';
COMMIT;
dbms_output.put_line ( 'Rows successfully Deleted from Original Table ');
END Archive_psuser_grants;
Thanks in advance,
Sri
Edited by: user3969470 on Feb 9, 2011 8:50 PM

ROW by ROW, is SLOW by SLOW.
COMMIT inside LOOP is a GREAT mechanism for producing ORA-01555; SNAPSHOT TOO OLD, error
You need to implement EXCEPTION handler(s)
What should be done where DELETE fails?

Similar Messages

  • Add a check box on the Contract Account Screen (CAA2)

    Hello All,
    Requirement:
    Need to add a custom checkbox on the Contract Account Screen (CAA2) only for contract accounts with cont acct category as '02'. And in addtion ot that I need to add a custom field in the table FKKVKP.
    Any kind of help will be highly appreciated and rewarded.
    Thanks and regards,
    Rakesh

    Hi Rakesh.
    I dont know whether you tried this or not (please excuse if you already tried it),
    From System > status .
    you will get the prog name and screen no.
    go to se51 and enter those details and find pbo and  pai modules.
    2).
    In PAI module insert your checkbox field name in the code already written for the screen values to be saved.(save code).To find out where the save code is written,
    enter some data on the screen fields, and start debugging (/h and enter in com prompt) and press save button the cursor takes you to the save code.
    1).you need to handle it in pbo module.
    in pbo module
    collect the rec with 02 accounts in an internal table
    enable the check box for those records only.

  • How to find end of the Page in Crystal ? or I need to add one Horizontal line at the end of the page.--- URGENT HELP NEEDED

    Hi friends,
    I need to add one horizontal line  for the detail section at the end of the page.
    I tried to put that line in page footer and i tried with Box also. Both are not properly working. Some space problem is coming.
    Is there any feature to find end of the Page.
    I want report format like this.
    set id  |  set name |  date  Name
      1         x           dddd   vijay
                            dddd   sarathi
                            dddd    reddy
    (End of the page)
    Thanks in advance...
    vijay.

    Do you know how many detail records are showing up per page?
    If you do - you could create a Details B section that is suppressed except for on Record N (where N is a counter, and N is the last Detail record that will show up on a page).
    The Page footer is indeed built so that it will be rendered at the bottom of your physical page of paper.

  • I'm using apple's bluetooth keyboard and I need an easy way to switch between the text and numbers fields instead of tapping on the screen

    I'm using apple's bluetooth keyboard and I need an easy way to switch between the text and numbers fields instead of tapping on the screen

    While not in edit mode:
    - if start typing numbers, then it enters number mode.
    - if start typing text, then it enters text mode.
    Using the arrow keys exits edit mode. So this should work for you:
    1 Type text into a cell, which enters text mode.
    2 Press Return to move to the next cell.
    3 Press right arrow key to exit edit mode.
    4 Press left arrow key to get back to the cell.
    5 Type a number, which enters number mode.
    Another method that requires more planning ahead of time is to format the cells as text or number before starting the data entry. Then when you navigate to a cell while in edit mode, you will be in the appropriate mode (without having to exit edit mode).
    This all works fine for me. Hopefullly it does for you also.

  • Need to add a new release of the segment and maintain that version

    Hi All,
    I want to add one field in the Z segment type using WE31.But i am getting the error message as
    'Current segment definition <segment name> can no longer be changed and The current segment definition
    is already released.You can either add a new segment definition or cancel the release of the current segment definition'.
    The current segment defenition which i am trying to change got the SAP release of 4.6C. But the system has upgraded to Ecc6 recently.
    I tried going to the edit menu and cancel the release, but still it is not allowing.
    Whats the impact of the Add button(Add version) and creating a new version?.will it create a new version for ECC6?.
    I suggested by that
    *You can only edit segments in the current release. You will need to add a new release of the segment and maintain that version with changes. *
    If this is right then
    How to do this settings
    regards,

    'Add version' use this option - a new version will be created in the current release.
    then add your field to that and relase it again.
    Regds,

  • Need to add a new page in the SAP Script as last page

    Hello,
    I need to add a new page in the SAP Script as last page.
    Currently I have three pages in the form(FIRST,NEXT,LAST). For this I created one more page END.
    FIRST page next page is NEXT
    NEXT page next page is NEXT
    LAST page next page is LAST
    END page next page is END.
    I used NEW-PAGE END in the main window but it is not working and also I trired with CONTROL_FORM this also not working.
    Thanks,
    Ravi.

    Hello,
    I need to add a new page in the SAP Script as last page.
    Currently I have three pages in the form(FIRST,NEXT,LAST). For this I created one more page END.
    FIRST page next page is NEXT
    NEXT page next page is NEXT
    LAST page next page is LAST
    END page next page is END.
    Create the text element in the main wondow of your form
    /E           ENDPAGE
    /:           NEW-PAGE END
    and call the element from your print program by using write_form, where you want the END page in your print.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'ENDPAGE'
        EXCEPTIONS
          element = 1
          window  = 2.
    Thanks,
    Ravi.

  • To add a check box in the login screen

    Hi,
    I need to put a check box in the login screen of CRM below the LOGON button with a message :'I agree with the terms and condition of the System'.
    Please help.

    See: Improve PDFs: Create interactive PDF checklists

  • Need to add new Text Field on the Screen

    Hi,
    I am using Oracle 9 Designer and generating the web pages using web pl/sql language. After I generate the page, my screen looks like this:
    Employee id: TextField
    Employee Name: TextField
    I want to add a comment"(Please enter characters Only" below the Employee ID like the following:
    Employee id : TextField
    (Please enter characters Only)
    Employee Name: TextField
    Can anybody help me how to add this in the designer form?
    thanks in advance.

    You can do this with an unbound item on a View Form. You cannot do it at all for an Insert Form. There is a work around but takes a little explaining for the Insert Form. You need to create a web page from the insert form html, modify it manually. I do it as a simple procedure so it is consistent with the rest of the application. Then all menus, links, etc. need to reference that page instead of the FormInsert procedure in the generated package.
    There may be other work arounds. Without knowing more about your requirements, I can't say.
    John Caputo
    [email protected]

  • Need to add 2 new columns to the existing table control of C223 transaction

    Hi ABAP Gurus,
    I have to do a screen enhancement for transaction C223.
    Below is the requirement:
    need to add 2 new columns to the existing table control of C223 transaction.
    there is no customer exits, screen exit or user exit present for this transaction C223, i have found one enhancement spot for this transaction.
    i dont have any idea how to do this in standard transaction C223, the table control in C223 saves the data to MKAL table and the table control uses the structure MKAL_EXPAND in the screen program.
    i have created an append structure for  the 2 fields to the standard table MKAL.
    Can anyone please suggest me how this can be done in standard screen C223, will the enhancement spot can be used to do this....
    please sugest...
    Thanks & Regards

    Hi Santosh,
    Thanks for the reply. I have looked into this Enhancement Spot CPFX_SCREEN_SET , inside this there is only one method INPUT_DISABLED having below parameters
    IM_MKAL     Importing     Type     MKAL                                                                                Production Version
    EX_MSGID     Exporting     Type     SY-MSGID                                                                                Messages, Message
    EX_MSGTY     Exporting     Type     SY-MSGTY                                                                                Messages, Message
    EX_MSGNO     Exporting     Type     SY-MSGNO                                                                                Messages, Message
    EX_MSGV1     Exporting     Type     SY-MSGV1                                                                                Messages, Message
    EX_MSGV2     Exporting     Type     SY-MSGV2                                                                                Messages, Message
    EX_MSGV3     Exporting     Type     SY-MSGV3                                                                                Messages, Message
    EX_MSGV4     Exporting     Type     SY-MSGV4                                                                                Messages, Message
    EX_INPUT_DISABLE     Exporting     Type     CHAR1                                                                                Display Only if X Was Set
    the BADI definition present here is a SAP internal so we cant implement the BADI , but we can created a enhancement spot implementation for this. as per my understanding on this the enhancement spot is only for making the table control fields display / change .  i dont think this can be used to add two new coloumns to C223 table control.
    I am not sure thats why seeking your help/valuable sugestion on this.
    Please provide your sugestion on this , so that i can come to conclusion on this issue.
    Thanks & Regards
    Siddhartha Mishra

  • Customize the stored procedure migrating of MWB

    Hi, All,
    Is there anybody know how much customize we can have for using
    the MWB when migrate stored procedure? For sample I have a SQL
    Server 6.5 strored procedure like following:
    /******************* SQL Server 6.5 sp *************/
    CREATE PROCEDURE sp_SelectUsers
    AS
    select
    tbl_Sp_users.ID, UserName, Password, ExpiresOn,
    PwdChangedDate, tbl_Sp_UserGrps.name
    from
    tbl_Sp_users, tbl_Sp_UserGrps
    where
    GroupID = tbl_Sp_UserGrps.id
    order by username
    /******************* end ***************************/
    After I migrate it to Oracle 8 with MWB, I got following object,
    one Pkg and one Procedure in Oracle db, like following:
    /****************** Oracle Pkg **********************/
    CREATE OR REPLACE PROCEDURE sp_SelectUsers(
    RC1 IN OUT sp_SelectUsersPkg.RCT1)
    AS
    StoO_selcnt INTEGER;
    StoO_error INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
    StoO_sqlstatus INTEGER;
    BEGIN
    OPEN RC1 FOR
    SELECT tbl_Sp_users.ID, UserName, Password,
    ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
    tbl_Sp_users, tbl_Sp_UserGrps
    WHERE GroupID = tbl_Sp_UserGrps.id
    ORDER BY username ;
    END sp_SelectUsers;
    /******************* Oracle Procedure ****************/
    PROCEDURE sp_SelectUsers(
    RC1 IN OUT sp_SelectUsersPkg.RCT1)
    AS
    StoO_selcnt INTEGER;
    StoO_error INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
    StoO_sqlstatus INTEGER;
    BEGIN
    OPEN RC1 FOR
    SELECT tbl_Sp_users.ID, UserName, Password,
    ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
    tbl_Sp_users, tbl_Sp_UserGrps
    WHERE GroupID = tbl_Sp_UserGrps.id
    ORDER BY username ;
    END sp_SelectUsers;
    /******************* end *****************************/
    As our client use RDO as access method, there is no way we can
    use this migrated SP in RDO and return resultset. We need
    convert this SP to following to be able to use RDO to get
    resultset back in client:
    /******************* need convert to *********************/
    create or replace package sp_selectUsersPkg
    as
    cursor c1
    is select tbl_Sp_users.ID, UserName, Password,ExpiresOn,
    PwdChangedDate, tbl_Sp_UserGrps.name
    from tbl_Sp_users, tbl_Sp_UserGrps
    where GroupID = tbl_Sp_UserGrps.id
    order by username;
    type UsersCur
    is ref cursor return c1%ROWTYPE;
    procedure sp_selectUsers(UserCursor in out UsersCur );
    END;
    create or replace package body sp_selectUsersPkg
    as
    procedure sp_selectUsers(UserCursor in out UsersCur )
    is
    begin
    open UserCursor for
    select tbl_Sp_users.ID, UserName,
    password, ExpiresOn,
    PwdChangedDate, tbl_Sp_UserGrps.name
    from tbl_Sp_users, tbl_Sp_UserGrps
    where GroupID = tbl_Sp_UserGrps.id
    order by username;
    end;
    end;
    /******************* end *********************************/
    Is there any idea how we can do this? I hope we don't need do
    this manually.
    Thank you very much for any help!
    Jing
    null

    I have done a rough example of using VB6, RDO and ODBC
    drivers, which may be of help to some workbench users:
    Calling Oracle 8.1.5 stored procedures with ref cursors using RDO
    and Visual
    Basic.
    Ver 0.1 [email protected]
    Summary
    Versions Used
    Table
    Code
    With Explicit Ref Cursor Argument
    Without Explicit Ref Cursor Argument
    Actions
    Summary
    This gives a comparison of the connectivity between Visual Basic
    and Oracle,
    with both the intersolve and oracle drivers. The Oracle odbc
    still has
    significant
    shortcomings in comparison to the intersolve/Merant driver.
    Versions Used
    Visiual Basic 6.0, Oracle odbc driver 8.1.5.3.0, Oracle Database
    8.1.5.0.0 on
    NT, intersolve/Merant 3.5 32 bit Oracle driver.
    Table
    html table replaced by rough results in ascii form
    test case with named result set cursor variable:
    sSQL = "{CALL reftest.GetEmpData(?)}"
    oracle 8.1.5.3
    could not find item indicated by text, known vb6.0 bug?, thinks
    reftest is user
    intersolve
    could not find item indicated by text, known vb6.0 bug?, thinks
    reftest is user
    sSQL = "begin reftest.GetEmpData(?); end;"
    oracle 8.1.5.3
    run time error 40002 driver not capable
    intersolve
    ok
    sSQL = "{CALL GetEmpData(?)}"
    oracle 8.1.5.3
    run time error 40002 driver not capable
    intersolve
    could not find item indicated by text,?(similar to bug above?)
    at qd.rdoParameters(0).Type = rdTypeVARCHAR
    sSQL = "begin GetEmpData(?); end;"
    oracle 8.1.5.3
    run time error 40002 driver not capable
    intersolve
    ok
    procedure with result set last argument wanting to be simulated
    as not
    argument result set
    strsql = "{CALL BYROYALTYPkg.byroyalty()}"
    oracle 8.1.5.3
    ok
    intersolve
    ok
    strsql = "begin BYROYALTYPkg.byroyalty(); end;"
    oracle 8.1.5.3
    wrong number of arguments in byroyalty
    intersolve
    ok
    strsql = "{CALL byroyalty() }"
    oracle 8.1.5.3
    wrong number of arguments
    intersolve
    ok
    strsql = "begin byroyalty(); end;"
    oracle 8.1.5.3
    wrong number of arguments
    intersolve
    ok
    Code
    With Explicit Ref Cursor Argument
    Oracle Stored Procedures and Packages
    (on scott/tiger account)
    create or replace package reftest as
    cursor c1 is select ename from emp;
    type empCur is ref cursor return c1%ROWTYPE;
    procedure GetEmpData(EmpCursor in out empCur );
    END;
    create or replace package body reftest as
    procedure GetEmpData(EmpCursor in out empCur) is
    begin
    open EmpCursor for select ename from emp;
    end;
    end;
    create or replace procedure GetEmpData(EmpCursor in out
    reftest.empCur)
    is
    begin
    open EmpCursor for select ename from emp;
    end;
    VB code
    Private Sub Command1_Click()
    Dim cn As New rdoConnection
    Dim qd As rdoQuery
    Dim rs As rdoResultset
    Dim cl As rdoColumn
    Static Number As Integer
    Number = 0
    cn.Connect = "uid=scott; pwd=tiger; DSN=Oracle;"
    'enable the MS Cursor library
    cn.CursorDriver = rdUseOdbc
    'Make the connection
    cn.EstablishConnection rdDriverPrompt
    sSQL = "BEGIN GetEmpData(?); END;"
    Set qd = cn.CreateQuery("", sSQL)
    qd.rdoParameters(0).Type = rdTypeVARCHAR
    'Dynamic or Keyset is meaningless here
    Set rs = qd.OpenResultset(rdOpenStatic)
    'all the output is routed to the debug window
    Debug.Print ".....Starting Result Sets....."
    Do
    Debug.Print
    Debug.Print
    Do Until rs.EOF
    For Each cl In rs.rdoColumns
    If IsNull(cl.Value) Then
    Debug.Print " "; cl.Name; "NULL"; 'Error
    trap for
    null fields
    Else
    Debug.Print " "; cl.Name; " ";
    cl.Value;
    End If
    Next
    Debug.Print
    rs.MoveNext
    Loop
    Loop While rs.MoreResults
    cn.Close
    End Sub
    Without Explicit Ref Cursor Argument
    Oracle Stored Procedures and Packages
    (requires table:
    SQL> desc MTG_VERSION
    Name
    Null?
    Type
    VERSION
    NUMBER
    create or replace PACKAGE BYROYALTYPkg AS
    TYPE RT1 IS RECORD (
    val MTG_VERSION.VERSION%TYPE
    TYPE RCT1 IS REF CURSOR RETURN RT1;
    PROCEDURE byroyalty(
    RC1 IN OUT BYROYALTYPkg.RCT1);
    END;
    create or replace PACKAGE BODY BYROYALTYPkg AS
    PROCEDURE byroyalty(
    RC1 IN OUT BYROYALTYPkg.RCT1)
    AS
    StoO_selcnt INTEGER;
    StoO_error INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
    StoO_sqlstatus INTEGER;
    BEGIN
    OPEN RC1 FOR
    SELECT VERSION FROM MTG_VERSION;
    END byroyalty;
    END;
    create or replace PROCEDURE byroyalty(
    RC1 IN OUT BYROYALTYPkg.RCT1)
    AS
    StoO_selcnt INTEGER;
    StoO_error INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
    StoO_sqlstatus INTEGER;
    BEGIN
    OPEN RC1 FOR
    SELECT VERSION FROM MTG_VERSION;
    END byroyalty;
    VB code
    Dim env1 As rdoEnvironment
    Dim conn1 As rdoConnection
    Dim strsql As String
    Dim ps As rdoPreparedStatement
    Dim rs As rdoResultset
    Private Sub Command1_Click()
    strsql = "begin byroyalty(); end;"
    'in oracle odbc driver uses refcusor argument to
    get result set
    Set ps = conn1.CreatePreparedStatement("PsTest",
    strsql)
    Set rs = ps.OpenResultset(rdOpenStatic)
    Text1 = rs!Version
    rs.Close
    End Sub
    Private Sub Form_Load()
    rdoEngine.rdoDefaultCursorDriver = rdUseOdbc
    Set env1 = rdoEngine.rdoCreateEnvironment(" ", " ", " ")
    strsql = "ODBC;DSN=tot4;UID=test;PWD=test;"
    Set conn1 = env1.OpenConnection(" ", rdDriverPrompt, False,
    strsql)
    conn1.QueryTimeout = 3600
    End Sub
    Actions
    Encourage odbc to allow result sets , via the odbc processed
    extra
    argument, outside of packages.
    Document the current situation, and keep users informed of
    developments.
    Turloch
    Oracle Migration Workbench Team
    Turloch O'Tierney (guest) wrote:
    : Jing,
    : Note that there is an example in the FAQ where the intersolve
    : driver was used so no change was required in the client code.
    The
    : intersolve driver optionally converts the extra argument into a
    : result set. With the Oracle ODBC driver the argument needs to
    be
    : explicitly handled.
    : Is there a problem with RDO and the 8.0.5 ODBC driver handling
    : package references?
    : Turloch
    : Turloch O'Tierney
    : Oracle,
    : Migration and Technology Group.
    : FAQ entry reproduced:
    : How are result sets/dynasets returned to the calling program?
    : The Oracle Migration Workbench parser adds an extra
    argument
    : of type REF CURSOR for result
    : sets/dynasets. This type is understood and can be
    : manipulated by both PL/SQL and Oracle JDBC. Oracle8
    : release 8.0.5 ODBC drivers support REF CURSORs which means
    : that the additional argument must be
    : explicitly handled by the application, and the client
    : application code must be changed. However, some
    : third-party vendors such as Intersolv supply ODBC drivers
    : for Oracle that support REF CURSORs and can, in
    : addition, implicitly make use of REF CURSORs for using
    : result sets/dynasets. Therefore, no change is
    : required in the client application code. This is
    illustrated
    : in the following examples of an MS SQL Server
    : stored procedure and its equivalent Oracle package and
    : stored procedure as generated by the Oracle
    : Migration Workbench parser.
    : MS SQL Server Stored Procedure
    : CREATE PROCEDURE byroyalty
    : AS
    : select au_id from titleauthor
    : GO
    : Oracle8i Package and Stored Procedure
    : PACKAGE BYROYALTYPkg AS
    : TYPE RT1 IS RECORD (
    : au_id titleauthor.au_id%TYPE
    : TYPE RCT1 IS REF CURSOR RETURN RT1;
    : END;
    : PROCEDURE byroyalty(
    : RC1 IN OUT byroyaltyPkg.RCT1)
    : AS
    : StoO_selcnt INTEGER;
    : StoO_error INTEGER;
    : StoO_rowcnt INTEGER;
    : StoO_errmsg VARCHAR2(255);
    : StoO_sqlstatus INTEGER;
    : BEGIN
    : OPEN RC1 FOR
    : SELECT au_id FROM titleauthor;
    : END byroyalty;
    : The following example illustrates the typical ODBC code
    used
    : by Intersolv to call the above MS SQL Server
    : stored procedure. This code also works for the above
    : Oracle8i package and stored procedure. Note that error
    : handling must be added in a real application:
    : SQLPrepare(...,'{call byroyalty()}',...)
    : SQLExecute()
    : SQLBindCol()
    : SQLFetch()
    : Comments:
    : SQLPrepare(...,'{call byroyalty()}',...) is the ODBC SQL
    : syntax used to execute stored procedures.
    : SQLExecute()executes the stored procedure.
    : SQLBindCol()assigns storage for result column 1 in the
    : result set (au_id).
    : SQLFetch() fetches the first record from the result set
    : generated by the stored procedure.
    : The following examples illustrate how to call the above MS
    : SQL Server stored procedure with result
    : sets/dynasets in Visual Basic using DAO and RDO on top of
    : ODBC. This code works for Oracle8i packages
    : and stored procedures if you use an Intersolv ODBC driver
    to
    : understand Oracle REF CURSORs.
    : DAO
    : Private Sub Command2_Click()
    : Dim sSql As String
    : sSql = "{call byroyalty()}"
    : 'In Oracle ODBC driver use refcusor argument to get
    : result set
    : Set rCustomers = dbsServer.OpenRecordset(sSql,
    : dbOpenDynamic)
    : Text4 = rCustomers.Fields(0)
    : theend:
    : End Sub
    : Please note, this example assumes that a DAO connection
    has
    : been set up already.
    : RDO
    : Private Sub Command1_Click()
    : StrSql = "{call byroyalty}"
    : 'in oracle odbc driver uses refcusor argument to get
    : result set
    : Set Ps = connx1.CreatePreparedStatement("PsTest",
    : StrSql)
    : Set Rs = Ps.OpenResultSet(rdOpenStatic)
    : Text3 = Rs!au_id
    : Rs.Close
    : End Sub
    : Please note, this example assumes that an RDO connection
    has
    : been set up already.
    : Jing Zhang (guest) wrote:
    : : Hi, All,
    : : Is there anybody know how much customize we can have for
    using
    : : the MWB when migrate stored procedure? For sample I have a
    SQL
    : : Server 6.5 strored procedure like following:
    : : /******************* SQL Server 6.5 sp *************/
    : : CREATE PROCEDURE sp_SelectUsers
    : : AS
    : : select
    : : tbl_Sp_users.ID, UserName, Password, ExpiresOn,
    : : PwdChangedDate, tbl_Sp_UserGrps.name
    : : from
    : : tbl_Sp_users, tbl_Sp_UserGrps
    : : where
    : : GroupID = tbl_Sp_UserGrps.id
    : : order by username
    : : /******************* end ***************************/
    : : After I migrate it to Oracle 8 with MWB, I got following
    : object,
    : : one Pkg and one Procedure in Oracle db, like following:
    : : /****************** Oracle Pkg **********************/
    : : CREATE OR REPLACE PROCEDURE sp_SelectUsers(
    : : RC1 IN OUT sp_SelectUsersPkg.RCT1)
    : : AS
    : : StoO_selcnt INTEGER;
    : : StoO_error INTEGER;
    : : StoO_rowcnt INTEGER;
    : : StoO_errmsg VARCHAR2(255);
    : : StoO_sqlstatus INTEGER;
    : : BEGIN
    : : OPEN RC1 FOR
    : : SELECT tbl_Sp_users.ID, UserName, Password,
    : : ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
    : : tbl_Sp_users, tbl_Sp_UserGrps
    : : WHERE GroupID = tbl_Sp_UserGrps.id
    : : ORDER BY username ;
    : : END sp_SelectUsers;
    : : /******************* Oracle Procedure ****************/
    : : PROCEDURE sp_SelectUsers(
    : : RC1 IN OUT sp_SelectUsersPkg.RCT1)
    : : AS
    : : StoO_selcnt INTEGER;
    : : StoO_error INTEGER;
    : : StoO_rowcnt INTEGER;
    : : StoO_errmsg VARCHAR2(255);
    : : StoO_sqlstatus INTEGER;
    : : BEGIN
    : : OPEN RC1 FOR
    : : SELECT tbl_Sp_users.ID, UserName, Password,
    : : ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
    : : tbl_Sp_users, tbl_Sp_UserGrps
    : : WHERE GroupID = tbl_Sp_UserGrps.id
    : : ORDER BY username ;
    : : END sp_SelectUsers;
    : : /******************* end *****************************/
    : : As our client use RDO as access method, there is no way we
    can
    : : use this migrated SP in RDO and return resultset. We need
    : : convert this SP to following to be able to use RDO to get
    : : resultset back in client:
    : : /******************* need convert to *********************/
    : : create or replace package sp_selectUsersPkg
    : : as
    : : cursor c1
    : : is select tbl_Sp_users.ID, UserName, Password,ExpiresOn,
    : : PwdChangedDate, tbl_Sp_UserGrps.name
    : : from tbl_Sp_users, tbl_Sp_UserGrps
    : : where GroupID = tbl_Sp_UserGrps.id
    : : order by username;
    : : type UsersCur
    : : is ref cursor return c1%ROWTYPE;
    : : procedure sp_selectUsers(UserCursor in out UsersCur );
    : : END;
    : : create or replace package body sp_selectUsersPkg
    : : as
    : : procedure sp_selectUsers(UserCursor in out UsersCur )
    : : is
    : : begin
    : : open UserCursor for
    : : select tbl_Sp_users.ID, UserName,
    : : password, ExpiresOn,
    : : PwdChangedDate, tbl_Sp_UserGrps.name
    : : from tbl_Sp_users, tbl_Sp_UserGrps
    : : where GroupID = tbl_Sp_UserGrps.id
    : : order by username;
    : : end;
    : : end;
    : : /******************* end *********************************/
    : : Is there any idea how we can do this? I hope we don't need do
    : : this manually.
    : : Thank you very much for any help!
    : : Jing
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Need help with BC4J/Struts application using a Stored Procedure

    Hi,
    I am doing a proof of concept for a new project using JDeveloper, Struts and BC4J. We want to reuse our Business logic that is currently residing in Oracle Stored Procedures. I previously created a BC4J Entity Object based on a stored procedure Using Oracle Stored Procedures but this stored procedure is a bit different in that it returns a ref cursor as one of the paramters. http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html
    I tried the above method, but I am having some trouble with it. I keep getting the error ORA-01008: not all variables are bound when I test it using the AppModule tester.
    Here is the store procedure definition:
    CREATE OR REPLACE PACKAGE pprs_test_wrappers IS
    TYPE sn_srch_results IS REF CURSOR;
    PROCEDURE sn_srch_main_test
    (serial_num_in IN OUT VARCHAR2
    ,serial_coll_cd_in IN OUT NUMBER
    ,max_rows_allowed IN OUT NUMBER
    ,total_rows_selected IN OUT NUMBER
    ,message_cd_out IN OUT VARCHAR2
    ,query_results          OUT sn_srch_results
    END pprs_test_wrappers;
    And here is my code:
    package pprs;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.sql.Types;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    // --- File generated by Oracle Business Components for Java.
    public class LienCheckImpl extends ViewObjectImpl
    * This is the PLSQL block that we will execute to retrieve the REF CURSOR
    private static final String SQL =
    "begin ? := pprs_test_wrappers.sn_srch_main_test(?, ?, ?, ?, ?, ?);end;";
    public LienCheckImpl() {}
    * Overridden framework method.
    * Executed when the framework needs to issue the database query for
    * the query collection based on this view object. One view object
    * can produce many related result sets, each potentially the result
    * of different bind variable values. If the rowset in query is involved
    * in a framework-coordinated master/detail viewlink, then the params array
    * will contain one or more framework-supplied bind parameters. If there
    * are any user-supplied bind parameter values, they will PRECEED the
    * framework-supplied bind variable values in the params array, and the
    * number of user parameters will be indicated by the value of the
    * numUserParams argument.
    protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
    * If there are where-clause params (for example due to a view link)
    * they will be in the 'params' array.
    * We assume that if some parameter is present, that it is a Deptno
    * value to pass as an argument to the stored procedure.
    * NOTE: Due to Bug#2828248 I have to cast to BigDecimal for now,
    * ---- but this parameter value should be oracle.jbo.domain.Number type.
    String serialNumIn = null;
    BigDecimal serialCollCdIn = null;
    BigDecimal maxRowsAllowed = null;
    BigDecimal totalRowsSelected = null;
    String messageCdOut = null;
    if (params != null) {
    serialNumIn = (String)params[0];
    serialCollCdIn = (BigDecimal)params[1];
    maxRowsAllowed = (BigDecimal)params[2];
    totalRowsSelected = (BigDecimal)params[3];
    messageCdOut = (String)params[4];
    storeNewResultSet(qc,retrieveRefCursor(qc,serialNumIn,
    serialCollCdIn,
    maxRowsAllowed,
    totalRowsSelected,
    messageCdOut));
    super.executeQueryForCollection(qc, params, numUserParams);
    * Overridden framework method.
    * Wipe out all traces of a built-in query for this VO
    protected void create() {
    getViewDef().setQuery(null);
    getViewDef().setSelectClause(null);
    setQuery(null);
    * Overridden framework method.
    * The role of this method is to "fetch", populate, and return a single row
    * from the datasource by calling createNewRowForCollection() and populating
    * its attributes using populateAttributeForRow().
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
    * We ignore the JDBC ResultSet passed by the framework (null anyway) and
    * use the resultset that we've stored in the query-collection-private
    * user data storage
    rs = getResultSet(qc);
    * Create a new row to populate
    ViewRowImpl r = createNewRowForCollection(qc);
    try {
    * Populate new row by attribute slot number for current row in Result Set
    populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
    populateAttributeForRow(r,1, nullOrNewNumber(rs.getBigDecimal(2)));
    populateAttributeForRow(r,2, rs.getString(3));
    populateAttributeForRow(r,3, rs.getString(4));
    populateAttributeForRow(r,4, rs.getString(5));
    catch (SQLException s) {
    throw new JboException(s);
    return r;
    * Overridden framework method.
    * Return true if the datasource has at least one more record to fetch.
    protected boolean hasNextForCollection(Object qc) {
    ResultSet rs = getResultSet(qc);
    boolean nextOne = false;
    try {
    nextOne = rs.next();
    * When were at the end of the result set, mark the query collection
    * as "FetchComplete".
    if (!nextOne) {
    setFetchCompleteForCollection(qc, true);
    * Close the result set, we're done with it
    rs.close();
    catch (SQLException s) {
    throw new JboException(s);
    return nextOne;
    * Overridden framework method.
    * The framework gives us a chance to clean up any resources related
    * to the datasource when a query collection is done being used.
    protected void releaseUserDataForCollection(Object qc, Object rs) {
    * Ignore the ResultSet passed in since we've created our own.
    * Fetch the ResultSet from the User-Data context instead
    ResultSet userDataRS = getResultSet(qc);
    if (userDataRS != null) {
    try {
    userDataRS.close();
    catch (SQLException s) {
    /* Ignore */
    super.releaseUserDataForCollection(qc, rs);
    * Return a JDBC ResultSet representing the REF CURSOR return
    * value from our stored package function.
    private ResultSet retrieveRefCursor(Object qc,
    String serialNum,
    BigDecimal serialColCd,
    BigDecimal maxRows,
    BigDecimal totalRows,
    String messageCd ) {
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement(SQL,DBTransaction.DEFAULT);
    * Register the first bind parameter as our return value of type CURSOR
    st.registerOutParameter(1,OracleTypes.CURSOR);
    * Set the value of the 2nd bind variable to pass id as argument
    if (serialNum == null) st.setNull(2,Types.CHAR);
    else st.setString(2,serialNum);
    if (serialColCd == null) st.setNull(3,Types.NUMERIC);
    else st.setBigDecimal(3,serialColCd);
    if (maxRows == null) st.setNull(4,Types.NUMERIC);
    else st.setBigDecimal(4,maxRows);
    if (totalRows == null) st.setNull(5,Types.NUMERIC);
    else st.setBigDecimal(5,totalRows);
    if (messageCd == null) st.setNull(6,Types.CHAR);
    else st.setString(6,messageCd);
    st.execute();
    ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
    * Make this result set use the fetch size from our View Object settings
    rs.setFetchSize(getFetchSize());
    return rs ;
    catch (SQLException s) {
    throw new JboException(s);
    finally {try {st.close();} catch (SQLException s) {}}
    * Store a new result set in the query-collection-private user-data context
    private void storeNewResultSet(Object qc, ResultSet rs) {
    ResultSet existingRs = getResultSet(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {existingRs.close();} catch (SQLException s) {}
    setUserDataForCollection(qc,rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    * Retrieve the result set wrapper from the query-collection user-data
    private ResultSet getResultSet(Object qc) {
    return (ResultSet)getUserDataForCollection(qc);
    * Return either null or a new oracle.jbo.domain.Number
    private static oracle.jbo.domain.Number nullOrNewNumber(BigDecimal b) {
    try {
    return b != null ? new oracle.jbo.domain.Number(b) : null;
    catch (SQLException s) { }
    return null;
    I created the view object in expert mode so there is no entity object. Can someone help? I don't have much time left to finish this.
    Also, could I have done this from the Entity object instead of the view object by registering the ref cursor OUT parameter in handleStoredProcInsert()?
    Thanks
    Natalie

    I was able to get the input parameter by putting the following in my struts actions class
    vo.setWhereClauseParam(0,request.getParameter("row0_SerialNum"));
    The full code is:
    package mypackage2;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import oracle.jbo.html.BC4JContext;
    import oracle.jbo.ViewObject;
    import oracle.jbo.html.struts11.BC4JUtils;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    public class LienCheckView1QueryAction extends Action
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    BC4JContext context = BC4JContext.getContext(request);
    // Retrieve the view object instance to work with by name
    ViewObject vo = context.getApplicationModule().findViewObject("LienCheckView1");
    vo.setRangeSize(3);
    vo.setIterMode(ViewObject.ITER_MODE_LAST_PAGE_PARTIAL);
    // Do any additional VO setup here (e.g. setting bind parameter values)
    vo.setWhereClauseParam(0,request.getParameter("row0_SerialNum"));
    // default value for serialCollCd 1 is for Motor Vehicles
    vo.setWhereClauseParam(1,new oracle.jbo.domain.Number(1));
    // Default value for maxRows_allowed
    vo.setWhereClauseParam(2,new oracle.jbo.domain.Number(20));
    return BC4JUtils.getForwardFromContext(context, mapping);
    This doesn't always work properly though. The first time I press the query button, the SerialNum parameter is still null, however if I re-execute the query by pressing the query button again. It will work, and return the rows. I always have to query twice. Also the SerialNum attribute is set to a String in my view object, it is a varchar column in the database, but some serial number I enter give a "Error Message: oracle.jbo.domain.Number ". This happens even though the underlying BC4J is returning values for the query. I also get a "500 Internal Server Error java.lang.ClassCastException: java.lang.String on my View object's code at line 65 which is
    if (params.length>1) serialCollCdIn = (BigDecimal)params[1];
    This is an input paramter to the oracle stored procedure that defaults to a Number value of 1.
    Any idea what the problem is? Here is the full code for my view object:
    package mypackage1;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.sql.Types;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    // --- File generated by Oracle Business Components for Java.
    public class LienCheckViewImpl extends ViewObjectImpl
    * This is the PLSQL block that we will execute to retrieve the REF CURSOR
    private static final String SQL =
    "begin pprs_test_wrappers.sn_srch_main_test(?, ?, ?, ?, ?, ?);end;";
    private BigDecimal totalRows = null;
    private String messageCd = null;
    private BigDecimal serialColCd = null;
    private BigDecimal maxRows = null;
    public LienCheckViewImpl() {}
    * Overridden framework method.
    * Executed when the framework needs to issue the database query for
    * the query collection based on this view object. One view object
    * can produce many related result sets, each potentially the result
    * of different bind variable values. If the rowset in query is involved
    * in a framework-coordinated master/detail viewlink, then the params array
    * will contain one or more framework-supplied bind parameters. If there
    * are any user-supplied bind parameter values, they will *PRECEED* the
    * framework-supplied bind variable values in the params array, and the
    * number of user parameters will be indicated by the value of the
    * numUserParams argument.
    protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
    * If there are where-clause params (for example due to a view link)
    * they will be in the 'params' array.
    * We assume that if some parameter is present, that it is a Deptno
    * value to pass as an argument to the stored procedure.
    * NOTE: Due to Bug#2828248 I have to cast to BigDecimal for now,
    * ---- but this parameter value should be oracle.jbo.domain.Number type.
    String serialNumIn = null;
    BigDecimal serialCollCdIn = null;
    BigDecimal maxRowsAllowed = null;
    BigDecimal totalRowsSelected = null;
    String messageCdOut = null;
    if (params != null) {
    if (params.length>0) serialNumIn = (String)params[0];
    if (params.length>1) serialCollCdIn = (BigDecimal)params[1];
    if (params.length>2) maxRowsAllowed = (BigDecimal)params[2];
    storeNewResultSet(qc,retrieveRefCursor(qc,serialNumIn,
    serialCollCdIn,
    maxRowsAllowed));
    super.executeQueryForCollection(qc, params, numUserParams);
    * Overridden framework method.
    * Wipe out all traces of a built-in query for this VO
    protected void create() {
    getViewDef().setQuery(null);
    getViewDef().setSelectClause(null);
    setQuery(null);
    * Overridden framework method.
    * The role of this method is to "fetch", populate, and return a single row
    * from the datasource by calling createNewRowForCollection() and populating
    * its attributes using populateAttributeForRow().
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
    * We ignore the JDBC ResultSet passed by the framework (null anyway) and
    * use the resultset that we've stored in the query-collection-private
    * user data storage
    rs = getResultSet(qc);
    * Create a new row to populate
    ViewRowImpl r = createNewRowForCollection(qc);
    try {
    * Populate new row by attribute slot number for current row in Result Set
    //AddedByRegisNum
    populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
    System.out.println("AddedByRegisNum :" + rs.getBigDecimal(1));
    // OrigRegisNum
    populateAttributeForRow(r,1, nullOrNewNumber(rs.getBigDecimal(2)));
    System.out.println("OrigRegisNum :" + rs.getBigDecimal(2));
    // SerialNum
    populateAttributeForRow(r,2, rs.getString(3));
    System.out.println("SerialNum :" + rs.getString(3));
    // SerialNumDesc
    populateAttributeForRow(r,3, rs.getString(4));
    System.out.println("SerialNumDesc :" + rs.getString(4));
    // FlagExactMatch
    populateAttributeForRow(r,4, rs.getString(5));
    System.out.println("FlagExactMatch :" + rs.getString(5));
    // MessageCd
    populateAttributeForRow(r,5, messageCd);
    // TotalRows
    populateAttributeForRow(r,6, totalRows);
    catch (SQLException s) {
    throw new JboException(s);
    return r;
    * Overridden framework method.
    * Return true if the datasource has at least one more record to fetch.
    protected boolean hasNextForCollection(Object qc) {
    ResultSet rs = getResultSet(qc);
    boolean nextOne = false;
    try {
    nextOne = rs.next();
    * When were at the end of the result set, mark the query collection
    * as "FetchComplete".
    if (!nextOne) {
    setFetchCompleteForCollection(qc, true);
    * Close the result set, we're done with it
    rs.close();
    catch (SQLException s) {
    throw new JboException(s);
    return nextOne;
    * Overridden framework method.
    * The framework gives us a chance to clean up any resources related
    * to the datasource when a query collection is done being used.
    protected void releaseUserDataForCollection(Object qc, Object rs) {
    * Ignore the ResultSet passed in since we've created our own.
    * Fetch the ResultSet from the User-Data context instead
    ResultSet userDataRS = getResultSet(qc);
    if (userDataRS != null) {
    try {
    userDataRS.close();
    catch (SQLException s) {
    /* Ignore */
    super.releaseUserDataForCollection(qc, rs);
    * Overridden framework method
    * Return the number of rows that would be returned by executing
    * the query implied by the datasource. This gives the developer a
    * chance to perform a fast count of the rows that would be retrieved
    * if all rows were fetched from the database. In the default implementation
    * the framework will perform a SELECT COUNT(*) FROM (...) wrapper query
    * to let the database return the count. This count might only be an estimate
    * depending on how resource-intensive it would be to actually count the rows.
    public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
    Object[] params = viewRowSet.getParameters(true);
    String serialNumIn = (String)params[0];
    BigDecimal serialCollCdIn = (BigDecimal)params[1];
    BigDecimal maxRowsAllowed = (BigDecimal)params[2];
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement(SQL,DBTransaction.DEFAULT);
    * Register the fourth bind parameter as our return value of type NUMERIC
    st.registerOutParameter(4,Types.NUMERIC);
    * Set the value of the 3 bind variables to pass as arguments
    if (serialNumIn == null) st.setNull(1, Types.CHAR);
    else st.setString(1,serialNumIn);
    if (serialCollCdIn == null) st.setNull(2,Types.NUMERIC);
    else st.setBigDecimal(2,serialCollCdIn);
    if (maxRowsAllowed == null) st.setNull(3, Types.NUMERIC);
    else st.setBigDecimal(3, maxRowsAllowed);
    st.execute();
    System.out.println("returning value of :" + st.getLong(4));
    return st.getLong(4);
    catch (SQLException s) {
    throw new JboException(s);
    finally {try {st.close();} catch (SQLException s) {}}
    * Return a JDBC ResultSet representing the REF CURSOR return
    * value from our stored package function.
    private ResultSet retrieveRefCursor(Object qc,
    String serialNum,
    BigDecimal serialColCd,
    BigDecimal maxRows) {
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement(SQL,DBTransaction.DEFAULT);
    * Set the value of the bind variables
    System.out.println("SerialNumIn :" + serialNum);
    if (serialNum == null) st.setNull(1,Types.CHAR);
    else st.setString(1,serialNum);
    if (serialColCd == null) st.setNull(2,Types.NUMERIC);
    else st.setBigDecimal(2,serialColCd);
    if (maxRows == null) st.setNull(3,Types.NUMERIC);
    else st.setBigDecimal(3,maxRows);
    st.registerOutParameter(1, Types.CHAR); // serialNum
    st.registerOutParameter(2, Types.NUMERIC); // serialColCd
    st.registerOutParameter(3, Types.NUMERIC); // maxRows
    st.registerOutParameter(4, Types.NUMERIC); // totalRows
    st.registerOutParameter(5, Types.CHAR); // messageCd
    * Register the 6th bind parameter as our return value of type CURSOR
    st.registerOutParameter(6,OracleTypes.CURSOR);
    st.execute();
    ResultSet rs = ((OracleCallableStatement)st).getCursor(6);
    serialColCd = st.getBigDecimal(2);
    System.out.println("SerialColCd= " + serialColCd);
    maxRows = st.getBigDecimal(3);
    System.out.println("maxRows= " + maxRows);
    totalRows = st.getBigDecimal(4);
    System.out.println("totalRows= " + totalRows);
    messageCd = st.getString(5);
    System.out.println("messageCd= " + messageCd);
    * Make this result set use the fetch size from our View Object settings
    rs.setFetchSize(getFetchSize());
    return rs ;
    catch (SQLException s) {
    throw new JboException(s);
    finally {try {st.close();} catch (SQLException s) {}}
    * Store a new result set in the query-collection-private user-data context
    private void storeNewResultSet(Object qc, ResultSet rs) {
    ResultSet existingRs = getResultSet(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {existingRs.close();} catch (SQLException s) {}
    setUserDataForCollection(qc,rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    * Retrieve the result set wrapper from the query-collection user-data
    private ResultSet getResultSet(Object qc) {
    return (ResultSet)getUserDataForCollection(qc);
    * Return either null or a new oracle.jbo.domain.Number
    private static oracle.jbo.domain.Number nullOrNewNumber(BigDecimal b) {
    try {
    return b != null ? new oracle.jbo.domain.Number(b) : null;
    catch (SQLException s) { }
    return null;
    Natalie

  • Sender JDBC support the stored procedure in SQL Server 2005

    Dear All,
    My question here is , Sender is JDBC adpter support to call the Stored procedure in Microsoft SQL Server 2005?
    I followed the below thread before posting this question
    Sender JDBC Adapter Supports Stored Procedures????
    In the thread Suraj response has mentioned SAP note: 941317, I checked the note, Note says it supported only ORACLE DBMS versions.
    Could you please clarify about this to possibility to call the stored procedure in Microsoft SQL server 2005?
    Thank you in Advance
    Sateesh

    Hi Sateesh,
    To answer your query, Yes it does. SP call works with SQL Server 2005 as well, the SP call should be "execute SPNAME <paramas>". In the place of update statement put any junk value as mentioned in the earlier comment.
    But just one thing to be noted, the select or any other query returning the desired resultset must be the first statement in youre SP returning value to the calling app. Means if there are any update, deletion or intermediate select queries to be used with in your SP, those all should be placed after the Main Select query that returns the desired resultset. Variable declarions and assignments are allowed.
    But if the seq of statements in your SP are like:
    @var1 Varchar
    Update <tablename>....
    Select * from <tablename>
    Then the output of the SP is :
    1 row updated
    <the resultset from select>
    In such cases, PI can recognise the first value returned only, that is "1 row updated" and hence the returned resultset wouldn't be seen by PI or not be passed to integration engine. Hence the update should come after the main Select.
    One more interesting piece of information, even if you copy and paste the entire SP code in place of the query string of Sender JDBC adapter, that too will work with all your variable declarations, multiple queries and updates and everything. Just have to follow the above rule.
    Let us know what you find.
    Regards,
    Suddhasatta

  • Add Table Valued Parameter to a stored procedure

    I have a stored procedure that voids an invoice and puts the items back into inventory and makes available the payment that was used to apply to this invoice... I would like to be able to do all this for a number of invoices at a time using a table valued
    parameter how would I be able to do it?
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author: Debra
    -- Create date: March 25, 2014
    -- Description: Void an invoice.
    -- =============================================
    CREATE PROCEDURE AR_VOID
    -- Add the parameters for the stored procedure here
    @Invoice INT,
    @InvType nvarchar(3)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
        -- Insert statements for procedure here
    IF(@InvType = 'reg')
        BEGIN
    UPDATE INV SET ONHAND = ONHAND + ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED + ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
    WHERE ARD.INVOICE = @Invoice
    MERGE INTO RECEIPTSH target
        USING (SELECT JOURNAL, SUM(AMOUNT) AMOUNT FROM Applied
        WHERE INVOICE = @Invoice GROUP BY JOURNAL) AS source
        ON target.Journal = source.Journal
        WHEN MATCHED THEN 
        UPDATE 
        SET Applied = Applied - SOURCE.Amount;
        DELETE Applied WHERE INVOICE = @Invoice
        END
        ELSE 
        BEGIN
    UPDATE INV SET ONHAND = ONHAND - ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED - ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
    WHERE ARD.INVOICE = @Invoice
    MERGE INTO ARH target
        USING (SELECT INVOICE, SUM(AMOUNT) AMOUNT FROM CREDITMEMO WHERE CINVOICE = @Invoice GROUP BY INVOICE) AS source
        ON target.INVOICE = source.INVOICE
        WHEN MATCHED THEN 
        UPDATE 
        SET [OPEN] = 'TRUE', CLOSEDATE = NULL, PAID = target.PAID - source.AMOUNT;
    DELETE CREDITMEMO WHERE CINVOICE = @Invoice
        END
        UPDATE ARH SET SUBTOTAL = 0, TAXES = 0, PAID = 0, STATUS = 'VOD', [OPEN] = 'FALSE', CLOSEDATE = CONVERT(DATE,GETDATE()) WHERE INVOICE = @Invoice
    UPDATE ARD SET QTY = 0, ARD.PRICE = 0 WHERE INVOICE = @Invoice
    END
    GO
    Debra has a question

    Try
    CREATE TYPE InvoicesList AS TABLE (InvoiceID INT)
    GO
    - =============================================
    -- Author: Debra
    -- Create date: March 25, 2014
    -- Description: Voids passed invoices.
    -- =============================================
    CREATE PROCEDURE AR_VOID
    @InvoicesList InvoicesList READONLY,
    @InvType nvarchar(3)
    AS
    BEGIN
    SET NOCOUNT ON;
    IF(@InvType = 'reg')
    BEGIN
    UPDATE INV SET ONHAND = ONHAND + ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED + ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
    WHERE ARD.INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
    MERGE INTO RECEIPTSH target
    USING (SELECT JOURNAL, SUM(AMOUNT) AMOUNT FROM Applied
    WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList) GROUP BY JOURNAL) AS source
    ON target.Journal = source.Journal
    WHEN MATCHED THEN
    UPDATE
    SET Applied = Applied - SOURCE.Amount;
    DELETE Applied WHERE INVOICE IN (Select InvoiceID FROM @InvoicesList)
    END
    ELSE
    BEGIN
    UPDATE INV SET ONHAND = ONHAND - ARD.Qty,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED - ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
    WHERE ARD.INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
    MERGE INTO ARH target
    USING (SELECT INVOICE, SUM(AMOUNT) AMOUNT FROM CREDITMEMO WHERE CINVOICE IN (SELECT InvoiceID FROM @InvoicesList) GROUP BY INVOICE) AS source
    ON target.INVOICE = source.INVOICE
    WHEN MATCHED THEN
    UPDATE
    SET [OPEN] = 'TRUE', CLOSEDATE = NULL, PAID = target.PAID - source.AMOUNT;
    DELETE CREDITMEMO WHERE CINVOICE IN (SELECT InvoiceID FROM @InvoicesList)
    END
    UPDATE ARH SET SUBTOTAL = 0, TAXES = 0, PAID = 0, STATUS = 'VOD', [OPEN] = 'FALSE', CLOSEDATE = CONVERT(DATE,GETDATE()) WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
    UPDATE ARD SET QTY = 0, ARD.PRICE = 0 WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
    END
    GO
    I didn't look too close into your code, so I just translated your code as is into TVP.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Drop the stored procedure having null schema

    Hello All,
    I have 2 SPs with same name but different schema id , one 1(default) and other is 20 but when i check in sys.schemas it give no record for schema_id 20.
    i would like to drop the SP which has schema_id 20, i dont know the schema name for id 20 so not able to drop it.
    Please help me out to remove\drop the SP which has null schema.

    What version of SQL Server and service pack are your running? I've never seen this but you might try first try restarting SQL to rule cache corruption.  If the problem persists, below are some steps you can try.
    Run the query below to get the schema name from the stored procedure CREATE statement:
    SELECT m.definition
    FROM sys.procedures AS p
    JOIN sys.sql_modules AS m ON
    m.object_id = p.object_id
    WHERE OBJECT_SCHEMA_NAME(object_id) IS NULL;
    Query sys.schemas to identify gaps in schema_id values less than 20.  Create schemas with dummy names until schema_id 19 is assigned.  Then create a schema with the name retrieved from the proc schema and verify it has been assigned schema_id
    20.  Finally, try to drop the proc using the schema-qualified name.
    Is there anything unusual that might help explain what led to this problem.  Maybe a transfer of objects from one schema to another that went awry?
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • HIDE THE STORED PROCEDURE

    how i can HIDE THE STORED PROCEDURE for other user oracle version 9i
    Edited by: razagold on Jun 5, 2010 6:29 AM
    Edited by: razagold on Jun 5, 2010 6:30 AM

    Hardly anyone uses C or C++ with Oracle any more. If you are in an environment where this is done it is a very rare environment these days.
    Try to find an Oracle conference, or job description at dice.com, that asks for Oracle and C any more. Rarer than requests for Korn shell scripting.
    Your argument with respect to keeping the customer in the dark has nothing to do with Open Source. Perhaps you have not worked in the business of selling Oracle-based applications but you need to consider what reality looks like. The customer opens a support ticket. Do you ask to see the source code the minute they open the ticket? They have a problem that your support engineers can not solve in one day. Do you review all of your source code after 24 hours? When do you reach the threshold that doing so makes sense? Remember you application has many tens or hundeds of thousands of lines of code. By the time you do you have spent a small fortune in support costs. Your customer is angry with you. And the moron that made the change doesn't even work there any more so what are you going to do? Cut off their support and lose them to a competitor? No. Very simply you wrap your code and make alterations impossible.
    With respect to lawsuits. Not to pick on any country but just as an example. Lets assume you are in North America and sell an application. And lets further assume your code ends up in a commercial application sold by a company in China. You're going to sue them? Let's assume you don't have a team of lawyers on your payroll like Bill and Larry. You're going to sue them? Not realistic by any measure. Wrapping is simple and wrapping is free.

Maybe you are looking for