Problem in executing the stored procedure

I am trying to execute the following procedure which is used to capture data from 4 different tables:
The table structure is as follows with the sample data:
AREA
======
area_id area_type preferred_name
A1 Country India
A2 State AP
A3 Country Finland
A4 State Finland's State
A5 Country USA
T_CREATE_STAGE
=============
we_name we_num country_nm state_nm operator
B1 C1 A1 A2 O1
B1 C2 A3 A4 O1
ASSOCIATE
==========
ba_name busi_associate
ABC O1
XYZ O2
The IN-Paremeters of the procedure takes the Country name & State name (Prefered Name in table AREA) Operator Name (ba_name in table ASSOCIATE), at a time at least one parameter would come as Input and that could also be a Wild Card search.
The problem is that in the following procedure the query is taking the first match and returning it infinite times. Please suggest a suitable way to run the query in the procedure so that it returns the appropriate result.
CREATE OR REPLACE PROCEDURE proc_new_search (
p_recordset OUT sys_refcursor,
countryName VARCHAR2 ,
stateName VARCHAR2 ,
opName VARCHAR2 ,
fieldName VARCHAR2
AS
BEGIN
DECLARE
BEGIN
OPEN p_recordset FOR 'select b.preferred_name,d.preferred_name,a.we_name,a.we_num,c.ba_name,'
|| 'a.fluid_type,e.preferred_name FROM T_CREATE_STAGE a, AREA b,AREA d,AREA e,ASSOCIATE c '
|| 'where (upper('''||countryName||''') IS NULL or instr(b.preferred_name, upper('''||countryName||''') ) > 0) AND a.country_nm = b.area_id AND b.area_type=''COUNTRY'' AND b.active_ind=''Y'''
||' AND (upper('''||opName||''') IS NULL or instr(c.ba_name,upper('''|| opName||''') ) > 0) AND a.operator = c.busi_associate'
||' AND (upper('''||stateName||''') IS NULL or instr(d.preferred_name,upper('''|| stateName ||''') ) > 0) AND a.province_state = d.area_id AND d.area_type=''STATE_PROVINCE'' AND d.active_ind=''Y'''
|| ' AND (upper('''||fieldName||''') IS NULL or instr(a.field, upper('''||fieldName||''' )) > 0) ';
END;
Thanks in advance,
Regards,
Priya

OK, I have extracted the SQL from the code you posted. I notice that there are FIVE tables in the FROM clause of the SQL:
FROM T_CREATE_STAGE a,
       AREA b,
       AREA d,
       AREA e,
       ASSOCIATE cwhereas there are only THREE join-conditions joining FOUR tables [5th table AREA e has not been joined with any of the tables]:
/* other conditions in the WHERE clause are filters, not table joins */
       AND a.country_nm = b.area_id
       AND a.operator = c.busi_associate
       AND a.province_state = d.area_idIn order to get valid expected result from a query involving FIVE tables, at least FOUR joins are required. *[ in a query involving N tables, at least N-1 joins are required ]*. Otherwise, the result will have duplication and hence will not be valid/as-expected.
So add a join involving AREA e table with other(s) and see if this improves the result.
HTH

Similar Messages

  • Error while executing the stored procedure through sender JDBC adapter

    Hi All,
    I am getting below error while executing the stored procedure through sender JDBC adapter.
    Database-level error reported by JDBC driver while executing statement 'exec SapgetNextEntity 'SalesOrder''. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
    what is the problem? any idea to anyone...
    regards
    Ramesh

    hi Dharamveer,
    I am not getting below statement for your reply
    Try to use Refrence Cursor it will return u reference of resultset.
    I mention SP like this
    exec SapgetNextEntity 'SalesOrder'
    SapgetNextEntity -
    > SP Name
    SalesOrder----
    > Parameter I am passing...
    regards
    Ramesh

  • Problem while executing a Stored Procedure

    Hi,
    im a newbie,using Oracle 10g v(10.2.0.1.0) on linux machine.
    Im unable to execute following procedure through iSQLPLUS query interface.
    create or replace procedure pd_hr(
    pno varchar2,
    pdt date default sysdate,
    phr out number,
    perr_msg out varchar2
    ) as
    begin
         phr := 2;
    end pd_hr;
    VARIABLE phr number;
    VARIABLE perr_msg VARCHAR2(250);
    execute pd_hr('pno',NULL,phr,perr_msg);
    It flashes the following error when i try to execute the stored proc:
    ERROR at line 1:
    ORA-06550: line 1, column 44:
    PLS-00201: identifier 'PHR' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    I executed the following query through DBA login before executing the procedure:
    GRANT EXECUTE ANY PROCEDURE TO "SCOTT";
    Any kind of assistance will be priceless!
    Peter

    Hi, Peter,
    user10707566 wrote:
    Thanks Frank, it worked seamlessly!
    btw what the ':' signifies here?":" just means "this is a bind variable".
    It's convenient, because when you name a bind variable "phr", you can use ":phr" without worrying whether there is a column or a local variable that is also called phr, and, if so, which one takes precedence.

  • Executing the stored procedure with output which is a collection of objects

    Hello,
    I have the objects and collection of objects within an objects as below:
    CREATE OR REPLACE TYPE SHARE_OUTST_T
    AS OBJECT
    SHR_OUTST_AMT     number
    CREATE OR REPLACE TYPE SECURITY_T
    AS OBJECT
         VOTE_PER_SHR     number
    , CUSIP     varchar2(12)
    , EXCHANGE     varchar2(10)
    , IV_TYPE_CD     varchar2(10)
    , SEC_TICKER_SYMB     varchar2(20)
    CREATE OR REPLACE TYPE ALTERNATE_ID_T
    AS OBJECT
    ( ALT_ID_TYPE     varchar2(20)
    CREATE OR REPLACE TYPE ISSUE_MAINT_VERSION_T
    AS OBJECT
         IM_KEY_ID number     
    ,     IM_VER_NUM number
    ,     EFF_TMSTMP timestamp
    , EXP_TMSTMP timestamp
    ,     NEXT_REVIEW_TMSTMP timestamp
    ,     APPR_STATUS_REF_ID number
    , VOTE number
    , ADD_USR_ID varchar2(20)
    , ADD_TMSTMP timestamp
    , UPD_USR_ID varchar2(20)
    , UPD_TMSTMP timestamp
    , LOCK_LEVEL_NUM number
    , ACTION VARCHAR2(1)
    CREATE OR REPLACE TYPE ISSUE_SHARE_MAINT_T
    AS OBJECT
         IM_KEY_ID      number     
    ,     IM_VER_NUM      number
    ,     SHR_OUTST_AMT      number
    ,     CURR_OUTST_AMT     number
    ,      ADD_USR_ID      varchar2(20)
    ,      ADD_TMSTMP      timestamp
    ,      UPD_USR_ID      varchar2(20)
    ,      UPD_TMSTMP      timestamp
    ,      LOCK_LEVEL_NUM      number
    ,     ACTION     VARCHAR2(1)
    CREATE OR REPLACE TYPE ISSUE_MAINT_COMMENT_T
    AS OBJECT
         IM_KEY_ID      number     
    ,     IM_VER_NUM      number
    ,     COMMENT_TXT     varchar2(400)
    ,      ADD_USR_ID      varchar2(20)
    ,      ADD_TMSTMP      timestamp
    ,      UPD_USR_ID      varchar2(20)
    ,      UPD_TMSTMP      timestamp
    ,      LOCK_LEVEL_NUM      number
    ,     ACTION     VARCHAR2(1)
    CREATE OR REPLACE TYPE ISSUE_MAINT_COMMENT_COL_T AS TABLE OF ISSUE_MAINT_COMMENT_T;
    CREATE OR REPLACE TYPE ISSUE_VERSION_T
    AS OBJECT
         SHARE_OUTST     SHARE_OUTST_T
    ,     SECURITY     SECURITY_T
    ,     ALTERNATE_ID     ALTERNATE_ID_T
    ,     ISSUER     ISSUER_T
    ,     ISSUE_MAINT_VERSION     ISSUE_MAINT_VERSION_T
    ,     ISSUE_SHARE_MAINT     ISSUE_SHARE_MAINT_T
    , ISSUE_MAINT_COMMENT_COL ISSUE_MAINT_COMMENT_T
    CREATE OR REPLACE TYPE ISSUE_VERSION_COL_T AS TABLE OF ISSUE_VERSION_T;
    And the stored procedure as :
    =======================================
    PROCEDURE get_all_issue_version_col
    ( pv_issue_version_col OUT issue_version_col_t
    AS
    CURSOR cur_issue_version
    IS
    SELECT
    issue_version_t (
    SHARE_OUTST_T (so.shr_outst_amt )
    , SECURITY_T ( s.vote_per_shr
    , s.sec_cusip
    , s.PRI_MKT_EXCH_CD
    , s.IV_TYPE_CD
    , s.SEC_TICKER_SYMB )
    , ALTERNATE_ID_T (a.ALT_ID_TYPE)
    , ISSUER_T (i.ISSR_ID )
    , ISSUE_MAINT_VERSION_T (imv.im_key_id
    , imv.im_ver_num
    , imv.eff_tmstmp
    , imv.exp_tmstmp
    , imv.next_review_tmstmp
    , imv.appr_status_ref_id
    , imv.vote
    , imv.add_usr_id
    , imv.add_tmstmp
    , imv.upd_usr_id
    , imv.upd_tmstmp
    , imv.lock_level_num
    , NULL )
    , ISSUE_SHARE_MAINT_T (ism.im_key_id
    , ism.im_ver_num
    , ism.shr_outst_amt
    , ism.curr_outst_amt
    , ism.add_usr_id
    , ism.add_tmstmp
    , ism.upd_usr_id
    , ism.upd_tmstmp
    , ism.lock_level_num
    , NULL)
    , ISSUE_MAINT_COMMENT_T(imc.im_key_id
    , imc.im_ver_num
    , imc.comment_txt
    , imc.add_usr_id
    , imc.add_tmstmp
    , imc.upd_usr_id
    , imc.upd_tmstmp
    , imc.lock_level_num
    , NULL )
    FROM
    share_outst so
    , security s
    , alternate_id a
    , issuer i
    , issue_maintenance_version imv
    , issue_share_maintenance ism
    , issue_maintenance_comment imc
    WHERE
    s.sec_key_id = so.SEC_KEY_ID
    and s.SEC_KEY_ID = a.SEC_KEY_ID
    and s.MSTR_ISSR_KEY_ID = i.ISSR_KEY_ID
    and s.SEC_CUSIP = imv.SEC_CUSIP (+)
    and s.SEC_CUSIP = ism.SEC_CUSIP (+)
    and imv.IM_KEY_ID = imc.IM_KEY_ID (+);
    BEGIN
    OPEN cur_issue_version ;
    FETCH cur_issue_version BULK COLLECT INTO pv_issue_version_col ;
    CLOSE cur_issue_version ;
    END ;
    PROCEDURE get_all_issue_col_v1
    ( pv_issue_version_col OUT NOCOPY issue_version_col_t
    , pv_row_count IN number
    , pv_issuer_id IN VARCHAR2
    AS
    CURSOR cur_issue_version
    IS
    SELECT
    issue_version_t (
    SHARE_OUTST_T (so.shr_outst_amt )
    , SECURITY_T ( s.vote_per_shr
    , s.sec_cusip
    , s.PRI_MKT_EXCH_CD
    , s.IV_TYPE_CD
    , s.SEC_TICKER_SYMB )
    , ALTERNATE_ID_T (a.ALT_ID_TYPE)
    , ISSUER_T (i.ISSR_ID )
    , ISSUE_MAINT_VERSION_T (imv.im_key_id
    , imv.im_ver_num
    , imv.eff_tmstmp
    , imv.exp_tmstmp
    , imv.next_review_tmstmp
    , imv.appr_status_ref_id
    , imv.vote
    , imv.add_usr_id
    , imv.add_tmstmp
    , imv.upd_usr_id
    , imv.upd_tmstmp
    , imv.lock_level_num
    , NULL )
    , ISSUE_SHARE_MAINT_T (ism.im_key_id
    , ism.im_ver_num
    , ism.shr_outst_amt
    , ism.curr_outst_amt
    , ism.add_usr_id
    , ism.add_tmstmp
    , ism.upd_usr_id
    , ism.upd_tmstmp
    , ism.lock_level_num
    , NULL)
    , ISSUE_MAINT_COMMENT_T(imc.im_key_id
    , imc.im_ver_num
    , imc.comment_txt
    , imc.add_usr_id
    , imc.add_tmstmp
    , imc.upd_usr_id
    , imc.upd_tmstmp
    , imc.lock_level_num
    , NULL )
    FROM
    share_outst so
    , security s
    , alternate_id a
    , issuer i
    , issue_maintenance_version imv
    , issue_share_maintenance ism
    , issue_maintenance_comment imc
    WHERE
    s.sec_key_id = so.SEC_KEY_ID
    and s.SEC_KEY_ID = a.SEC_KEY_ID
    and s.MSTR_ISSR_KEY_ID = i.ISSR_KEY_ID
    and s.SEC_CUSIP = imv.SEC_CUSIP (+)
    and s.SEC_CUSIP = ism.SEC_CUSIP (+)
    and imv.IM_KEY_ID = imc.IM_KEY_ID (+);
    BEGIN
    OPEN cur_issue_version ;
    FETCH cur_issue_version BULK COLLECT INTO pv_issue_version_col ;
    CLOSE cur_issue_version ;
    END ;
    ====================
    When I execute this stored procedure thru rapid sql, I get error
    Error: ORA-06550: line 1, column 21:
    PLS-00306: wrong number or types of arguments in call to 'GET_ALL_ISSUE_VERSION_COL'
    ORA-06550: line 1, column 21:
    PL/SQL: Statement ignored, Batch 1 Line 1 Col 21
    What is that I am missing?
    Any help would be greatly appreciated.

    I've never tried Rapid SQL, but my guess is that you can't pass objects through it. I'd write a test case on the server and try it there. It looks like it should work but I didn't build a test case. If it works on the server but not in the tool, it's like the tool. OCI8 doesn't support passing instantiated objects.

  • Problem when trying the Stored Procedures in JDBC receiver side

    Hi,
    I am facing some problem when i am trying to configure a scenario in the receiver side of JDBC adpater.
    We have never got stored procedures to work as messages go in 'Delivering'   status always. It's as if control never gets back to the adapter engine after the stored procedure call is made by the JDBC adapter. Then I went to checkt in the IE where the message has successfuly sent. Then I went to check
    in AE where the message is in "Delivering" state for long time.
    So checked the Default trace File and Thread dumps.
    In Thread dumps, i found a strange thing like one thread is hanging on condition wait at the below location :
      at java/lang/StringCoding.getEncoder(StringCoding.java:331(Compiled Code))
      at java/lang/StringCoding.encode(StringCoding.java:472(Compiled Code))
      at java/lang/String.getBytes(String.java:651(Compiled Code))
      at com/sap/aii/adapter/jdbc/SAXHandler.constructResponseStream(xml2sql.java:841(Compiled Code))
      at com/sap/aii/adapter/jdbc/SAXHandler.SQLcallStmt(xml2sql.java:988)
    Can you please help me in solving this issue as it is very critical to me ?
    Thanks,
    Prakash.

    Dear Prakash,
       There are number of reasons for SAX error. May be structure is not well defined, statement is not written correctly. These following links help you to solve your issue.
         SQL Queries(JDBC sendor CC)
         Oracle DB - XI - SQL DB
         JDBC Scenerio.
    Regards,
    JP.

  • Help required in executing the stored procedure and capturing the responce

    Hi,
    I have to execute a stored procedure in oracle database and if it successful then have to create a status IDOC.
    The stored procedure may throw an exception(it is not an out parameter), in such cases i should capture the exception as part of the response message and send this information while creating the status IDOC.
    i would like if the below is possible.
    As the stored procedure is not returning( this means if you execute the procedure manually it will display the result), will it be possible to capture the result which has the exception details?
    any direction to this will be highly appreciated.
    Many thanks.
    Regards,
    Rahul

    @Bhaskar,
    i need to execute the procedure by sending the input data from a file and capture the result after executing the procedure to create a status idoc
    im not sure how the provided links helps me here.
    i m not looking for any look ups. i would like to know is there any way that we can capture the result after executing the database procedure?
    Edited by: Rahul_10416 on Dec 5, 2011 10:07 PM

  • Error while executing the stored procedure

    Hi All,
    When I try to execute the store procedure .The store procedure does not have parameter. I am getting the following error. The store procedure has been successfully complied.
    Thanks for all your help.
    uday
    ORA-01422: exact fetch returns more than requested number of rows
    01422. 00000 - "exact fetch returns more than requested number of rows"
    *Cause:    The number specified in exact fetch is less than the rows returned.
    *Action:   Rewrite the query or change number of rows requested                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi All,
    Here is the store proc and version. I do not have much exposure to pl sql store proc .
    Thanks for all your support and help.
    uday
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE     11.2.0.3.0     Production"
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    Here is the store proc .
    create or replace
    PROCEDURE TEST AS
    R_REGION VARCHAR2(5);
    R_listing2rifs_count number;
    R_listing2rifs number;
    listing2iag_count number; /* mentioned already: rp0428 */
    listing2iag number;
    R_rod2iag_count number;
    R_rod2iagnumber;
    R_rod2ra_count number;
    R_rod2ra number;
    begin
    select Region,
    sum(listing2rifs_count) as listing2rifs_count,
    round((sum(listing2rifs) / sum(listing2rifs_count))/30.4,1) as listing2rifs,
    sum(listing2iag_count) as listing2iag_count,
    round((sum(listing2iag) / sum(listing2iag_count))/30.4,1) as listing2iag,
    sum(rod2iag_count) as rod2iag_count,
    round((sum(rod2iag) / sum(rod2iag_count))/30.4,1) as rod2iag,
    sum(rod2ra_count) as rod2ra_count,
    round((sum(rod2ra) / sum(rod2ra_count))/30.4,1) as rod2ra
    into R_REGION,R_listing2rifs_count,R_listing2rifs,listing2iag_count,listing2iag,
    R_rod2iag_count,R_rod2iag,R_rod2ra_count,R_rod2ra
    from (select site.FK_REF_REGION_CODE Region,
    site.site_id,
    site.EPA_ID,
    site.name site_name,
    FEDERAL_FACILITY_DETER_CODE,
    NPL_STATUS_CODE,
    site.BRAC_TYPE_NAME,
    sis.FT_FLAG,
    listing_action,
    rifs_action,
    iag_action,
    rod_action,
    ra_action,
    listing.ACTUAL_COMPLETION_DATE as listing_date,
    iag.ACTUAL_COMPLETION_DATE as iag_date,
    first_rifs.ACTUAL_START_DATE as first_rifs_start_date,
    first_rod.ACTUAL_COMPLETION_DATE as first_rod_date,
    ra_start.ACTUAL_START_DATE as first_ra_start_date,
    case when first_rifs.ACTUAL_START_DATE is not null
    and listing.ACTUAL_COMPLETION_DATE is not null
    then 1
    else 0
    end as listing2rifs_count,
    first_rifs.ACTUAL_START_DATE - listing.ACTUAL_COMPLETION_DATE as listing2rifs,
    case when first_rifs.ACTUAL_START_DATE is not null
    and listing.ACTUAL_COMPLETION_DATE is not null
    then 1
    else 0
    end as listing2iag_count,
    iag.ACTUAL_COMPLETION_DATE - listing.ACTUAL_COMPLETION_DATE as listing2iag,
    case when first_rifs.ACTUAL_START_DATE is not null
    and listing.ACTUAL_COMPLETION_DATE is not null
    then 1
    else 0
    end as rod2iag_count,
    iag.ACTUAL_COMPLETION_DATE - first_rod.ACTUAL_COMPLETION_DATE as rod2iag,
    case when first_rifs.ACTUAL_START_DATE is not null
    and listing.ACTUAL_COMPLETION_DATE is not null
    then 1
    else 0
    end as rod2ra_count,
    ra_start.ACTUAL_START_DATE - first_rod.ACTUAL_COMPLETION_DATE as rod2ra
    from site
    LEFT OUTER JOIN
    (select fk_site_id,
    SPECIAL_INITIATIVE_CODE as FT_FLAG
    from SPECIAL_INITIATIVE_SITE sppi
    where SPECIAL_INITIATIVE_CODE = 'FT'
    ) SIS
    ON site.site_id = sis.fk_site_id
    LEFT OUTER JOIN
    (select fk_site_id,
    TYPE_SEQUENCE_CODE as listing_action,
    ACTUAL_COMPLETION_DATE
    from action
    where TYPE_CODE = 'NF'
    and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
    and ACTUAL_COMPLETION_DATE is not null
    and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
    (SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
    from action b
    WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
    and b.TYPE_CODE = 'NF'
    and b.ACTUAL_COMPLETION_DATE is not null
    ) listing
    ON SITE.SITE_ID = LISTING.FK_site_id
    LEFT OUTER JOIN
    (select FK_site_id,
    TYPE_SEQUENCE_CODE as rifs_action,
    ACTUAL_START_DATE,
    ACTUAL_COMPLETION_DATE
    from action
    where TYPE_CODE in ('NH','LW') /*('RI','NA','NH','FS','NK','NI','CO','BD','LW') */
    and LEAD_CODE = 'FF'
    and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PS','PB','OA','OS','TN','TT'))
    and ACTUAL_START_DATE is not null
    and TO_CHAR(action.ACTUAL_START_DATE,'YYYYMMDD') || TYPE_SEQUENCE_CODE =
    (SELECT min(TO_CHAR(ACTUAL_START_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
    from action b
    WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
    and b.TYPE_CODE in ('NH','LW') /*('RI','NA','NH','FS','NK','NI','CO','BD','LW') */
    and b.ACTUAL_START_DATE is not null
    ) first_rifs
    ON site.site_id = first_rifs.FK_site_id
    LEFT OUTER JOIN
    (select FK_site_id,
    TYPE_SEQUENCE_CODE as iag_action,
    ACTUAL_COMPLETION_DATE
    from action
    where TYPE_CODE = 'FI'
    and action.LEAD_CODE = 'FE'
    and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
    and ACTUAL_COMPLETION_DATE is not null
    and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
    (SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
    from action b
    WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
    and b.TYPE_CODE = 'FI'
    and b.ACTUAL_COMPLETION_DATE is not null
    ) iag
    ON site.site_id = iag.FK_site_id
    LEFT OUTER JOIN
    (select FK_site_id,
    TYPE_SEQUENCE_CODE as rod_action,
    ACTUAL_COMPLETION_DATE
    from action
    where TYPE_CODE = 'RO'
    and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
    and ACTUAL_COMPLETION_DATE is not null
    and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
    (SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
    from action b
    WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
    and b.TYPE_CODE = 'RO'
    and b.ACTUAL_COMPLETION_DATE is not null
    ) first_rod
    ON site.site_id = first_rod.FK_site_id
    LEFT OUTER JOIN
    (select FK_site_id,
    TYPE_SEQUENCE_CODE as ra_action,
    ACTUAL_START_DATE
    from action
    where TYPE_CODE = 'LY'
    and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PS','PB','OA','OS','TN','TT'))
    and ACTUAL_START_DATE is not null
    and TO_CHAR(action.ACTUAL_START_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
    (SELECT min(TO_CHAR(ACTUAL_START_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
    from action b
    WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
    and b.TYPE_CODE = 'LY'
    and b.ACTUAL_START_DATE is not null
    ) ra_start
    ON site.site_id = ra_start.FK_site_id
    WHERE site.FEDERAL_FACILITY_DETER_CODE = 'Y'
    and site.NPL_STATUS_CODE in (/*'P',*/'F','D','A')
    ) durations
    group by Region
    order by 1;
    end;
    errors:
    ORA-01422: exact fetch returns more than requested number of rows
    01422. 00000 - "exact fetch returns more than requested number of rows"
    *Cause: The number specified in exact fetch is less than the rows returned.
    *Action: Rewrite the query or change number of rows requested                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem in invoking the stored procedure

    Hi,
    I am trying to invoke a stored procedure thru java jdbc. The SP works if I execute it directly.
    declare P_RECORDSET1 SYS_REFCURSOR := null;
    begin
    USER1.USER_DELEGATE_PKG.GET_ACCOUNTS (P_RECORDSET1,'APP',74908,null,'Y',null);
    end;
    In the java code, I do the following
    final String sql = "{CALL USER1.USER_DELEGATE_PKG.GET_ACCOUNTS(?,?,?,?,?,?)}"
    cstmt = conn.prepareCall(sql);
    cstmt.registerOutParameter(1, OracleTypes.CURSOR);
    cstmt.setString(2, "APP");
    cstmt.setInt(3, 74908);
    cstmt.setObject(4, null);
    cstmt.setString(5, "Y");
    cstmt.setObject(6, null);
    When I execute this query, I get the Invalid SQL exception. Not really able to make out whats wrong with this query...Any clues?
    Thanks

    Alright, now I am able to atleast invoke the SP, but getting the error
    Failed to execute GET_ACCOUNTS.Message is ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GET_ACCOUNTS'
    The procedure declaration is PROCEDURE get_accounts (
    param1 OUT T_CURSOR,
    param2 IN VARCHAR2,
    param3 IN NUMBER,
    param4 IN APP.KEY_ARRAY_T,
    param5 IN VARCHAR2,
    param6 IN APP.KEY_INT_ARRAY_T

  • Is it possible to execute a stored procedure using the JDBC adapter?

    Hi all,
    Can anybody confirm whether we can execute a stored procedure created in a database using the processing parameters of a JDBC adapter of a communication channel?
    If yes, then please let me know how (may be with an example)
    Thanks.

    Yes, that is possible. You have to chose EXECUTE in the action field to execute the stored procedure. Here's a little piece on the JDBC receiver:
    JDBC Receiver
    For writing data to an SQL database you also need to define a strict data type. The general format is like this:
        <ns:MT_RECORDSET>
              <STATEMENT>
                   <TABLE_NAME ACTION="">
                        <TABLE/>
                        <ACCESS>
                             <FIELD1/>
                             <FIELD2/>
                             <FIELDn/>
                        </ACCESS>
                        <KEY>
                             <ID compareOperation=""/>
                             <FIELDx compareOperation=""/>
                        </KEY>
                   </TABLE_NAME>
              </STATEMENT>
    </ns:MT_RECORDSET>
    This recordset represents an SQL statement like "update TABLE1 set FIELD1=123, FIELD2=456, FIELDn='xyz' where ID=12345 and FIELDx is NULL"
    MT_RECORDSET is the name of the Message Type used.
      For the value of the attribute ACTION you can choose from the following values:
         UPDATE : updates the given fields in the table with their new values
         INSERT : insert the given fields as a new row in the table
         UPDATE_INSERT : insert rows in the table when update is not possible
         DELETE : deletes given fields from the table
         SELECT : selects given fields from the table. Note that this option returns a response in the JDBC Sender form!
         EXECUTE : execution of a stored SQL procedure
         SQL_QUERY | SQL_DML : option to transfer more complex SQL statements to the database
      The attribute compareOperation can have the following values:
         EQ : equal
         NEQ : not equal
         LT : less than
         LTEQ : less than or equal to
         GT : greater than
         GTEQ : greater than or equal to
         LIKE : used to compare strings

  • 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

  • Incorrect Update Count by executing a stored procedure from Java

    Hi Guys,
    I am calling a stored procedure from the java program which is modifying the rows of a table. Now I want to know how many rows have been modified by executing the stored procedure. I am writing the following code for the purpose:
    OracleCallableStatement stmt =
    (oracle.jdbc.driver.OracleCallableStatement)con.prepareCall("{callsp_um_setForumID(?,?)}");
    stmt.setInt(1,101);
    stmt.setInt(2,666);
    n = stmt.executeUpdate();
    System.out.println(n + " row(s) updated");
    This procedure is actually modifying the table(When I query the databse it has modified 1 row). But it is returning a value 0 and is printing "0 row(s) updated".
    Is there a way by which I can find out the number of rows updated by executing the stored procedure?
    Thanks
    Sachin
    [email protected]

    I'm no expert on this, but I have a similar call where I fetch
    an Oracle REF CURSOR from a call to a stored function. If you
    fetch the cursor as an Object from your CallableStatement, you
    can then cast it to a ResultSet e.g.
    mystatement.executeUpdate();
    ResultSet rs = (ResultSet) mystatement.getObject(1);
    Then you should be able to loop through your ResultSet as usual.
    Good luck!
    Chris

  • Geeting TIMEOUT while executing a Stored Procedure.

    Hi Gurus,
    Am facing a TimeOut  issue while executing the Sql Stored Procedure.
    I have changed a settings of Execution TimeOut to Zero (which is unlimited ), Am still unable to execute the Stored Procedure.
    Should i have to add any TimeOut Command in my Sql Stored Procedure. If please suggest me.
    Thanks in advance.

    Time out is the client who throws the error  not SQL Server. Please read Erland's article
    http://www.sommarskog.se/query-plan-mysteries.html
    Are you sure there is blocking/locking? Is that possible someone run BEGIN TRAN and did not properly specify COMMIT TRAN?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How will be outbound data structure in sap xi after executing the stored pr

    Hi All
    can any one please tell me how will be outbound data structure in sap xi after executing the stored procedure by sender JDBC adapter?
    Thanks in advance
    regards
    Rams

    Hi..
    My stored procedure is select and it will be OUTBOUND in PI.
    is it will be same as following
    <resultset>
    <row>
    <column-name1>column-value</ column-name1>
    <column-name2></column-name2>
    <column-name3>column-value</ column-name3>
    <column-name4></column-name4>
    </row>
    <row>
    <column-name1>column-value</ column-name1>
    <column-name2></ column-name2>
    </row>
    </resultset>
    Regards
    Rams
    Edited by: Rameshkumar Varanganti on Oct 15, 2008 12:04 PM

  • Execute oracle stored procedure from C# always returns null

    Hi,
    I'm trying to execute a stored procedure on oracle 9i. I'm using .Net OracleClient provider.
    Apparently, I can execute the stored procedure, but it always returns null as a result (actually all the sp's I have there returns null)! I can execute any text statement against the database successfully, and also I can execute the stored procedure using Toad.
    This is not the first time for me to call an oracle stored procedure, but this really is giving me a hard time! Can anyone help please?
    Below are the SP, and the code used from .Net to call it, if that can help.
    Oracle SP:
    CREATE OR REPLACE PROCEDURE APIECARE.CHECK_EXISTENCE(l_number IN NUMBER) AS
    v_status VARCHAR2(5) := NULL;
    BEGIN
    BEGIN
    SELECT CHECK_NO_EXISTENCE(to_char(l_number))
    INTO v_status
    FROM DUAL;
    EXCEPTION WHEN OTHERS THEN
    v_status := NULL;
    END;
    DBMS_OUTPUT.PUT_LINE(v_status);
    END CHECK_CONTRNO_EXISTENCE;
    C# Code:
    string connStr = "Data Source=datasource;Persist Security Info=True;User ID=user;Password=pass;Unicode=True";
    OracleConnection conn = new OracleConnection(connStr);
    OracleParameter param1 = new OracleParameter();
    param1.ParameterName = "v_status";
    param1.OracleType = OracleType.VarChar;
    param1.Size = 5;
    param1.Direction = ParameterDirection.Input;
    OracleParameter param2 = new OracleParameter();
    param2.ParameterName = "l_number";
    param2.OracleType = OracleType.Number;
    param2.Direction = ParameterDirection.Input;
    param2.Value = 006550249;
    OracleParameter[] oraParams = new OracleParameter[] { param1, param2 };
    OracleCommand cmd = new OracleCommand("CHECK_EXISTENCE", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddRange(oraParams);
    conn.Open();
    object result = cmd.ExecuteScalar();
    conn.Close();

    Hi,
    Does that actually execute? You're passing two parameters to a procedure that only takews 1 and get no error?
    Your stored procedure doesnt return anything and has no output parameters, what are you expecting to be returned exactly?
    If you're trying to access V_STATUS you'll need to declare that as either an output parameter of the procedure, or return value of the function, and also access it via accessing Param.Value, not as the result of ExecuteScalar.
    See if this helps.
    Cheers,
    Greg
    create or replace function myfunc(myinvar in varchar2, myoutvar out varchar2) return varchar2
    is
    retval varchar2(50);
    begin
    myoutvar := myinvar;
    retval := 'the return value';
    return retval;
    end;
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    public class odpfuncparams
         public static void Main()
          OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
          con.Open();
          OracleCommand cmd = new OracleCommand("myfunc", con);
          cmd.CommandType = CommandType.StoredProcedure;
          OracleParameter retval = new OracleParameter("retval",OracleDbType.Varchar2,50);
          retval.Direction = ParameterDirection.ReturnValue;
          cmd.Parameters.Add(retval);
          OracleParameter inval = new OracleParameter("inval",OracleDbType.Varchar2);
          inval.Direction = ParameterDirection.Input; 
          inval.Value="hello world";
          cmd.Parameters.Add(inval);
          OracleParameter outval = new OracleParameter("outval",OracleDbType.Varchar2,50);
          outval.Direction = ParameterDirection.Output;
          cmd.Parameters.Add(outval);
          cmd.ExecuteNonQuery();
          Console.WriteLine("return value is {0}, out value is {1}",retval.Value,outval.Value);
          con.Close();
    }

  • Problem in OUT Parameter in the stored procedure

    Hi,
    I have a problem in the OUT parameter of the stored procedure under the package. I encountered the error PLS-00306. Below are the codes.
    Package
    CREATE OR REPLACE package body test as
         procedure sp_countries(rst OUT country_typ) as
         sql_stmt VARCHAR2(300);
         begin
         sql_stmt := 'SELECT * FROM countries WHERE region_id = 1';
         OPEN rst FOR sql_stmt;     
         end;
    end test;
    by the way. i declared the country_typ as this:
    TYPE country_typ IS REF CURSOR;
    Here is the code that will call this package:
    declare
    tst countries%ROWTYPE;
    begin
    test.sp_countries(tst);
    dbms_output.put_line(tst.country_name);
    end;

    Works for me. Although I had to use emp instead of your table:
    SQL> create or replace
      2  package test as
      3     TYPE country_typ IS REF CURSOR;
      4     procedure sp_countries(rst OUT country_typ);
      5  end;
      6  /
    Package created.
    SQL> CREATE OR REPLACE
      2  package body test as
      3     procedure sp_countries(rst OUT country_typ) as
      4        sql_stmt VARCHAR2(300);
      5     begin
      6        sql_stmt := 'SELECT * FROM emp WHERE deptno = 20';
      7        OPEN rst FOR sql_stmt;
      8     end;
      9  end test;
    10  /
    Package body created.
    SQL> var tcur refcursor
    SQL> exec test.sp_countries(:tcur);
    PL/SQL procedure successfully completed.
    SQL> print tcur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    SQL>

Maybe you are looking for