Rewrite the static query to dynamic SQL

Can any one please help me to write a dynamic query within a pl/sql for the following SQL??
This is for the set ('25','04'). the number of list could be n .
The column_type ranges from(1..6) and
the column_amt1 ranges from(1..6)
SELECT t.claim_no, t.cert_no, t.rec_code,
(NVL(decode(t.column_type1,'25',NVL (t.column_amt1, 0)),0)+
    NVL(decode(t.column_type1,'04',NVL(t.column_amt1, 0)),0 )
  +
   (NVL(decode(t.column_type2,'25',NVL (t.column_amt2, 0)),0)+
    NVL(decode(t.column_type2,'04',NVL(t.column_amt2, 0)),0 )
  +
   (NVL(decode(t.column_type3,'25',NVL (t.column_amt3, 0)),0)+
    NVL(decode(t.column_type3,'04',NVL(t.column_amt3, 0)),0 )
  +
   (NVL(decode(t.column_type4,'25',NVL (t.column_amt4, 0)),0)+ 
     NVL(decode(t.column_type4,'04',NVL(t.column_amt4, 0)),0 )
  +
     (NVL(decode(t.column_type5,'25',NVL (t.column_amt5, 0)),0)+ 
      NVL(decode(t.column_type5,'04',NVL(t.column_amt5, 0)),0 )
  +
      (NVL(decode(t.column_type6,'25',NVL (t.column_amt6, 0)),0)+ 
       NVL(decode(t.column_type6,'04',NVL(t.column_amt6, 0)),0 )) amt from test_detail t;
   Thanks in Advance
Hena

user11253970 wrote:
This is the part of a procedure.NowThe query is only for type '25' and '04' .It could be more in numbers in future.So I want to maintain a dynamic sql irrespective of the number of types I use.Then first thing you must do is rename column case since it is PL/SQL reserved word (I renamed it to case_id). Then you could create a couple of SQL types and a pipelined function:
CREATE OR REPLACE
  TYPE test_detail_copay_obj
    AS
      OBJECT(
             case_id char(10),
             item    char(9),
             code    char(2),
             copay   number(10,2)
CREATE OR REPLACE
  TYPE test_detail_copay_tbl
    AS
      TABLE OF test_detail_copay_obj
CREATE OR REPLACE
  FUNCTION test_detail_copay(p_type_list varchar2)
    RETURN test_detail_copay_tbl
    PIPELINED
    IS
        v_cur sys_refcursor;
        v_copay_obj test_detail_copay_obj;
    BEGIN
        OPEN v_cur FOR 'select  test_detail_copay_obj(case_id,
                                                      item,
                                                      code,
                                                      case
                                                        when type1 in (' || p_type_list || ') then nvl(amt1,0)
                                                        else 0
                                                      end +
                                                      case
                                                        when type2 in (' || p_type_list || ') then nvl(amt2,0)
                                                        else 0
                                                      end +
                                                      case
                                                        when type3 in (' || p_type_list || ') then nvl(amt3,0)
                                                        else 0
                                                      end +
                                                      case
                                                        when type4 in (' || p_type_list || ') then nvl(amt4,0)
                                                        else 0
                                                      end +
                                                      case
                                                        when type5 in (' || p_type_list || ') then nvl(amt5,0)
                                                        else 0
                                                      end +
                                                      case
                                                        when type6 in (' || p_type_list || ') then nvl(amt6,0)
                                                        else 0
                                                      end
                          from  test_detail';
        LOOP
          FETCH  v_cur
            INTO v_copay_obj;
          EXIT WHEN v_cur%notfound;
          PIPE ROW(v_copay_obj);
        END LOOP;
        RETURN;
END;
/Now:
SQL> select  *
  2    from  table(test_detail_copay('''25'',''04'''))
  3  /
CASE_ID    ITEM      CO      COPAY
EML3371015 133761570 10        355
EML3371015 133761570 10         20
EML3371015 133761570 10          5
EMC6369600 140328551 10         54
EMH6353995 140328551 11      26.04
SQL> select  *
  2    from  table(test_detail_copay('''25'''))
  3  /
CASE_ID    ITEM      CO      COPAY
EML3371015 133761570 10        300
EML3371015 133761570 10         20
EML3371015 133761570 10          5
EMC6369600 140328551 10          0
EMH6353995 140328551 11       5.52
SQL> SY.

Similar Messages

  • Query with Dynamic SQL

    Hello,
    I would like to create a Dynamic SQL in which change is the name of the table according to the outcome of the first SQL. This is possible?
    'WITH TABLE_X AS(SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL <= 12)' ||
    'SELECT A.COL1, A.COL2, B.COL1, B.COL7'                              ||
    '  FROM TABLE_A' || TABLE_X.LVL || ' A'                              ||
    '     , TABLE_B' || TABLE_X.LVL || ' B'                              ||
    ' WHERE A.COL1 = B.COL1 AND ...    'tables in database
    TABLE_A1
    TABLE_A2
    TABLE_A12
    TABLE_B1
    TABLE_B2
    TABLE_B12let me know how I can do this
    Regards

    Hi,
    Sorry, I don't see what you're trying to do.
    "Dynamic SQL" is really a mis-nomer. The number of tables and columns in a query, and their names, must be spelled out when the statement is compiled. There is nothing dynamic about it.
    In dynamic SQL, a PL/SQL procedure or another query writes all or part of query just milliseconds before it is compiled, typically using data taken from tables or supplied by a user right then.
    For example, consider this static query:
    SELECT     a.col1, a.col2, b.col1, b.col7
    FROM     table_1     a
    ,     table_2 b
    WHERE     a.col1 = b.col1;Now, say the 1 in "table_1" and the 2 in "table_2" are variables, x and y, that you will want to look up from another table every time you run this query. You can make it dynamic like this:
    sql_txt := 'SELECT  a.col1, a.col2, b.col1, b.col7 '
         || 'FROM    table_' || TO_CHAR (x) || ' a '
         || ',       table_' || TO_CHAR (y) || ' b '
         || 'WHERE   a.col_1 = b.col1';Now let's make it really interesting. Say that instead of 2 tables, and 1 join condition, you''ll have n tables and n-1 join conditions, where n has to be computed at (actually a split second before) run-time. That is, if n=4, you might need to construct a static query with 4 tables and 3 join conditions, like this:
    SELECT     a.col1, a.col2, b.col1, b.col7
    FROM     table_1     a
    ,     table_2 b
    ,     table_12 c
    ,     table_2 d
    WHERE     a.col1 = b.col1
    AND     a.col1 = c.col1
    AND     a.col1 = d.col1;You can do that using dynamic SQL, too.
    Post an example of the static query you need to build, and describe what parts of it are dynamic, and how you get the values for those parts, and someone will help you write the dynamic SQL.

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • What is the problem with native dynamic sql when counting rows in all table

    what is the problem with native dynamic sql when counting rows in all table?Giving an error "table or view does not exist". Thanks.
    DECLARE
    v_sql_string varchar2(1000);
    v_no_of_rows number;
    BEGIN
    for i in ( select table_name from all_tables )
    loop
    v_sql_string := ' select count(1) from ' || i.table_name;
    dbms_output.put_line( v_sql_string );
    --execute immediate v_sql_string into v_no_of_rows;
    end loop;
    END;

    Usually your problem can be described with 'Who cares'. I mean, for what reason do you do this? I doubt that there's a business need to get 100 % accurate answers for this. Normally such things are used to get a picture about the growth of data.
    Personally I would prefer to have up-to-date statistics for all tables and just query the number of rows from there. Sufficient for me in < 99 % of all cases.
    Just my $ .02...

  • Difference between Static SQL Query and Dynamic SQL Query.

    Hi,
    Please explain the basic difference between static and dynamic sql queries. Please explain with example.

    Static: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm
    Dynamic: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm

  • InterMedia Text Query in Dynamic SQL

    I have a query using score and contains interMedia operators that runs without problem from the SQL*Plus command line, but generates a "ORA-01858: a non-numeric character was found where a numeric was expected" error when run via dynamic sql.
    The query runs something like this:
    select
    score(1),
    score(2),
    a.field1,
    b.field2
    from
    a,
    b,
    where
    b.id (+)= a.id and
    b.name (+)= 'test' and
    ((contains(a.content, 'query', 1) +
    (contains(b.valud, 'query', 2)) > 0
    I'm trying to avoid an OR clause by adding the two contains clauses together. Could this error be caused by the outer join on table b? If so, why does it run without problems from SQLPlus?
    null

    Thanks for the help.
    Can you give me an example of how I have to specify the url in the database? For my intranet websites, I was able to use the foln. two formats http://host1/asptest/index.html (and)
    URL:http://scott:tiger@host1:80/asptest/index.html
    where host1 is the name of the host and 80, the port number.
    I need to be able to access the oracle website(http://www.oracle.com/index.html) and run the foln. query,
    SELECT id, url FROM test WHERE CONTAINS(url, 'Education')>0;
    I tried setting the HTTP_PROXY attribute of the URL_DATASTORE, and specified the url as http://www.oracle.com/index.html in the database, but that didn't seem to help.
    Thanks.
    null

  • Linked server query using Dynamic SQL

    I have a Linked server query that takes forever to run. WHen I hardcode the acct# it runs fast. However I want these acct numbers int he where clause to be generated dynamically. For eg: below is what I need:
    --Get the 11 Loans from this Table A From the FIRST QUERY
    --- Plug those loans numbers in the second query  In the WHERE Clause eg should looks like  where  ACCT in (1,2,3,5)
    DECLARE
    @sSQL varChar(MAX)
    SET @sSQL
    =
    ' SELECT
    [Loan] FROM TableA D
    EXECUTE(@sSQL)
    --2ND QUERY 
    DECLARE
    @sSQL1 varChar(MAX)
    SET @sSQL1
    ='
    SELECT Field1, 
    Field2,
    Field3,
    Field4,
    Field5
       FROM LinkedServer.Dbaname.dbo.TableB a
    where ACCT in ''('''
    +(@sSQL)
    +
    ''')'''--- This needs to look like  where  ACCT in (1,2,3,5)
    select
    @sSQL1

    Ok, so use this.. instead of your first statement.
    DECLARE @sSQL NvarChar(MAX), @output NVARCHAR(100), @ParmDefinition nvarchar(500);
    SET @ParmDefinition = N'@sqlout NVARCHAR(100) OUTPUT'
    SET @sSQL = N'SELECT DISTINCT @sqlout = STUFF((SELECT '',''+CAST(S2.loan AS VARCHAR(100))
    FROM tableA S2
    FOR XML PATH('''')), 1, 1, '''')
    FROM tableA S1'
    EXECUTE sp_executesql @sSQL, @parmdefinition, @sqlout = @output OUTPUT
    and use @output instead of @sSQL in the second statement.
    You can read about STUFF command @
    http://sqlsaga.com/sql-server/how-to-concatenate-rows-into-one-row-using-stuff/.
    Good Luck :)
    Visit www.sqlsaga.com for more t-sql code snippets or BI related how to's.

  • Can we make the Lookup Query more dynamic?

    Hello OIM gurus,
    I have a lookup field in my process form and I am entering the properties of this field with the design client, such as Column Names, Captions, widths, Lookup Query etc. I would like to make the Lookup query a little more flexible in that it can take in different lookup codes based on some criteria. To be specific, I would like the lookup query specific to each resource.
    A sample of my query is: 'select v.lkv_encoded,v.lkv_decoded from lkv v, lku u where u.lku_key=v.lku_key and u.lku_type_string_key='<my lookup code>'
    I have lookup codes that are specific to each resource and I would like to use these codes here. I see some things like $Process Data.xxx$ and I am not sure how to use this or change the lookup code dynamically. Or is there a totally different way to do this?
    Thanks in advance
    -SK

    Hi ,
    can anyone please let me know the exact usage of Lookup Quey. I tried to find out in OIM docs but end up with no luck. By this post i am able to write basic lookup query (find out the USR_Login from USR table). I have couple of queries which i am not sure about and will apreaciate if anyone could provide me answer
    1. We have to add property - Lookup Column names, Column names, Column width and Caption for lookup query. What are their usage and restrictions (what values we can use and what we cannot).
    2. I am using my lookup field currently in AD resource form. My requirement is to provide manager options to search for user (in AD resource form only) for his/her direct reports having AD account. For this i tried to lookup the query on UD_ADUSER table but it is giving me error (even resource form on console is not coming up) Does LookupQuery is not much flexible to query the connector tables. if so how can i compete my requirement.
    3. Does lookup querry (in resource form) provides you option to provide the filter as per user attribute value in OIM user profile.
    Thanks.....

  • Change the image in the statice adobe forms dynamically based on condition.

    Hi Experts,
    Could you please explain how to change the image dynamically in the static adobe forms based on certain condition/calculation.
    Thanks in Advance.

    One of the very few options you have is loading them all into the form as embedded images, and then dynamically making the visible and hidden depending on your conditions.
    Dynamic loading of images (from a URL or remote location) was completely removed from Interactive Forms a while ago as it was deemed insecure. (and it is)
    The second option is loading them all into your SAP system and then making a webservice which you call with a trigger to return you the binary form of the image, which you can read by creating the correct type in the Context.
    Kind regards,
    Frederik-Jan.

  • Rewrite the max query...

    The inner select statement works fast and few columns generated based on A.QSN_DESC_X values, AND to get a single row I am doing a group by on cmpltn_i by taking the max row. When I do this group by the query takes approx 5 mnts. The inner query returns 227270 records. The final query give 37,000 records.
    Can someone suggest any better way to write this query?
    select
    CMPLTN_I,
    max(emp_i) as emp_i,
    max(first_name) as first_name,
    max(last_name) as last_name,
    max (vendor) as vendor,
    max (product_type) as product_type,
    max (event_type) as event_type,
    max (dollar_amt) as dollar_amt,
    max (date_received) as date_received,
    max (branch_code) as branch_code
    from (
    select   /*+DRIVING_SITE(A)*/   
    B.CMPLTN_I,
    B.emp_i, 
    E.EMP_1ST_NME_X as first_name,
    E.EMP_LAST_NME_X as last_name, 
    case when substr(A.QSN_DESC_X,1,6) = 'Vendor' then A.CHCE_DESC_X else null end as vendor,
    case when substr(A.QSN_DESC_X,1,12) = 'Product Type' then A.CHCE_DESC_X else null end  as product_type,
    case when substr(A.QSN_DESC_X,1,10) = 'Event Type' then A.CHCE_DESC_X else null end as  event_type,
    case when substr(A.QSN_DESC_X,1,13) = 'Dollar Amount' then A.CHCE_DESC_X else null end as  dollar_amt,
    case when substr(A.QSN_DESC_X,1,13) = 'Date Received' then A.CHCE_DESC_X else null end as date_received,
    case when substr(A.QSN_DESC_X,1,16) = 'Branch Wire Code' then A.CHCE_DESC_X else null end as branch_code        
    from  OAT.FORM_FACT@REMOTE_AB A, OAT.FORM_CMPLTN_FACT@REMOTE_AB B, empl_info_dimn E
    where  A.CMPLTN_I  =  B.CMPLTN_I
    and      B.CMPLTN_C  =  'C'
    and      B.app_i  = '20'
    and      E.emp_i = B.emp_i
    group by
    CMPLTN_I

    10g release 2.
    cost based, statistics are good
    without driving site hint, the response time is bad
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2770348679
    | Id  | Operation              | Name                       | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT REMOTE|                            |   922K|   139M|       |   104K  (1)| 00:20:49 |        |      |
    |   1 |  SORT GROUP BY         |                            |   922K|   139M|   300M|   104K  (1)| 00:20:49 |        |      |
    |*  2 |   HASH JOIN            |                            |   922K|   139M|  4976K| 71818   (2)| 00:14:22 |        |      |
    |   3 |    REMOTE              | EMPL_INFO_DIMN             | 86311 |  3961K|       | 10903   (1)| 00:02:11 |      ! | R->S |
    |*  4 |    HASH JOIN           |                            |   923K|    97M|       | 55274   (2)| 00:11:04 |        |      |
    |*  5 |     TABLE ACCESS FULL  | FORM_RECIPIENT_CMPLTN_FACT | 24223 |   331K|       |   698   (3)| 00:00:09 | OATP0~ |      |
    PLAN_TABLE_OUTPUT
    |   6 |     TABLE ACCESS FULL  | FORM_RESP_FACT             |    10M|  1013M|       | 54439   (2)| 00:10:54 | OATP0~ |      |
    Predicate Information (identified by operation id):
       2 - access("A1"."EMP_I"="A2"."EMP_I")
       4 - access("A3"."CMPLTN_I"="A2"."CMPLTN_I")
       5 - filter("A2"."APP_I"=20 AND "A2"."CMPLTN_I" IS NOT NULL AND "A2"."CMPLTN_C"='C')
    Remote SQL Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       3 - SELECT /*+ USE_HASH ("A1") */ "EMP_I","EMP_LAST_NME_X","EMP_1ST_NME_X" FROM "DWCSADM"."EMPL_INFO_DIMN" "A1"
           (accessing '!' )
    Note
       - fully remote statement
    31 rows selected.

  • Kindly help with rewriting the foll. query in a better way

    IS there a better way of writing the foll query:
    When I have 12,50,00,000 rows in Fact Table, the query is unable to execute. I use more than 200GB of temporary space. But I still get Temp Tablespace Full Error:
    --Foll WITH Clause is to calculate Sum of Debit-Credit to calculate BLNC acc. to Group By values
    WITH crnt_blnc_set
    AS ( SELECT f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.pstng_crncy_id AS crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id AS txn_id,
    f.acntng_entry_src AS txn_src,
    f.acntng_entry_typ AS acntng_entry_typ,
    f.val_dt_dmn_id,
    f.revsn_dt,
    SUM (
    DECODE (
    f.pstng_typ,
    'Credit', f.pstng_amnt,
    0))
    - SUM (
    DECODE (
    f.pstng_typ,
    'Debit', f.pstng_amnt,
    0))
    AS blnc
    FROM FactTable f
    GROUP BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.pstng_crncy_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.acntng_entry_src,
    f.acntng_entry_typ,
    f.val_dt_dmn_id,
    f.revsn_dt),
    --Foll WITH Clause calculates Min and Max Date Ids for the Group By conditions as mentioned
    min_mx_dt
    AS ( SELECT /*+parallel(32)*/
    f.hrarchy_dmn_id AS hrarchy_dmn_id,
    f.prduct_dmn_id AS prduct_dmn_id,
    f.crncy_dmn_id AS crncy_dmn_id,
    f.acnt_dmn_id AS acnt_dmn_id,
    f.txn_id AS txn_id,
    f.txn_src AS txn_src,
    f.acntng_entry_typ AS acntng_entry_typ,
    MIN (f.val_dt_dmn_id) AS min_val_dt,
    GREATEST (MAX (f.val_dt_dmn_id), 2689) AS max_val_dt
    FROM crnt_blnc_set f
    GROUP BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ),
    /*Foll WITH Clause has a Cartesian Join on date_dmn to populate missing entries
    This requirement is because if we have a distinct row for
    hrarchy_dmn_id,
    prduct_dmn_id,
    crncy_dmn_id,
    acnt_dmn_id,
    txn_id,
    txn_src,
    acntng_entry_typ Combination and If wehave a missing entry for that in the max date provided then we actually create those missing entries*/
    slctd_rcrds
    AS ( SELECT /*+ ordered use_nl(d) parallel(mx, 4) */
    mx.hrarchy_dmn_id AS hrarchy_dmn_id,
    mx.prduct_dmn_id AS prduct_dmn_id,
    mx.crncy_dmn_id AS crncy_dmn_id,
    mx.acnt_dmn_id AS acnt_dmn_id,
    mx.txn_id AS txn_id,
    mx.txn_src AS txn_src,
    mx.acntng_entry_typ AS acntng_entry_typ,
    d.date_value AS val_dt,
    d.date_dmn_id AS val_dt_dmn_id
    FROM min_mx_dt mx, date_dmn d
    WHERE mx.min_val_dt <= d.date_dmn_id
    AND mx.max_val_dt >= d.date_dmn_id
    --Foll. WITH clause actually has a outer Join with Firt With Clause to populate the values accordingly
    cmbnd_rcrds
    AS (
    SELECT /*+ USE_HASH(c) */ s.hrarchy_dmn_id AS hrarchy_dmn_id,
    s.prduct_dmn_id AS prduct_dmn_id,
    s.crncy_dmn_id AS crncy_dmn_id,
    s.acnt_dmn_id AS acnt_dmn_id,
    s.txn_id AS txn_id,
    s.txn_src AS txn_src,
    s.acntng_entry_typ AS acntng_entry_typ,
    s.val_dt_dmn_id AS val_dt_dmn_id,
    NVL (c.revsn_dt, s.val_dt) AS revsn_dt,
    NVL (c.blnc, 0) AS blnc,
    0 AS prvs_rcrd_ind
    FROM slctd_rcrds s, crnt_blnc_set c
    WHERE s.hrarchy_dmn_id = c.hrarchy_dmn_id(+)
    AND s.prduct_dmn_id = c.prduct_dmn_id(+)
    AND s.crncy_dmn_id = c.crncy_dmn_id(+)
    AND s.acnt_dmn_id = c.acnt_dmn_id(+)
    AND s.txn_id = c.txn_id(+)
    AND s.txn_src = c.txn_src(+)
    AND s.acntng_entry_typ = c.acntng_entry_typ(+)
    AND s.val_dt_dmn_id = c.val_dt_dmn_id(+))
    Select * from cmbnd_rcrds

    Thanks for the response Alfonso. I have tried that as well. But Create Table as Also uses Temp Storage till it's created. And that again gives the same error as well.
    Anyways I am now trying with a smaller set. This much piece gets executed in Half an hour but the next piece where we pivot the data is taking forever now.
    That piece is as follows:
    (SELECT /*+parallel(8)*/
    f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ,
    f.val_dt_dmn_id,
    f.revsn_dt,
    SUM (
    blnc)
    OVER (
    PARTITION BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ
    ORDER BY d.date_value)
    AS crnt_blnc,
    SUM (
    blnc)
    OVER (
    PARTITION BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ,
    d.fin_mnth_num
    || d.fin_year_strt
    || d.fin_year_end
    ORDER BY d.date_value)
    / d.mnth_to_dt
    AS mtd_avg,
    SUM (
    blnc)
    OVER (
    PARTITION BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ,
    d.fin_year_strt || d.fin_year_end
    ORDER BY d.date_value)
    / yr_to_dt
    AS ytd_avg,
    f.prvs_rcrd_ind AS prvs_rcrd_ind
    FROM cmbnd_rcrds f, thor_date_dmn d
    WHERE d.holidaY_ind = 0 AND f.val_dt_dmn_id = d.date_dmn_id)
    SELECT f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id AS txn_id,
    f.txn_src AS acntng_entry_src,
    f.acntng_entry_typ AS acntng_entry_typ,
    f.val_dt_dmn_id,
    f.revsn_dt,
    f.crnt_blnc,
    f.mtd_avg,
    f.ytd_avg,
    'EOD TB ETL' AS crtd_by,
    SYSTIMESTAMP AS crtn_dt,
    NULL AS mdfd_by,
    NULL AS mdfctn_dt
    FROM fnl_set f
    WHERE f.prvs_rcrd_ind = 0
    ORDER BY f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.crncy_dmn_id,
    f.acnt_dmn_id,
    f.txn_id,
    f.txn_src,
    f.acntng_entry_typ,
    f.val_dt_dmn_id
    Any other way to pivot this?
    Also I am getting a lot of foll wait events:
    PX Deq Credit :Send blkd
    PX Deq :Table Q Normal
    Direct Path Write Temp
    And Direct Path Read Temp.

  • Need help on the below query or Pl-SQL

    Hello Every one,
    Please let me know if some one can help me out with the below scenario either in pl-sql or sql.
    Source Data:
    0000253800     0.25          0845A     0900A
    0000253800     1          0900A     1000A
    0000253800     1          1300P     1400P
    0000253800     1          1500P     1600P
    0000253800     1          1600P     1700P
    Output needed:
    0000253800     1.25          0845A     1000A
    0000253800     1          1300P     1400P
    0000253800     2          1500P     1700P
    Thanks in Advance....
    Edited by: user12564103 on Dec 11, 2011 5:54 PM

    Hi,
    Welcome to the forum!
    Depending on your data and your requirements:
    WITH     got_times     AS
         SELECT     column_1, column_2, column_3, column_4
         ,     TO_DATE ( substr (column_3, 1, 4)
                   , 'HH24MI'
                   )     AS time_3
         ,     TO_DATE ( SUBSTR (column_4, 1, 4)
                   , 'HH24MI'
                   )     AS time_4
         FROM     table_x
    ,     got_grp_id     AS
         SELECT     column_1, column_2, column_3, column_4
         ,     time_3, time_4
         ,     time_4 - SUM (time_4 - time_3) OVER ( PARTITION BY  column_1
                                        ORDER BY         time_3
                                      )     AS grp_id
         FROM     got_times
    SELECT       column_1
    ,       SUM (column_2)     AS sum_2
    ,       MIN (column_3) KEEP (DENSE_RANK FIRST ORDER BY time_3)
                        AS min_3
    ,       MAX (column_4) KEEP (DENSE_RANK LAST  ORDER BY time_4)
                        AS max_4
    FROM       got_grp_id
    GROUP BY  column_1
    ,       grp_id
    ORDER BY  column_1
    ,       grp_id
    ;Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, as well as the results you want from that data. Explain, with specific examples, how you get the results you want from that data.
    Always say which version of Oracle you're using. The query above will work in Oracle 9.1 (and higher).
    Since this is your first thread, I'll do this for you:
    CREATE TABLE     table_x
    (     column_1     NUMBER
    ,     column_2     NUMBER
    ,     column_3     VARCHAR2 (5)
    ,     column_4     VARCHAR2 (5)
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, .25, '0845A', '0900A');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '0900A', '1000A');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1300P', '1400P');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1500P', '1600P');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1600P', '1700P');Column_1 identifes a day.
    Column_2 is an amount that I need to total.
    Column_3 and column_4 are starting and ending times. We can assume that they are all valid times (in 'HH24MI' format, plus a redundant 'A' or 'P') on the same day, column_3 is always less than column_4, and that the range of two rows for the same value of column_1 never overlap. Column_4 of one row may be equal to column_3 of another rows with the same column_1, but it will never be greater.
    Each row of the output represent a contiguous group of rows (each ending exactly when the next one begins) with the same column_1, with the common column_1, the total of column_2, and the range of the group.
    For example, the first two rows for a single group, because they have the same value for column_1, and one ends exactly when the other begins (at 9:00 AM). This group represents day 253800, from 8:45 AM to 10:00 AM. The totla of column_2 fro this group is .25 + 1 = 1.25.
    The next row (from 1:00 PM to 2:00 PM) is a group all by itself, because there is a gap one either side of it separating it from its nearest neighbor on the same day."
    Of course, I'm guessing at lots of things.
    Edited by: Frank Kulash on Dec 11, 2011 9:44 PM
    Changed TO_DATE calls.
    Edited by: Frank Kulash on Dec 11, 2011 9:52 PM
    Added sample question.

  • Can't get same results on query using dynamic time frame versus static time frame

    I am trying to run a query on a Lookout database using MS Access. If I use static dates as criteria in the "LocalTime" field I get results that are marked on the hour, eg. 1:00 pm. If I try to use dynamic dates as criteria I get results that are marked on the half hour, eg. 1:30 pm. The results are for each hour but the difference in the queries causes the dynamic query to come up with different results than a spreadsheet generated by Lookout that the client relies on for backup. Does anybody know a way I can get the dynamic date query to act like the static query? I can't use static queries because this is for a daily report and the client will not pay for me to make 365 new queries each y
    ear. I tried NI's tech support but they pointed me to the same SQL examples that are in the Developer's Manual which are all static queries. Tech Support also told me they can't help me figure out dynamic queries.

    Yes I am using an interval clause that says "interval=1:00". I create the localtime clause dynamically and this seems to be where my problem lies. No matter what I have the dynamic function create the date/time as, i.e., 07/01/2002 or 07/01/2002 12:00 AM or 07/01/2002 00:00, the time the query returns for each record is 32 minutes after the hour. From this I assume it is averaging each hour interval from one half hour mark to the next, eg. from 12:30 am to 1:30 am. This is born out because the hourly averages do not match the averages for the same time frame that Lookout exports to an Excel spreadsheet. Thanks for your suggestion though.

  • ORA-06502:PL/SQL:numeric or value error. Dynamic SQL the only answer??

    ORA-06502: PL/SQL: numeric or value error: character string buffer too small.
    I have an HTMLDB report that errors with the above message. The query is over 7000 characters long so I'm guessing this is the cause. If I retrieve the query from a query table, replace the variables in the LONG query using PL/SQL and execute using dynamic SQL, are the HTMLDB reporting features the same as if I was using a simple SQL query? Is there a better way? I will need to 'drill-down' from this report so how do I create the links? The only HTMLDB PL/SQL package I can find mentioned in the User's Guide is HTMLDB_PLSQL_JOB.
    Cheers, Paul

    Hello All,
    I have the same problem.
    For me it started when i got about 500 rows in the table
    on which the LOV is based.
    With a lot of trying with substr I managed to find the size of the string which it still accepted, which was 51 characters.
    So I thought it was some glitch in the APEX insides, and since I had no time to resolve it further, I went on working.
    But I have to resolve it now, because the following mysterious behaviour is occurring:
    Every few records added to the base table, the problem occurs again, and I can resolve it by cutting down the string
    with one character.
    I have now reached 39 characters !?
    I am afraid that I will end up with 1 character or even null.
    If I switch to Popup list based on LOV there's no problem, and the complete strings are shown.
    The maximum length of the string in my basetable is 252, but the data in it now reaches 55 at most.
    Any idea welcome!
    I did already recreate the master-detail form from scratch, but there the same behaviour.
    greetings,
    Richard Kloostra

  • Query Build problem in Native Dynamic SQL

    I am writing a procedure to calculate the summary from the monthly salary table by dynamically building the query using ref cursor,open cursor using the bind variables and bulding the query statement.But the query is not returning any rows
    vSQL := 'select a.ad_code,a.acc_code,m.jobtype,m.estbtype,'||'sum(m.'||vabsrec.vadsn||') from gencopayroll.pay_allowaccounthead a,'||
    'gencopayroll.pay_monthly_paybill m where bill_type = :ptype and loc_id = :plocid '||
    'and processing_period = :pprocmon and a.ad_code = :padcode group by a.acc_code,'||
    'm.jobtype,m.estbtype,a.ad_code';

    I am writing a procedure to calculate the summary
    from the monthly salary table by
    1) dynamically building the query using ref cursor
    2) open cursor using the bind variables
    3) bulding the query statement.Can you show us the code that performs these steps.
    Once a cursor is opened you need to fetch the rows from it in order to get the data.
    Also, have you checked that the query runs as plain non-dynamic SQL within SQL*Plus with the same parameters, to see that it returns data?
    What is you purpose for using Dynamic SQL? If you clarify the requirement we may be able to show you how to do the same using non-dynamic SQL.

Maybe you are looking for

  • IPod Touch doesn't show up in iTunes

    So I've been reading the support site and this forum for 2 days and I know this is a common problem, but I've tried everything. Environment: PC w/ Visa SP1 (Intel 975XBX Motherboard) 32GB iPod Touch (new with 1.1.4 software) After many itunes reinsta

  • Implementing I2C on Siemens TC65

    Hi, I need an assistance with I2c protocol, just some basic questions. Do you need connector object, and connection to start and control I2C, or all control is done by AT commands ? If You need connector and connection, what type of connection should

  • Email shows gmail + hotmail setup. No acess to either inboxes.

    Email shows gmail + hotmail. No acess to either inboxes. Driving me nuts any help kindly appreciated.

  • If I update to 37.0.2, can I keep my red cats/green flavor theme?

    Every single time I update, I lose them. Not being geeky, it's been hard get them back, so I just won't update if they can't come along.

  • Accesspoint not joining correct controller

    Hi, I am trying to setup a 2504 Wireless Controller with a few  AIR-AP1262N-E-K9 Access Points. But i'm having trouble getting the access points to connect to the controller. The controller and AP's are setup at a local network at one of my customers