OPEN lcur_trade_cursor FOR select Syntax

HI I am new to cursors .i am seeing this code in my package .any help what the code in block will do?what for this is defined ?
or can u please explain the behaviour of this cursor meaning the data how populated?
I would like to understand especially this block in square brackets
[rec
                    WHERE      rec.par_amt <> rec.fa_trade_quantity OR
          rec.original_face_amt <> rec.fa_original_face_amt OR
          ( rec.current_trade_status_cd = 'EX' AND rec.fa_trade_status_cd <> '12' OR
          (rec.current_trade_status_cd = 'SAVED' AND (rec.sent_to_downstream = 'N' or rec.sent_to_downstream IS NULL)
                    AND rec.fa_trade_status_cd <> '11') OR
          ((rec.current_trade_status_cd = 'PN' AND rec.sent_to_downstream = 'Y') AND rec.fa_trade_status_cd <> '11') OR
          rec.current_trade_status_cd = 'TR' AND rec.fa_trade_status_cd <> '12');]
OPEN lcur_trade_cursor FOR
                    SELECT pv_cycle_date_i,
                    FI_S2O_TRD_DIFF_SEQ.NEXTVAL,
                    rec.trade_effective_dt AS fide_trd_eff_dt,
                    rec.pot_trade_id AS pot_trade_id,
                    rec.fa_trade_id AS fide_trade_id,
                    rec.transaction_alternate_id AS transaction_alternate_id,
                    rec.fi_instrument_id AS fi_instrument_id,
                    rec.portfolio_id AS portfolio_id,
                    'Trades in FIDE and UDE but difference in Par Amount or Original Face Value or Trade Status',
                    rec.par_amt AS ude_par_amt,
                    rec.original_face_amt AS ude_original_face_amt,
                    rec.fa_trade_quantity AS fide_par_amt,
rec.fa_original_face_amt AS fide_original_face_amt,
                    rec.txn_source_system_cd AS fide_source_system,
                    rec.trade_src_cd AS ude_source_system,
                    rec.settlement_dt AS settlement_dt,
                    pv_recon_type_i,
                    SYSTIMESTAMP,
               USER,
               SYSTIMESTAMP,
               USER,
                    SYSTIMESTAMP
                    FROM (
                         SELECT
                         trd.trade_effective_dt ,
                         trd.transaction_alternate_id ,
          ude.pot_trade_id ,
          trd.fa_trade_id ,
          trd.fi_instrument_id ,
          trd.portfolio_id ,
                         trd.fa_trade_quantity          ,
                         trd.fa_original_face_amt          ,
                         ude.par_amt ,
                         ude.original_face_amt ,
                         trd.txn_source_system_cd ,
                         ude.trade_src_cd ,
                         trd.settlement_dt ,
                         ude.current_trade_status_cd ,
                         trd.fa_trade_status_cd ,
                         trd.sent_to_downstream
                    FROM FUND_TRADE_V trd,
                              STG_SYB_TRADES ude,
                              FI_FUND_SUBPORTFOLIO sub,
                              INSTRUMENT_ALTERNATE_ID ia
                    WHERE trd.trade_effective_dt >= pv_cycle_date_i
                    AND ude.trade_effective_dt >= pv_cycle_date_i
                    AND trd.transaction_alternate_id = ude.trade_sequence_nbr
                    AND ude.trade_effective_dt = trd.trade_effective_dt
                    AND ude.recon_type = pv_recon_type_i
                    AND trd.portfolio_id = sub.portfolio_id
                    AND ude.fund_nbr = sub.fund_nbr
                    AND ude.subportfolio_nbr = sub.subportfolio_nbr
                    AND trd.fi_instrument_id = ia.fi_instrument_id
                    AND ia.alternate_id_type_code ='FMR_CUSIP'
                    AND ude.fmr_cusip = ia.alternate_id
                    AND EXISTS
          ( SELECT 1
          FROM HLDGS_RECON_TAXBD_GRP_FUND_MV mm,
                                        FUND fnd
          WHERE mm.parent_grp = 'OMS_FUND'
          AND mm.member_grp = 'MM_FUND'
          AND mm.fund_nbr = ude.fund_nbr
                              AND mm.fund_nbr     = fnd.fund_nbr
                              AND fnd.fund_ending_dt IS NULL
               ) rec
                    WHERE      rec.par_amt <> rec.fa_trade_quantity OR
          rec.original_face_amt <> rec.fa_original_face_amt OR
          ( rec.current_trade_status_cd = 'EX' AND rec.fa_trade_status_cd <> '12' OR
          (rec.current_trade_status_cd = 'SAVED' AND (rec.sent_to_downstream = 'N' or rec.sent_to_downstream IS NULL)
                    AND rec.fa_trade_status_cd <> '11') OR
          ((rec.current_trade_status_cd = 'PN' AND rec.sent_to_downstream = 'Y') AND rec.fa_trade_status_cd <> '11') OR
          rec.current_trade_status_cd = 'TR' AND rec.fa_trade_status_cd <> '12');
Edited by: 945400 on Aug 23, 2012 3:24 AM

This is one of those situations where if you formatted the code for readability the answer falls right out.
OPEN lcur_trade_cursor FOR
SELECT pv_cycle_date_i,
       FI_S2O_TRD_DIFF_SEQ.NEXTVAL,
       rec.trade_effective_dt AS fide_trd_eff_dt,
       rec.pot_trade_id AS pot_trade_id,
       rec.fa_trade_id AS fide_trade_id,
       rec.transaction_alternate_id AS transaction_alternate_id,
       rec.fi_instrument_id AS fi_instrument_id,
       rec.portfolio_id AS portfolio_id,
       'Trades in FIDE and UDE but difference in Par Amount or Original Face Value or Trade Status',
       rec.par_amt AS ude_par_amt,
       rec.original_face_amt AS ude_original_face_amt,
       rec.fa_trade_quantity AS fide_par_amt,
       rec.fa_original_face_amt AS fide_original_face_amt,
       rec.txn_source_system_cd AS fide_source_system,
       rec.trade_src_cd AS ude_source_system,
       rec.settlement_dt AS settlement_dt,
       pv_recon_type_i,
       SYSTIMESTAMP,
       USER,
       SYSTIMESTAMP,
       USER,
       SYSTIMESTAMP
  FROM (SELECT trd.trade_effective_dt,
               trd.transaction_alternate_id,
               ude.pot_trade_id,
               trd.fa_trade_id,
               trd.fi_instrument_id,
               trd.portfolio_id,
               trd.fa_trade_quantity,
               trd.fa_original_face_amt,
               ude.par_amt,
               ude.original_face_amt,
               trd.txn_source_system_cd,
               ude.trade_src_cd,
               trd.settlement_dt,
               ude.current_trade_status_cd,
               trd.fa_trade_status_cd,
               trd.sent_to_downstream
          FROM FUND_TRADE_V trd,
               STG_SYB_TRADES ude,
               FI_FUND_SUBPORTFOLIO sub,
               INSTRUMENT_ALTERNATE_ID ia
         WHERE     trd.trade_effective_dt >= pv_cycle_date_i
               AND ude.trade_effective_dt >= pv_cycle_date_i
               AND trd.transaction_alternate_id = ude.trade_sequence_nbr
               AND ude.trade_effective_dt = trd.trade_effective_dt
               AND ude.recon_type = pv_recon_type_i
               AND trd.portfolio_id = sub.portfolio_id
               AND ude.fund_nbr = sub.fund_nbr
               AND ude.subportfolio_nbr = sub.subportfolio_nbr
               AND trd.fi_instrument_id = ia.fi_instrument_id
               AND ia.alternate_id_type_code = 'FMR_CUSIP'
               AND ude.fmr_cusip = ia.alternate_id
               AND EXISTS
                      (SELECT 1
                         FROM HLDGS_RECON_TAXBD_GRP_FUND_MV mm, FUND fnd
                        WHERE     mm.parent_grp = 'OMS_FUND'
                              AND mm.member_grp = 'MM_FUND'
                              AND mm.fund_nbr = ude.fund_nbr
                              AND mm.fund_nbr = fnd.fund_nbr
                              AND fnd.fund_ending_dt IS NULL)) rec
WHERE    rec.par_amt != rec.fa_trade_quantity
       OR rec.original_face_amt != rec.fa_original_face_amt
       OR (       rec.current_trade_status_cd = 'EX'
              AND rec.fa_trade_status_cd != '12'
           OR (    rec.current_trade_status_cd = 'SAVED'
               AND (   rec.sent_to_downstream = 'N'
                    OR rec.sent_to_downstream IS NULL)
               AND rec.fa_trade_status_cd != '11')
           OR (    (    rec.current_trade_status_cd = 'PN'
                    AND rec.sent_to_downstream = 'Y')
               AND rec.fa_trade_status_cd != '11')
           OR     rec.current_trade_status_cd = 'TR'
              AND rec.fa_trade_status_cd != '12');'rec' is an alias for a query defined in the FROM clause.

Similar Messages

  • Open sys_refcursor for select from table variable?

    Hi,
    I've got a challenge for you! :-)
    I've got a procedure that has a lot of logic to determine what data should be loaded into a table variable. Because of various application constraints, i can not create a global temporary table. Instead, i'd like to create a table variable and populate it with stuff as i go through the procedure.
    The end result of the procedure is that i must be able to pass the results back as a sys_refcursor. This is a requirement that is beyond my control as well.
    Is there a way to make this sort of procedure work?
    Create Or Replace Procedure Xtst
    Mu_Cur In Out Sys_Refcursor
    Is
    Type Xdmlrectype Is Record (Col1 Varchar2(66));
    Type Xdmltype Is Table Of Xdmlrectype;
    Rtn Xdmltype;
    Begin
    Select Internal_Id Bulk Collect Into Rtn From Zc_State;
    open mu_cur for select col1 from table(rtn);
    end;
    11/42 PLS-00642: local collection types not allowed in SQL statements
    11/36 PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    11/19 PL/SQL: SQL Statement ignored
    Show Errors;

    Not anything i'd want to personally implement.
    But for educational purposes only of course....
    create table this_will_be_gross
       column1 number,
       column2 varchar2(30)
    insert into this_will_be_gross values (1, 'begin the ugliness');
    insert into this_will_be_gross values (2, 'end the ugliness');
    variable x refcursor;
    ME_XE?
    declare
       Rtn sys.ODCIVARCHAR2LIST;
    BEGIN
       SELECT
          column1 || '-' || column2 Bulk Collect
       INTO
          Rtn
       FROM
          this_will_be_gross;
       OPEN :x FOR
       SELECT 
          regexp_substr (column_value, '[^-]+', 1, 1) as column1,
          regexp_substr (column_value, '[^-]+', 1, 2) as column2      
       FROM TABLE(CAST(rtn AS sys.ODCIVARCHAR2LIST));
    end;
    17  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.09
    ME_XE?
    ME_XE?print :x
    COLUMN1                        COLUMN2
    1                              begin the ugliness
    2                              end the ugliness
    2 rows selected.
    Elapsed: 00:00:00.11In the above example i 'knew' that a hypen was a safe character to use to break up my data elements (as it would not be found anywhere in the data itself).
    I would strongly encourage you not to implement something like this. I realize it's tempting when you are working in strict environments where it can take a serious battle to get structures like temporary tables or SQL Types created, but that's really the proper approach to be taking.

  • Problem with OPEN My_Cursor FOR SELECT ...

    Please, I need some help here. I'm developing an ASP NET application with Crystal Reports and Oracle 9i as DB.
    I'm desining a report. I use a Stored Procedure (in a package). I know that in order to CR be able to read the stored procedure, I have to use Cursor in this way: OPEN My_Cursor FOR SELECT * FROM My_Table;
    The problem is that I need to do other sub-queries to get the names of 3 people (from TBL_TWO) and show them in my Cursor (from TBL_ONE). How can I do it? I tried as my example, but I get error when try to connect from ASP NET: "ORA-24338 statement handle not executed"
    Apparantly, CR needs to read just only OPEN My_Cursor FOR ... Is there any way to resolve this problem?
    PROCEDURE SP_REP_OP_03 (My_CURSOR OUT MY_REF_CURSOR,
    i_Cod_OP IN INTEGER)
    IS
    v_id_1 char(8);
    v_Names_1 varchar(25);
    v_id_2 char(8);
    v_Names_2 varchar(25);
    v_id_3 char(8);
    v_Names_3 varchar(25);
    BEGIN
    SELECT TWO.Id, PER1.Names -- may or may not exist
    INTO v_id_1, v_Names_1
    FROM TBL_TWO TWO, PADRON.PADRON PER1
    WHERE TWO.Cod_OP = i_cod_op AND
    TWO.Cod_Rep = '01' AND
    TWO.Id = PER1.Id;
    IF v_id_1 IS NULL THEN
    v_id_1:= '';
    v_Names_1:= '';
    END IF;
    SELECT TWO.Id, PER1.Names -- may or may not exist
    INTO v_id_2, v_Names_2
    FROM TBL_TWO TWO, PADRON.PADRON PER1
    WHERE TWO.Cod_OP = i_cod_op AND
    TWO.Cod_Rep = '02' AND
    TWO.Id = PER1.Id;
    IF v_id_2 IS NULL THEN
    v_id_2:= '';
    v_Names_2:= '';
    END IF;
    SELECT TWO.Id, PER1.Names -- may or may not exist
    INTO v_id_3, v_Names_3
    FROM TBL_TWO TWO, PADRON.PADRON PER1
    WHERE TWO.Cod_OP = i_cod_op AND
    TWO.Cod_Rep = '03' AND
    TWO.Id = PER1.Id;
    IF v_id_3 IS NULL THEN
    v_id_3:= '';
    v_Names_3:= '';
    END IF;
    -- I tried to "attach" v_id and v_Names to My_Cursor, but CR can't get it
    OPEN My_CURSOR FOR
    SELECT ONE.Cod_Exp AS Cod_Exp,
    ONE.Cod_Exp_OP AS Cod_Exp_OP,
    ONE.Cod_OP AS Cod_OP,
    ONE.cod_ficha AS cod_ficha,
    v_id_1 As id_1 ,
    v_Names_1 As Names_1,
    v_id_2 As id_2 ,
    v_Names_2 As Names_2,
    v_id_3 As id_3 ,
    v_Names_3 As Names_3,
    FROM TBL_ONE ONE
    WHERE OP.Cod_op = i_Cod_op;
    END SP_REP_OP_03;

    Why can't you just have a single SQL query that outer-joins the tables and returns the values you need? It looks like it should start in TBL_ONE and outer-join three times to TBL_TWO and PADRON, perhaps something like:
    SELECT one.cod_exp
         , one.cod_exp_op
         , one.cod_op
         , one.cod_ficha
         , id1.id AS id_1
         , per1.names AS names_1
         , id2.id AS id_2
         , per2.names AS names_2
         , id3.id AS id_3
         , per3.names AS names_3
    FROM   tbl_one one
         , tbl_two id1
         , padron.padron per1
         , tbl_two id2
         , padron.padron per2
         , tbl_two id3
         , padron.padron per3
    WHERE  one.cod_op = i_cod_op
    AND    id1.cod_op (+)= one.cod_op
    AND    id1.cod_rep (+)= '01'
    AND    per1.id (+)= id1.id
    AND    id2.cod_op (+)= one.cod_op
    AND    id2.cod_rep (+)= '02'
    AND    per2.id (+)= id2.id
    AND    id3.cod_op (+)= one.cod_op
    AND    id3.cod_rep (+)= '03'
    AND    per3.id (+)= id3.id;

  • OPEN out_cur FOR        SELECT  exception handling help

    Here is the stored procedure for reading a data based on the input, if no data then return null ref cursor and proper error message.
    I am not sure, i am handling proper exception handling ? Please help me to complete this item.
    Thanks.
    PROCEDURE testing
    module IN VARCHAR2,
    module_id IN VARCHAR2,
    out_cur OUT SYS_REFCURSOR,
    out_error_no OUT NUMBER
    BEGIN
    out_error_no := 0;
    CASE
    WHEN module = 'a' AND module_id = 'b' THEN
    BEGIN
    OPEN out_cur FOR
    SELECT id,
    mime_type,
    file_length,
    file_name ,
    uploadeddate,
    created_user ,
    status_name
    FROM l_table_cnt
    WHERE id = module_id;
    EXCEPTION
    WHEN OTHERS THEN
    OPEN out_cur_file_cursor FOR
    SELECT
    NULL id,
    NULL mime_type,
    NULL file_length,
    NULL file_name,
    NULL uploadeddate,
    NULL created_user,
    NULL status_name
    FROM dual
    WHERE 1= 0;
    out_error_no := 2;
    RAISE_APPLICATION_ERROR(-20024,'No Document ');
    END;

    Venkadesh wrote:
    The correct way is to just open the ref cursor and pass it back and then the receiving code that is going to use that cursor handles whether there is any code in it or not. can you please explain with simple exampleIs it really that difficult?
    Ok...
    Here's the procedure to return a ref cursor...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure get_rc(p_deptno in number, p_rc out sys_refcursor) is
      2  begin
      3    open p_rc for 'select * from emp where deptno = :1' using p_deptno;
      4* end;
    SQL> /
    Procedure created.Now we have some application that wants to consume a ref cursor... in this case the application is SQL*Plus, but it could be Java or .NET etc.
    It declares it's local reference to the ref cursor...
    SQL> var r refcursor;then calls the procedure to get a ref cursor reference assigned...
    SQL> exec get_rc(10, :r);
    PL/SQL procedure successfully completed.Now, the application itself determines if there is any data when it comes to actually perform the fetches on it...
    SQL> print r;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10in the above case it had data, so it displayed it.
    So what if there isn't any data...
    SQL> exec get_rc(90, :r);
    PL/SQL procedure successfully completed.
    SQL> print r;
    no rows selected
    SQL>SQL*Plus (the application that calls the procedure) is the one that has determined that there was not data when it came to fetch it (using the print statement in this case). And when it found there was no data it handled it itself (in this case printing the message "no rows returned").
    The procedure doesn't have to do any overhead of determining if there is data going to be returned or not, because it's not it's responsibility and completely unnecessary. The calling application can easily determine if there is data or not when it starts to try and fetch it.

  • Report for CRM-Opportunities - Open CRMD_ORDER for selected ALV row

    Hello,
    i created a report which can be used to find the relevant opportunities and list them in a ALV table.
    I have the requirement that by doubleclick on the table line the selected opportunity shall open in tx crmd_order.
    I have the GUID and the object_id of the opportunity in my ALV tableline.
    Has anybody already experience how to achieve this?
    Thank you
    Best regards
    Manfred

    It works perfectly for me. Look at the code (this works)
    REPORT ytestfhe3.
    DATA: gv_1o_manag    TYPE REF TO cl_crm_1o_manag,
          gv_1o_main     TYPE REF TO cl_crm_1o_main.
    DATA: gv_dynnr       TYPE sydynnr.
    DATA: gv_1o_frame_pa TYPE crmt_1o_frame_pa.
    DATA: gv_guid        TYPE crmt_object_guid.
    DATA: gv_boolean     TYPE crmt_boolean VALUE 'X'.
    PARAMETERS: p_order TYPE crmd_orderadm_h-object_id.
    START-OF-SELECTION.
      SELECT SINGLE guid FROM crmd_orderadm_h
                         INTO gv_guid
                        WHERE object_id EQ p_order.
    END-OF-SELECTION.
      gv_1o_frame_pa-transaction_guid = gv_guid.
      CREATE OBJECT gv_1o_manag
        EXPORTING
          iv_with_navig  = gv_boolean
          iv_1o_frame_pa = gv_1o_frame_pa.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
      CALL METHOD gv_1o_manag->get_main_screen
        IMPORTING
          ev_dynnr = gv_dynnr.
      CALL FUNCTION 'CRM_1O_MANAG_CALL_SCREEN_UI'
        EXPORTING
          iv_dynnr       = gv_dynnr
          iv_1o_frame_pa = gv_1o_frame_pa.

  • Open cursor for string and select from partition (cannot bind)

    Hi,
    i don't manage to use a bind variable for a select ... from ... PARTITION(...).
    It doesn't work to use something like
    open cur for 'select ... from ... PARTITION(:1) where ...' using 'NDAY_20120301';So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    Doesn't that prevent from re-use in library_cache?
    best regards,
    Frank

    >
    So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    >
    Yes it does.
    Doesn't that prevent from re-use in library_cache?
    >
    Yes it does.
    So why do you care? Unless you have large numbers of partitions what difference does it make? Bind variables are useful to keep Oracle from doing hard parses of queries that are basically the same but use different filter values. Such as an INSERT statement that uses different values FOR EACH ROW rather
    You are just constructing the main (non-filter) part of the query one time and need a single value for the entire query regardless of how many rows - that isn't really a use case for bind variables and isn't going to provide any real benefit.
    So the real question is why do you even care about something that wouldn't provide any benefit to you even if you could do it?
    Looks like you just want to 'roll your own' parallel processing rather that use, and pay for, Oracle's parallel functionality.
    If each partition uses its own tablespace you could filter on the FILE Id of the ROWIDs since the file number will be different for each tablespace and datafile.
    1. Determine the list of file numbers for each partitions tablespace.
    2. Use a WHERE DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) = :n filter (or use IN (:n1, :n2))to filter rows based on file number(s) for the partition you want
    See DBMS_ROWID.ROWID_RELATIVE_FNO in the PL/SQL Packages and Types doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_rowid.htm#i1004259

  • OPEN ....... FOR 'SELECT...........with references to string var

    I am having a problem refencing a string variable within the WHERE clause of an OPEN statement, where DATASET is a ref cursor and the string variables are defined below. Sorry if too much detail below.
    Thank you for any help,
    Scott
    Error msg = ORA-00904: invalid column name
    strInvCountTableName := 'cats_invcount' || to_char(sysdate, 'MMDDYYHH24MISS');
    strUsageTableName := 'cats_partusage'|| to_char(sysdate, 'MMDDYYHH24MISS');
    strCSSLType := 'S';
    strPDType := 'P';
    strVanType := 'V';
    strMCDCType := 'M';
    strSpareStatus := 'S';
    strAvailableStatus := 'A';
    OPEN dataset FOR 'SELECT
    Inv.PARTID, Inv.LOCATIONDETAILID,Inv.Total,Inv.Average,
    Part.PARTCODE,Part.MFGPARTNUMBER,Part.MANUFACTURER,Part.DESCRIPTION,
    (Usg.USAGECOUNT/Inv.Average) TURN,Usg.USAGECOUNT,Usg.USAGECODE,
    Ldel.LOCATIONDETAILCODE,
    Loc.NAME LOCATIONNAME,Loc.REGION,Loc.MTA
    FROM ' || <<this
    strInvCountTableName || ' Inv,' || <<works
    strUsageTableName || ' Usg, <<fine
    CATS_PART PART,
    CATS_LOCATIONDETAIL LDEL,
    CATS_LOCATION LOC,
    CATS_LOCATIONSTATUS STAT,
    CATS_LOCATIONTYPE TYP
    WHERE
    Inv.PARTID = Usg.PARTID AND
    Inv.LOCATIONDETAILID = Usg.LOCATIONDETAILID AND
    Inv.PARTID = Part.PARTID AND
    Inv.LOCATIONDETAILID = Ldel.LOCATIONDETAILID AND
    Ldel.LOCATIONID = Loc.LOCATIONID AND
    Ldel.LOCATIONSTATUSID = STAT.LOCATIONSTATUSID AND
    Loc.LOCATIONTYPEID = TYP.LOCATIONTYPEID AND
    (STAT.CODECOMPONENT = ' || strSpareStatus || ' AND << this does not work
         (TYP.CODECOMPONENT = ' || strCSSLType || ' OR <<
    TYP.CODECOMPONENT = ' || strPDType || ' OR << i've tried putting literals in " "
    TYP.CODECOMPONENT = ' || strVanType || ') OR << but still no luck
    (STAT.CODECOMPONENT = ' || strAvailableStatus || ' AND <<
         TYP.CODECOMPONENT = ' || strMCDCType || '))'; <<

    This is just the 'double single quote' problem. Just add two single quotes around the reference - these two quotes will resolve to a single quote:
    (STAT.CODECOMPONENT = ''' || strSpareStatus || ''' ANDor
    (STAT.CODECOMPONENT = ''S'' AND

  • Open cursor for existing procedure

    Is it possible to open a refcursor for an existing procedure as apposed to opening a refcursor for a standard select statement. For example:
    Standard select:
    OPEN refcursor FOR
    select * from my_table;
    RETURN the_cursor;
    Based on an existing procedure:
    OPEN refcursor FOR
    my_package.my_procedure();
    RETURN the_cursor;
    Note: my_procedure returns a table of record type rows defined by myself in the package spec.
    Any help is much appreciated
    Regards
    Tony

    Hi Sven
    Thank you for that information however I am still a little unsure as to how to call the procedure including the necessary parameters. The procedure in question has the following IN parameters with one OUT parameter.
    my_procedure (p_context_id in number,
    p_username in varchar2,
    p_mdata out mtab)
    As you stated, if it is a procedure, which it is, then use the following:
    my_package.my_procedure(the_cursor);
    However if I need to pass parameters in the call that kind of conflicts where 'the_cursor' is?
    Any ideas?
    Tony

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

  • Open cursor for a nested table

    Hi,
    I want to open a cursor like:
    open c1 for select * from emp;
    BUT
    I what the cursor results to be populated with contents of a nested table or associative array..
    How can this be done???
    Thanks in advance,
    teo

    Well, given a variable YOUR_EMP of nested table type EMP_NT it could be as simple as
    open c1 for select * from TABLE( CAST(your_emp AS emp_nt));Cheers, APC

  • Open SYS_REFCURSOR for DYNAMIC SQL

    Hi!
    I have stored procedure like below:
    CREATE OR REPLACE
    PROCEDURE MYPROCEDURE
    cv_r OUT SYS_REFCURSOR
    AS
    lv_ExecuteString varchar(2000);
    BEGIN
      lv_ExecuteString := 'select 1 from dual';
      open cv_r for lv_ExecuteString;
      END MYPROCEDURE;and then
    SQL> var y refcursor
    SQL> execute myprocedure(:y);
    BEGIN myprocedure(:y); END;
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "BPATEL.MYPROCEDURE", line 9
    ORA-06512: at line 1shouldnt it suppose to work??? If not then How can I fill up OUT SYS_REFCURSOR with dynamic sql string ???
    although If I modify this below in my stored procedure it works fine:
    -- open cv_r for lv_ExecuteString;
    open cv_r for select 1 from dual;
    SQL> var y refcursor
    SQL> execute myprocedure(:y);
    PL/SQL procedure successfully completed.
    SQL> print y
             1
             1any idea?? why is it doing so???

    What version are you on? Works fine for me....
    ME_XE?CREATE OR REPLACE
      2  PROCEDURE MYPROCEDURE
      3  (
      4  cv_r OUT SYS_REFCURSOR
      5  )
      6  AS
      7  lv_ExecuteString varchar(2000);
      8  BEGIN
      9    lv_ExecuteString := 'select 1 from dual';
    10    open cv_r for lv_ExecuteString;
    11    END MYPROCEDURE;
    12  /
    Procedure created.
    Elapsed: 00:00:00.71
    ME_XE?var y refcursor
    ME_XE?execute myprocedure(:y);
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.03
    ME_XE?print :y
                     1
                     1
    1 row selected.
    Elapsed: 00:00:00.00
    ME_XE?@version
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    5 rows selected.
    Elapsed: 00:00:00.10

  • How to get the opening balances for lessthan selected date in cubes.

    Hi All,
    my task is to get the opening balances for the selected date.
    Ex: If I select date say 31-1-2013, I should get the sum of values which are less than the selected date.
    in sql:
    select sum(balance) from banktrans where banktrans.transdate < 31-1-2013;
    BankTable                            BankTrans
    BankId                               BankId
                                            balance
                                            transdate
    BankTable (records):
    SCB
    BankTrans(records):
    a) SCB, 15000, 10-02-2013
    b) SCB, 20000, 31-01-2014
    c) SCB, 50000, 21-09-2012
    If I select date as 31-01-2014, I should get the value as 65000 
    If I select date as 10-02-2013, I should get the value as 50000
    Date will be dynamic selection from years months days hirearchy ( time dimension)
    How can i achieve this?  
    any help is much appreciated.
    Thanks,
    Rakesh

    Dear David,
    I've tried the below with static date but i'm not getting the values which are sum of less than the given date.
    I've given 1st jan 2013 as static date and I need to get the sum of values which are less than the 1st jan date.
    CREATE
    MEMBER
    CURRENTCUBE.[Measures].[OPENBALANCE]
    AS
    Sum({Null:[Time].[Years
    Quarters Months Weeks Days].[Days].&[2013-01-01T00:00:00]},[Measures].[AmountCur]]),
    FORMAT_STRING
    = "Standard",
    VISIBLE
    = 1
    can you plz check the above once and guide me.
    Thankyou,
    Rakesh

  • Selection of open item for payment

    Hi
    I understand that in the automatic payment program, the selection of the open items for payment is partly determined by the "documents entered up to date" and the "Next payment" run date. Would like to confirm if the posting date specified will affect the open items selected.
    I have a vendor with 3 open items - 2 invoices and 1 credit memo. The payment date for all 3 documents are 13.9.2007.
    Only the 2 invoices were selected for payment when I specify
    Posting date : 12.9.2007
    Doc entered up till and next payment date : 14.9.2007
    Only when we change the posting date to a later date was the credit memo selected as well. Why is this so?
    Hope someone could advise me on this.
    Thank you.

    Hi
    Thanks for responding.
                           Baseline date               Payment terms
    Invoice                14.08.2007                14 days
    Credit memo       13.09.2007                 -
    Regards.

  • My mum has an iPad 1, the email programme will not open properly.  If you click on the icon it opens only for a few seconds but then shuts.  In that few seconds you cant select anything that you see on screen.  Any ideas? Thanks

    My mum has an iPad 1, the email programme will not open properly.  If you click on the icon it opens only for a few seconds but then shuts.  In that few seconds you cant select anything that you see on screen.  Any ideas? Thanks

    If the Reset Ian mentioned doesn't work...
    Shut down and restart the Mail app...
    - From any Home Screen, double tap the home button to bring up the Recents List
    - Tap and hold any icon in this list until they wiggle
    - Press the red to delete the Mail app from this list.
    - Press the home button twice when done.
    - Restart the Mail app

  • SELECT DISTINCT With OPEN cursor FOR

    Hello.
    I have the following procedure. All it does is open a cursor for an SQL string passed into it, and return the open cursor.
    PROCEDURE sp_execute_dynamic (hold_input_string IN CLOB,
    hold_cursor OUT hold_cursor_type) IS
    BEGIN
    OPEN hold_cursor FOR TO_CHAR(hold_input_string);
    END sp_execute_dynamic;
    It works fine except when I perform SELECT DISTINCT. I get the following error.
    SQL> declare
    2 TYPE hold_cursor_type IS REF CURSOR;
    3 hold_cursor hold_cursor_type;
    4 hold_object_name VARCHAR2(1024);
    5 hold_object_type VARCHAR2(1024);
    6 begin
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    10 exit when hold_cursor%NOTFOUND;
    11 dbms_output.put_line('Object Name = '||hold_object_name||' Object Type = '||hold_object_type);
    12 end loop;
    13 end;
    14 /
    declare
    ERROR at line 1:
    ORA-01007: variable not in select list
    ORA-06512: at line 9
    It does the same thing with SELECT UNIQUE or SELECT with a GROUP BY. Can anyone tell me why this happens and what I could to to work around it?
    Thanks
    Chris

    see at line 7 you are selecting only one column and at line 9you are fetching into two variables
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    HTH

Maybe you are looking for

  • "There was a problem downloading the software for the iPhone....An unknown error occurred (-23)." What should I do?

    "There was a problem downloading the software for the iPhone....An unknown error occurred (-23)." What should I do?

  • Current Calendar Day on Selection Screen as Default

    Hi, I have a situation where i need to have a variable which pulls up current calender day as a default value in the selection screen. Here users can use the default value if they want or else they should be able to change the default value to their

  • Approver does not exist

    Hi, I have an issue with Leave Request for Edit/Cancel options:    - if employee cancels/edit leave request (that has been previously created in portal), the application works fine.    - if employee has an absence created directly in backend, when he

  • Cross platform mail madness

    Just to make my life easier (supposedly), I used the mail client in Windows over on my Boot Camp partition, to check my .Mac mail. No problem. As soon as I did this though, when I returned to OSX, all my old mail in Mail had disappeared. Is this simp

  • Problem starting the j2ee server

    I am trying to run j2ee -verbose and I am getting the following error. I am running it on Windows 2000 and my environment variables are set like this set JAVA_HOME=C:\jdk1.3.1_04 set J2EE_HOME=C:\j2sdkee1.3.1 set CLASSPATH=%J2EE_HOME%\lib\j2ee.jar;%J