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.

Similar Messages

  • Html form for select * from table a

    Hi all,
    I m looking for report on header/footer part from one apex pages
    which will display context from table a, like sql statement
    select * from table a, written in html.
    Is any examples in java script/html select from tables
    (and same insert into table A (...) select * from table b)
    thanks,
    Gordan

    Hello Gordan,
    Do you want to show the whole report or just some data of it?
    If it's for ex just the name and address you could create two items and have a process or computation to fill it with your select statement.
    If it's the whole report, just create the report and put it in for ex. Region 1. In your page template you can specify that Region 1 needs to come into the footer.
    Regards,
    Dimitri
    -- http://dgielis.blogspot.com/
    -- http://apex-evangelists.com/
    -- http://apexblogs.info/

  • 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

  • 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.

  • Insert into table a (select * from table b) - need pk?

    Hi there.
    I'm going to insert into table FINAL (select * from table STAGING) - same structure but in STAGING the ID column has nulls.
    Do I need to provide the ID (primary key) for table FINAL or will it get created based on sequence/trigger?
    If I were doing this in a loop I'd get the next val from the sequence but on a simple insert, I'm curious.
    thanks!

    hmm.. what is ?
    it didn't like it.
    Error(11,4): PLS-00103: Encountered the symbol "[" when expecting one of the following:     begin case declare exit for goto if loop mod null pragma    raise return select update while with <an identifier>    <a double-quoted delimited-identifier> <a bind variable> <<    close current delete fetch lock insert open rollback    savepoint set sql execute commit forall merge    <a single-quoted SQL string> pipe
    9i, sqldeveloper                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How do I do SELECT * FROM TABLE WHERE KEY IN ({list})?

    The title says it all really.
    Is there a reasonable performant way to perform the query
    SELECT * FROM TABLE WHERE KEY IN ({list})where {list} is String []?
    I am currently creating a PreparedStatement with a for loop like this   StringBuffer sb = new StringBuffer ("SELECT * FROM TABLE WHERE ID IN (");
      for (int ii=0;ii<keys.length;ii++) {
        sb.append (keys [ii]);
        if (ii != keys.length-1) sb.append (",");
      sb.append (")");but this means that the prepared statement is created each time I call my method and so I'm not sure that the optimizer will find it easy to cope with. Is there a construction that I'm missing along the lines of SELECT * FROM TABLE WHERE KEY = ? where I can create the PreparedStatement once and just call setObject or something on it when the values in {list} change?

    but this means that the prepared statement is created
    each time I call my method and so I'm not sure that
    the optimizer will find it easy to cope with.You are right, the optimizer won't find that easy to deal with (presuming that is even relevant for your driver/database.) But most optimizers won't do anything with statements that change and that is what you are doing.
    You could create several prepared statements which have a common number of bind variables. For example 10 statements with from 1 to 10 bind values. This will work if most of the queries use those.

  • How to achieve that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND n"

    How to achieve the SQL like that "SELECT * FROM table WHERE age BETWEEN 18 AND 23 AND name = 'Will' " with BDB C-API
    The primary key in the primary database is 'age' ,and the secondary key in the secondary index is 'name' ,in a lot of examples ,there are all simple , but how to do that complex one.thx~

    but this means that the prepared statement is created
    each time I call my method and so I'm not sure that
    the optimizer will find it easy to cope with.You are right, the optimizer won't find that easy to deal with (presuming that is even relevant for your driver/database.) But most optimizers won't do anything with statements that change and that is what you are doing.
    You could create several prepared statements which have a common number of bind variables. For example 10 statements with from 1 to 10 bind values. This will work if most of the queries use those.

  • 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

  • Select * from table not working with Oracle OBDC driver

    Hello,
    In our web development we have been using the MS ODBC for Oracle
    driver to connect to our Oracle db. We decided to try the
    Oracle ODBC driver because it supports the commandTimeout
    property in ASP which the MS driver does not. The problem I'm
    running into now is that all of our select * from table
    statements appear not to be working. The Oracle ODBC driver
    version we are using is ver 8.00.05.00. Is there something that
    I'm not doing properly? If I take the same select * from table
    statement and name the columns, I dont get any error. Otherwise
    I'm getting a Subscript out of range error. It seems strange to
    me that this driver would not support a select * from table
    statement (which I''m told is the case by another developer
    here).
    Is there something I'm missing?
    Thanks,
    Pete

    I'm positive I have a connection. Otherwise I wouldn't get a
    response when I name the columns instead of using *.
    There must be something else that I'm missing or doing wrong.
    I've actually been looking into alternative ODBC drivers to see
    if I have the same problems but none that I have found support
    commandTimeout.
    Any other ideas?

  • Performace Which is better ?  : Bapi inside a loop OR Select from Tables

    Hi Gurus,
    I have a report which displays purchase info records.
    If I am selecting from tables i need to use EINA, EINE, EORD and some other tables.
    There is a BAPI which gets all purchase info records specific to a vendor , material , purchasing organisation.
    QUESTION: Performace wise which is the better Approach, either selecting from tables or BAPI for Purchase info records
    Regards
    Avi.

    Whether it using BAPI or select. you need to check the performance. If you have full key for these tables EINA, EINE, EORD  then mak a select outside of the loop and within loop use READ TABLE statement with binary search. of if you want multiple records within loop then use loop insdie loop.
    Your final objective is to minimise the database hits . If you use bapi inside loop then your database hits will be more
    select from EINA
    select from EINE
    select from EORD
    loop at itab,
      read table EINA
      read table EINE
      read table EORD
    endloop

  • Special Grant to use "Select * from Table(cast..."??

    Hi,
    I've recently created the types and function to use the Table(Cast(funtion) as type)). It works fine, and gives me the correct result. I've granted execute on the types and on the function to a role that is enabled for a user, but when the user tries to use the "select * from table(cast(function) as type))", he gets a "ORA-01031: Insufficient Privileges" error message. Is there any other grant that must be given to the role, so that the user can execute the select?
    Thanks in advance!
    Daniel

    Hi Kamal,
    I'm not sure what anonymous PL/SQL block means. When I (or the user) try to run the select, I enter all the information, i.e., the owners for the type and function: "select * from table(cast(a.my_function(my_argument) as a.my_type))". I'm trying to use SQLPlus at this time, and I have Oracle 8i.
    I didn't to explicitly grant execute to the user because that would go against some rules I have to follow... I'll se if I give it a try though!
    Thanks!

  • Select * from table where rownum 5; no rows returned? why is it so?

    select from table where rownum > 5;*
    no rows returned. why is it so?
    can anyone explain me?

    Hi,
    rownum is pseudo column, and it is based on the sort order.
    For ex, if you want to get the first 5 employees who get the least salary, you use,
    select ename,sal from
        (select ename, sal
         from emp
         order by sal )
        where rownum<=5
    ENAME      SAL                   
    SMITH      800                   
    ALLEN1     890                   
    JAMES      951                   
    TURNER     998                   
    ADAMS      1100Suppose, if you want to use highest salary, you change the order by and not the rownum. So, it becomes,
    select ename,sal from
        (select ename, sal
         from emp
         order by sal desc)
        where rownum<=5
    ENAME      SAL                   
    KING1      5000                  
    FORD       3000                  
    SCOTT      3000                  
    JONES      2975                  
    BLAKE      2850 So, its not the rownum you would want to change, but the order by.
    -Arun

  • Is select from view faster then select from table..???

    Hello Gurus,
    I want to query some data from two tables, both of table have many columns (attributes) and many rows...
    I use several where clauses to retrieve data from those tables..
    witch one is faster, I create a view or I just "select" from those tables???
    Regards.
    Nia...

    riedelme wrote:
    3360 wrote:
    riedelme wrote:
    Selecting through a view almost never helps performance and frequently hurts.Views do not affect performance.
    Views are simply queries and like queries there are fast and slow ones.I disagree.
    First of all, to use a view you are executing a query to get a result set, then accessing the data from that result set - a built-in extra step to perform to get data.First of all that entire explanation of how views work is not correct. The optimizer will rewrite the query to make the view go away if possible.
    SQL> create or replace view v as select * from dual;
    View created.
    SQL> explain plan for select * from dual where dummy = 'X';
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 272002086
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DUMMY"='X')
    13 rows selected.
    SQL> explain plan for select * from v where dummy = 'X';
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 272002086
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DUMMY"='X')
    13 rows selected.Exactly the same.
    >
    Second, when accessing the data from the view the result sets don't have indexes for fast lookups and efficient joins on later steps.This is also known as just making stuff up and is not how the database works. care to share any references at all for any of this?
    >
    Third, the systems I've seen that use views extensively - I am looking at one now - tend to perform joins on views using the same tables with the same data over and over. This is a design issue and not specifically a problem with views but they lend themselves to this misuse much too easilyCorrect as I said a view is just a query, and just like queries there are good fast views and bad slow views
    >
    I'll concede that the problem is not specifically with views themselves but as I just said they lend themselves to misuse. Tuning views of views and views joined to views is difficultYes, queries can be misused as can almost all SQL functions and functionality.
    As I said - Views are simply queries and like queries there are fast and slow ones.
    Nothing that you have posted that is accurate changes that.

  • 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.

Maybe you are looking for

  • Gray screen at start up

    I hope someone can shed some light. I've been extremely happy with my first Mac...until now. It was running fine, it was turned off. The next day we turned it on and the gray screen appeared. Now you turn it on, you hear the initial sound and some cl

  • Problem using lilo in archCD0.7 after upgrade to 2.6.12.2-1

    What procedure is available to permit lilo to be activated with Udev kernel using arch 0.7CD for repair? Note that arch 0.7CD uses devfs nomenclature and that chroot doesn't permit Udev statements. What can be done?

  • SQL statement in MS Access

    Here is the SQL statement... SELECT BankCode,BranchCode,UserID,Password,Admin FROM UM_USER WHERE BankCode = '01' and BranchCode = '0014' and UserID ='ADMIN' and Password = 'admin' The resultset contains result whose UserID = 'adMin' or UserID = 'admi

  • Camera Raw 8.3 for Nikon d610

    I just installed Camera Raw 8.3 RC for CS6 in Windows 8 and it won't open my Nikon d610 Raw files.

  • Problem when confirmation of opertion in CO11n

    Dear All When i try to do confirmation of individual operation via CO11n it pickup actual data from order & when i try to save it system give me error message "Saving not necessary, data was not changed"  Message no. RU099 & when i enter system exit