Query doesn't return rows

Hi,
The following query returns no rows, while there is one row in the table:
SELECT *
FROM (SELECT id,
             amt_disburse amt1,
             TO_CHAR (dt_disburse, 'RRRRMMDD') date1
      FROM (SELECT a.*,
                   ROW_NUMBER ()
                      OVER
                         PARTITION BY id
                         ORDER BY dt_disburse DESC
                      rnk
            FROM pymt_tmp a)
      WHERE rnk = 1),
     (SELECT amt_disburse amt2, TO_CHAR (dt_disburse, 'RRRRMMDD') date2
      FROM (SELECT amt_disburse,
                   dt_disburse,
                   ROW_NUMBER ()
                      OVER
                         PARTITION BY id
                         ORDER BY dt_disburse DESC
                      rnk
            FROM pymt_tmp)
      WHERE rnk = 2)
Script for pymt_tmp tabe:
CREATE TABLE PYMT_TMP
  ID                          VARCHAR2(10)         NOT NULL,
  AMT_DISBURSE        NUMBER(11,2)              NOT NULL,
  DT_DISBURSE          DATE                      NOT NULL
Data in the pymt_tmp table
ID                              AMT_DISBURSE        DT_DISBURSE        
0099999999                       199                 3/16/2009
Expected Results:
      ID             AMT1      DATE1         AMT2    DATE2
0099999999    199.00    20090316    
                                                           AMT2 AND DATE2 should be blankAdvance thanks for your help.

Using Kordirko's approach from this thread: {message:id=4412642}, you could do something like:
SQL> select * from pymt_tmp;
ID         AMT_DISBURSE DT_DISBUR
0099999999          199 16-MAR-09
1 row selected.
SQL> select id
  2  ,      amt1
  3  ,      date1
  4  ,      amt2
  5  ,      date2
  6  from ( select id
  7         ,      to_char(amt_disburse, '999g999d90') amt1
  8         ,      to_char(dt_disburse, 'rrrrmmdd') date1
  9         from ( select a.*
10                ,      row_number() over (partition by id order by dt_disburse desc) rnk
11                from   pymt_tmp a
12              )
13         where rnk = 1
14       )
15  ,    ( with pymt_tmp2 as ( select to_char(amt_disburse, '999g999d90') amt2
16                             ,      to_char(dt_disburse, 'rrrrmmdd') date2
17                             from ( select amt_disburse
18                                    ,      dt_disburse
19                                    ,      row_number() over (partition by id order by dt_disburse desc) rnk
20                                    from   pymt_tmp
21                                  )
22                             where rnk = 2
23                           )
24         select amt2
25         ,      date2
26         from   pymt_tmp2                        
27         union all
28         select null amt2
29         ,      to_char(null) date2
30         from   dual
31         where not exists ( select null
32                            from   pymt_tmp2
33                          )
34       );
ID         AMT1        DATE1    AMT2        DATE2
0099999999      199.00 20090316
1 row selected.if you insist on querying for a non-existing second record.
not blind, but deaf instead

Similar Messages

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • Select query does not return rows

    Hi all,
    The following query does not returning rows even though values are there in table.
    Kindly let me know why it is creating problem.
    thanks, P Prakash
    /* Formatted on 2011/05/11 16:44 (Formatter Plus v4.8.8) */
    SELECT pr.pa_rqst_sid, ptr.sbmtr_trnsctn_idntfr, ptr.athrztn_infrmtn,
    DECODE (ou.org_unit_name,
    'PA - MDCH', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_1_PA'),
    'PA - MPRO', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_2_PA'),
    'PA - DEFAULT', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_1_PA'),
    NULL
    ) AS intrchng_sndr_idntfr,
    ptr.intrchng_sndr_idntfr AS intrchng_rcvr_idntfr, ptr.usg_indctr,
    ptr.intrchng_sndr_idntfr AS applctn_rcvr_code,
    ptr.trnsctn_set_cntrl_nmbr AS trnsctn_set_cntrl_nmbr,
    ptr.athrztn_infrmtn_qlfr AS athrztn_infrmtn_qlfr,
    ptr.scrty_infrmtn_qlfr AS scrty_infrmtn_qlfr,
    ptr.scrty_infrmtn AS scrty_infrmtn,
    ptr.intrchng_sndr_idntfr_qlfr AS intrchng_sndr_idntfr_qlfr,
    ptr.intrchng_rcvr_idntfr_qlfr AS intrchng_rcvr_idntfr_qlfr,
    ptr.intrchng_cntrl_stndrds_idntfr AS intrchng_cntrl_stndrds_idntfr,
    ptr.intrchng_cntrl_vrsn_nmbr AS intrchng_cntrl_vrsn_nmbr,
    ptr.intrchng_cntrl_nmbr AS intrchng_cntrl_nmbr,
    ptr.acknwldgmnt_rqstd_indctr AS acknwldgmnt_rqstd_indctr,
    ptr.cmpnt_elmnt_sprtr AS cmpnt_elmnt_sprtr,
    ptr.fnctnl_idntfr_code AS fnctnl_idntfr_code,
    ptr.grp_cntrl_nmbr AS grp_cntrl_nmbr,
    ptr.rspnsbl_agncy_code AS rspnsbl_agncy_code,
    ptr.vrsn_rls_indstry_idntfr_code AS vrsn_rls_indstry_idntfr_code
    FROM pa_request pr, pa_transaction_request ptr, org_unit ou
    WHERE ptr.pa_trnsctn_rqst_sid = pr.pa_trnsctn_rqst_sid
    AND pr.org_unit_sid = ou.org_unit_sid
    AND pr.oprtnl_flag = 'A'
    AND ptr.oprtnl_flag = 'A'
    AND ou.oprtnl_flag = 'A'
    AND pr.pa_mode_type_lkpcd = 'BT'
    AND (pr.status_cid = 86 OR pr.status_cid IN
    (20, 70, 30, 80, 25, 101, 96)
    AND pr.pa_rqst_sid = 75006271
    ORDER BY pr.pa_rqst_sid;
    the query is not giving result for this particular request sid.75006271 is present in table.

    833560 wrote:
    Hi all,
    The following query does not returning rows even though values are there in table.
    Kindly let me know why it is creating problem.
    thanks, P Prakash
    /* Formatted on 2011/05/11 16:44 (Formatter Plus v4.8.8) */
    SELECT pr.pa_rqst_sid, ptr.sbmtr_trnsctn_idntfr, ptr.athrztn_infrmtn,
    DECODE (ou.org_unit_name,
    'PA - MDCH', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_1_PA'),
    'PA - MPRO', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_2_PA'),
    'PA - DEFAULT', (SELECT property_value
    FROM hipaa_system_defaults
    WHERE property_name = 'RECEIVER_ID_1_PA'),
    NULL
    ) AS intrchng_sndr_idntfr,
    ptr.intrchng_sndr_idntfr AS intrchng_rcvr_idntfr, ptr.usg_indctr,
    ptr.intrchng_sndr_idntfr AS applctn_rcvr_code,
    ptr.trnsctn_set_cntrl_nmbr AS trnsctn_set_cntrl_nmbr,
    ptr.athrztn_infrmtn_qlfr AS athrztn_infrmtn_qlfr,
    ptr.scrty_infrmtn_qlfr AS scrty_infrmtn_qlfr,
    ptr.scrty_infrmtn AS scrty_infrmtn,
    ptr.intrchng_sndr_idntfr_qlfr AS intrchng_sndr_idntfr_qlfr,
    ptr.intrchng_rcvr_idntfr_qlfr AS intrchng_rcvr_idntfr_qlfr,
    ptr.intrchng_cntrl_stndrds_idntfr AS intrchng_cntrl_stndrds_idntfr,
    ptr.intrchng_cntrl_vrsn_nmbr AS intrchng_cntrl_vrsn_nmbr,
    ptr.intrchng_cntrl_nmbr AS intrchng_cntrl_nmbr,
    ptr.acknwldgmnt_rqstd_indctr AS acknwldgmnt_rqstd_indctr,
    ptr.cmpnt_elmnt_sprtr AS cmpnt_elmnt_sprtr,
    ptr.fnctnl_idntfr_code AS fnctnl_idntfr_code,
    ptr.grp_cntrl_nmbr AS grp_cntrl_nmbr,
    ptr.rspnsbl_agncy_code AS rspnsbl_agncy_code,
    ptr.vrsn_rls_indstry_idntfr_code AS vrsn_rls_indstry_idntfr_code
    FROM pa_request pr, pa_transaction_request ptr, org_unit ou
    WHERE ptr.pa_trnsctn_rqst_sid = pr.pa_trnsctn_rqst_sid
    AND pr.org_unit_sid = ou.org_unit_sid
    AND pr.oprtnl_flag = 'A'
    AND ptr.oprtnl_flag = 'A'
    AND ou.oprtnl_flag = 'A'
    AND pr.pa_mode_type_lkpcd = 'BT'
    AND (pr.status_cid = 86 OR pr.status_cid IN
    (20, 70, 30, 80, 25, 101, 96)
    AND pr.pa_rqst_sid = 75006271
    ORDER BY pr.pa_rqst_sid;
    Hi,
    Its very difficult to analyse the query without any data being provided. So I suggest you to debug the above query by keeping basic join condition intact and comment out all the other where conditions for initial run.
    FROM pa_request pr, pa_transaction_request ptr, org_unit ou
    WHERE ptr.pa_trnsctn_rqst_sid = pr.pa_trnsctn_rqst_sid
    --AND pr.org_unit_sid = ou.org_unit_sid
    --AND pr.oprtnl_flag = 'A'
    --AND ptr.oprtnl_flag = 'A'
    --AND ou.oprtnl_flag = 'A'
    --AND pr.pa_mode_type_lkpcd = 'BT'
    --AND (pr.status_cid = 86 OR pr.status_cid IN
    (20, 70, 30, 80, 25, 101, 96)
    --AND pr.pa_rqst_sid = 75006271If if you have given join conditions proper and if data exists ,you can see set of rows displayed.
    Next step is to keep on uncommenting each of the where condition
    AND pr.oprtnl_flag = 'A'Like this you 'll come to the condition which does not match your requirement
    Hope this helps
    Regards,
    Achyut

  • Flashback Version Query Does Not Return Rows

    I followed the example given in the documentation; http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_flashback.htm#sthref1478
    but even I connect as sys versions BETWEEN query no rows returns, any comments will be welcomed.
    Thank you,
    Best regards.
    Tonguc
    Test scenerio;
    conn hr/hr
    -- drop table flashback_test purge ;
    create table flashback_test ( c1 number, c2 date ) ;
    insert into flashback_test values ( 1, sysdate ) ;
    commit ;
    update flashback_test set c1 = c1 * 2 ;
    commit ;
    update flashback_test set c1 = c1 * 2 ;
    commit ;
    delete flashback_test ;
    commit ;
    conn sys/passwd as sysdba
    SELECT versions_xid xid,
    versions_startscn start_scn,
    versions_endscn end_scn,
    versions_operation operation,
    c1,
    c2
    FROM hr.flashback_test versions BETWEEN TIMESTAMP minvalue AND maxvalue
    ORDER BY versions_starttime;
    SELECT xid, undo_sql
    FROM flashback_transaction_query
    where undo_sql like '%HR%FLASH%' ;
    The results;
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    Table dropped
    Table created
    1 row inserted
    Commit complete
    1 row updated
    Commit complete
    1 row updated
    Commit complete
    1 row deleted
    Commit complete
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as SYS
    XID START_SCN END_SCN OPERATION C1 C2
    XID UNDO_SQL
    07002A0003010000 update "HR"."FLASHBACK_TEST" set "C1" = '1' where ROWID = 'AAADiFAAEAAAAiXAAA';
    08000E0027010000 insert into "HR"."FLASHBACK_TEST"("C1","C2") values ('4',TO_DATE('04/01/2007', '
    0900080013010000 delete from "HR"."FLASHBACK_TEST" where ROWID = 'AAADiFAAEAAAAiXAAA';
    0A0006000A010000 update "HR"."FLASHBACK_TEST" set "C1" = '2' where ROWID = 'AAADiFAAEAAAAiXAAA';
    Also tried with Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 the same results..
    Message was edited by:
    TongucY

    Hi Tonguc
    I Think there is something wrong with your configuration. If you want i can share the parameter file with you.
    hr@XE> conn hr/hr
    Connected.
    hr@XE> -- drop table flashback_test purge ;
    hr@XE> create table flashback_test ( c1 number, c2 date ) ;
    Table created.
    hr@XE> insert into flashback_test values ( 1, sysdate ) ;
    1 row created.
    hr@XE> commit ;
    Commit complete.
    hr@XE>
    hr@XE> update flashback_test set c1 = c1 * 2 ;
    1 row updated.
    hr@XE> commit ;
    Commit complete.
    hr@XE>
    hr@XE> update flashback_test set c1 = c1 * 2 ;
    1 row updated.
    hr@XE> commit ;
    Commit complete.
    hr@XE>
    hr@XE> delete flashback_test ;
    1 row deleted.
    hr@XE> commit ;
    Commit complete.
    hr@XE> connect sys/password as sysdba
    Connected.
    sys@XE> SELECT versions_xid xid,
    2 versions_startscn start_scn,
    3 versions_endscn end_scn,
    4 versions_operation operation,
    5 c1,
    6 c2
    7 FROM hr.flashback_test versions BETWEEN TIMESTAMP minvalue AND maxvalue
    8 ORDER BY versions_starttime;
    XID START_SCN END_SCN O C1 C2
    07001F0055010000 1038838 D 4 13/03/2007
    02001D0069010000 1038835 1038838 U 4 13/03/2007
    04001F0039010000 1038832 1038835 U 2 13/03/2007
    1038832 1 13/03/2007
    sys@XE> SELECT xid, undo_sql
    2 FROM flashback_transaction_query
    3 where undo_sql like '%HR%FLASH%' ;
    XID
    UNDO_SQL
    02001D0069010000
    update "HR"."FLASHBACK_TEST" set "C1" = '2' where ROWID = 'AAADskAAEAAAAM2AAA';
    04001F0039010000
    update "HR"."FLASHBACK_TEST" set "C1" = '1' where ROWID = 'AAADskAAEAAAAM2AAA';
    07001F0055010000
    insert into "HR"."FLASHBACK_TEST"("C1","C2") values ('4',TO_DATE('13/03/2007', 'DD/MM/RRRR'));
    08002D0074010000
    delete from "HR"."FLASHBACK_TEST" where ROWID = 'AAADskAAEAAAAM2AAA';
    sys@XE> select version from v$instance;
    VERSION
    10.2.0.1.0
    sys@XE>
    init file
    xe.__db_cache_size=415236096
    xe.__java_pool_size=4194304
    xe.__large_pool_size=12582912
    xe.__shared_pool_size=155189248
    xe.__streams_pool_size=8388608
    *.audit_file_dest='C:\oraclexe\app\oracle\admin\XE\adump'
    *.background_dump_dest='C:\oraclexe\app\oracle\admin\XE\bdump'
    *.compatible='10.2.0.1'
    *.control_files='C:\oraclexe\oradata\XE\control.dbf'
    *.core_dump_dest='C:\oraclexe\app\oracle\admin\XE\cdump'
    *.cpu_count=2
    *.db_block_checking='FALSE'
    *.db_name='XE'
    *.DB_RECOVERY_FILE_DEST_SIZE=10G
    *.DB_RECOVERY_FILE_DEST='C:\oraclexe\app\oracle\flash_recovery_area'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=XEXDB)'
    *.job_queue_processes=4
    *.open_cursors=300
    *.os_authent_prefix=''
    *.pga_aggregate_target=335544320
    *.remote_login_passwordfile='EXCLUSIVE'
    *.sessions=20
    *.sga_target=570M
    *.shared_servers=4
    *.undo_management='AUTO'
    *.undo_tablespace='UNDO'
    *.user_dump_dest='C:\oraclexe\app\oracle\admin\XE\udump'
    Message was edited by:
    coskan

  • CONNECT BY query doesn't return any results...

    Hi All
    I am trying to execute this CONNECT BY query...but it does not return any result.
    Could anyone please suggests what am I doing wrong. Or how should I modify the query to get the results.
    SELECT Distinct dt.DID FROM DEPT dt left outer join EMPLOYEE emp on dt.DID = emp.DID WHERE dt.parentid in (SELECT DEPT.DID FROM DEPT CONNECT BY PRIOR DEPT.DID = DEPT.PARENTID START WITH DEPT.PARENTID in (2000,-2000)) or dt.parentid=2000
    Any help would be really really appreciated.
    Thanks and Regards
    -Josef

    Take the nested query and run it in SQL developer (or SQL Plus) against the database directly. Does it give any results? That query returning no results is the most likely cause of the problem.

  • I found out issue distinct clause in query ,refcursor not returning rows

    URGENT
    hi the following procedure returns records  but when i add  distinct clause to (open v_refcursor for select )
    i.e   open v_refcursor for select distinct column1,column2   .......... in the procedure the procedure is not returning records. please help what is the issue here?
    CREATE OR REPLACE procedure proc_shared_report3 (in_cust_id varchar2,in_user_array user_tab , in_acct_array acct_tab,in_report_pvlg_hier varchar2,in_fmt_pvlg_hier varchar2,v_refcursor OUT sys_refcursor)
    is
    BEGIN
    if  in_acct_array.count>0 and in_fmt_pvlg_hier is not null and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null  then
    dbms_output.put_line('all are not null');
    *open v_refcursor for  select usr_id* from vw_get_user_profile where usr_id in (
            SELECT USR_ID FROM VW_GET_ACCOUNTS WHERE USR_ID IN (SELECT distinct up1.usr_id FROM vw_get_user_privileges up1,vw_get_user_privileges up2  WHERE 
            up1.usr_id=up2.usr_id and
            up1.product_hierarchy=in_report_pvlg_hier  and up2.PRODUCT_HIERARCHY=in_fmt_pvlg_hier AND up1.usr_id in (select usr_id from vw_get_user_for_customer where
            cust_id=in_cust_id)
            and up1.usr_id Member Of in_user_array) AND acct_nb Member of in_acct_array);
    /* if account list is null and rest all  not  null */
    elsif (in_acct_array is null or in_acct_array IS EMPTY or in_acct_array.count = 0) and in_fmt_pvlg_hier is not  null  and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null  then
    dbms_output.put_line('acc is null and rest are not null');
    *open v_refcursor for select usr_id,usr_type_cd* from vw_get_user_profile where usr_id in(SELECT  distinct up1.usr_id FROM vw_get_user_privileges up1,vw_get_user_privileges up2  WHERE 
              up1.usr_id=up2.usr_id and
              up1.product_hierarchy=in_report_pvlg_hier and up2.PRODUCT_HIERARCHY=in_fmt_pvlg_hier AND   up1.usr_id in (select usr_id from vw_get_user_for_customer where
              cust_id=in_cust_id)
              and up1.usr_id Member Of in_user_array);
    /* if account list is null and format pvlg hierarchy is null */
    elsif  (in_acct_array is null or in_acct_array IS EMPTY or in_acct_array.count = 0) and in_fmt_pvlg_hier is null and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null
    then
    dbms_output.put_line('acc is null and format is null null');
    *open v_refcursor for select usr_id,tmzon_cd* from vw_get_user_profile where usr_id in (
      (SELECT  distinct usr_id FROM vw_get_user_privileges  WHERE  product_hierarchy=in_report_pvlg_hier  AND   usr_id in (select usr_id from vw_get_user_for_customer where
       cust_id=in_cust_id)
       and usr_id Member Of in_user_array))  ;
    /* if account list is not null and format pvlg hierarchy is  null */
    else  -- If i get only one privilege and all other inputs then 
    dbms_output.put_line('acc list is not null and format pvlg is null');
    *open v_refcursor for select usr_id,prod_shrt_nm* from vw_get_user_profile where usr_id in (
         SELECT USR_ID FROM VW_GET_ACCOUNTS WHERE USR_ID IN (SELECT  distinct usr_id FROM vw_get_user_privileges  WHERE 
         product_hierarchy=in_report_pvlg_hier  AND   usr_id in (select usr_id from vw_get_user_for_customer where
         cust_id=in_cust_id) and usr_id Member Of in_user_array ) AND acct_nb Member of in_acct_array);
    END IF;
    END proc_shared_report3;
    /Edited by: raj_fresher on Aug 12, 2009 8:50 AM
    Edited by: raj_fresher on Aug 12, 2009 1:40 PM

    its like this ...... ?
    You have to understand that without any testdata/ a reproducable testcase, all I can do is asking you to test some alternatives, I'm just guessing things from what I can make of your example, and hope you'll repost back any differences in a clear and concisive way.
    What I didn't understand is why you're not just joining your tables/views instead of using inner queries.
    Unfortunatly you're not providing any feedback on that, on the other hand you've narrowed down your problem to a specific part of your query? But you're not sharing why/what makes you decide to take that turn.
    But: you're still using inner queries in your reply.
    So, sorry, I cannot proceed/say anything useful unless you answer my previous post.
    Because, there are still many other questions/doubts: I don't understand why you're not aliasing your columns properly, for example.
    I don't know why you've suddenly switched to VW_GET_USER_cust_sa?
    I don't know if you've tried the straight join instead of nesting queries?
    And if you did, what's the problem?
    Please read and understand this, so you'll get your answers by the speed of light the next time you've got a question or problem:
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    And don't refrain from using that tag ;)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Nested query doesn't return result

    Using CF 8.1.  First field in table is "item" which is a compound filed containing a five digit customer number, a space, then a six digit item number.  I need to produce a list of items for a specific customer based on their customer number, which is stored in a session variable. That part of my code all works. However, inside the output I need to retreive the item pack size from another table. This part of my code isn't working (QryAddInfo). Code pasted below. I'm wondering if it's because I'm trying to have a third query or that it is inside an output???
              <cfquery name="QryGetInfo" datasource="necsodbc">
              SELECT custnoitem, descrip, descrip4, lastdate
              FROM arcpric
              ORDER BY custnoitem
              </cfquery>
             <cfquery name="GetItems" dbtype="query">
              SELECT *
              FROM QryGetInfo
              WHERE #left(QryGetInfo.custnoitem, 5)# = #session.MemberID#
              ORDER BY custnoitem
              </cfquery>
    <body>
    <div align="center">
    <br /><br />
    Standard Order <cfoutput>#session.MemberID#</cfoutput>
    <br /><br />
    <table cellpadding="2">
    <tr>
    <td>ITEM</td>
    <td>DESCRIPTION</td>
    <td>PACK</td>
    <td>ITEM<br /> COMMITMENT</td>
    <td>QTY</td>
    <td>LAST<BR />ORDERED</td>
    </tr>
    <cfoutput query="QryGetInfo">
    <CFIF #left(QryGetInfo.custnoitem, 5)# eq #session.MemberID# AND #MID(QryGetInfo.custnoitem, 7,6)# LT 900000>
    <TR height="22">
    <TD>#MID(QryGetInfo.custnoitem, 7,6)#</TD>
    <TD align="left">#QryGetInfo.DESCRIP#</TD>
    <td>
    <cfquery name="GetAddInfo" datasource="necsodbc">
    SELECT SIZE
    FROM ARINVT01
    WHERE ITEM = '#MID(QryGetInfo.custnoitem, 7,6)#'
    </cfquery>
    #GetAddInfo.size#
    </td>
    <TD align="left">
    <div align="center">
    <cfif ASC(left(QryGetInfo.DESCRIP4,2)) NEQ 32>
    YES
    </cfif>
    </div>
    </TD>
    <TD width="25"> </TD>
    <TD>#QryGetInfo.LASTDATE#</TD>
    </TR>
    </CFIF>
    </cfoutput>
    </table>
    </div>
    </body>

    Thanks for all your suggestions Dan. Though they weren't the answer, it made me question the validity of the ITEM field in the second table. Upon checking with the programmers of the application I found the field was padded with spaces. Which is why nothing matched. Your suggestion on substr was also close, but not quite. Here is what I came up with to produce the desired results.
              <cfquery name="QryGetInfo" datasource="necsodbc">
              SELECT custnoitem, descrip, descrip4, lastdate
              FROM arcpric
              ORDER BY custnoitem
              </cfquery>
    <body>
    <div align="center">
    <br /><br />
    Standard Order <cfoutput>#session.MemberID#</cfoutput>
    <br /><br />
    <table cellpadding="2">
    <tr>
    <td>ITEM</td>
    <td>DESCRIPTION</td>
    <td>PACK</td>
    <td>ITEM<br /> COMMITMENT</td>
    <td>QTY</td>
    <td>LAST<BR />ORDERED</td>
    </tr>
    <cfoutput query="QryGetInfo">
    <CFIF #left(QryGetInfo.custnoitem, 5)# eq #session.MemberID# AND #MID(QryGetInfo.custnoitem, 7,6)# LT 900000>
    <TR height="22">
    <TD>#MID(QryGetInfo.custnoitem, 7,6)#</TD>
    <TD align="left">#QryGetInfo.DESCRIP#</TD>
    <td>
          <cfquery name="GetSize" datasource="necsodbc">
              SELECT item, size
              FROM arinvt01
              WHERE left(item, 6) = '#MID(QryGetInfo.custnoitem, 7,6)#'
              </cfquery>
              #GetSize.size#
              </td>
    <TD align="left">
    <div align="center">
    <cfif ASC(left(QryGetInfo.DESCRIP4,2)) NEQ 32>
    YES
    </cfif>
    </div>
    </TD>
    <TD width="25"> </TD>
    <TD>#QryGetInfo.LASTDATE#</TD>
    </TR>
    </CFIF>
    </cfoutput>
    </table>
    </div>
    </body>

  • Query doesn't return results.

    Hi all,
    currently I face strange behavior and before I going to raise possible incident want to check if I haven't forgot something.
    Use case: I created for my custom BO OVS screen. By default there is used QueryByElements query. Unfortunately it's not possible search through OVS results. That way I tried to create SADL query where I specified basic search fields. When I replaced this search I couldn't get anymore list of BOs records. So I tried to create new query for my BO. I rebound all fields to this Overview node, bound query, but again no results in OVS, when I bounded back default QueryByElements results ar displayed.
    Has anyone faced similar behavior?
    Thanks,
    Uldis

    hi Uldism I am facing similar issue!
    did u get any solution?

  • Query with subquery containing group clause doesn't return any rows - WHY ?

    Hi,
    My query doesn't return any values :
    select g1.NTRX from gtrx g1
    where exists
    (SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
    b.dltimtrx, b.nrtrftrx,count(*)
    FROM gtrxacq a, gtrx b
    WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
    FROM gmbr
    WHERE nmbr = 0)
    and g1.NTRX=b.NTRX
    GROUP BY b.cfunctrx,
    b.cpro1trx,
    b.nmsgitrx,
    b.nmrc,
    b.ncrd,
    b.namtstrx,
    b.dltimtrx,
    b.nrtrftrx
    HAVING COUNT (*) > 1);
    but such query returns some number of rows :
    SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
    b.dltimtrx, b.nrtrftrx,count(*)
    FROM gtrxacq a, gtrx b
    WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
    FROM gmbr
    WHERE nmbr = 0)
    /*and g1.NTRX=b.NTRX*/
    GROUP BY b.cfunctrx,
    b.cpro1trx,
    b.nmsgitrx,
    b.nmrc,
    b.ncrd,
    b.namtstrx,
    b.dltimtrx,
    b.nrtrftrx
    HAVING COUNT (*) > 1
    AND when i put results from query above into query :
    select g1.NTRX from gtrx g1
    where
    g1.CFUNCTRX= 200 and g1.CPRO1TRX= 000 and g1.NMSGITRX= 1240 and
    g1.NMRC= '000000000000675' and g1.NCRD= 405671**********
    and g1.NAMTSTRX=14.26 and g1.DLTIMTRX=to_date('07/08/2008 15:07:02','MM/DD/YYYY HH24:MI:SS')
    and g1.NRTRFTRX= '000414598393';
    it returns values.
    what is wrong ?
    Best Regards Arkadiusz Masny

    but such query returns some number of rows :
    /*and g1.NTRX=b.NTRX*/Add b.NTRX into group by and recheck.

  • Is the order in which a UNION ALL query returns rows guaranteed?

    Guys
    I'm doing a kind of query where I want to return matching rows in a priority order and take the first one. THink of it as getting the most specific error message for a particular context.
    SELECT * FROM (
    SELECT msg FROM errormessages WHERE device = 'x'
    UNION ALL
    SELECT msg FROM errormessages WHERE client = 'y'
    UNION ALL
    SELECT msg FROM (SELECT msg from errormessages WHERE class LIKE 'generic_' ORDER BY class)
    UNION ALL
    SELECT 'missing error message' FROM dual
    WHERE ROWNUM =1
    If UNION ALL is guaranteed to return rows in this order, great. If not, would it be better to have:
    SELECT * FROM ( SELECT * FROM(
    SELECT 1 as ord, msg FROM errormessages WHERE device = 'x'
    UNION ALL
    SELECT 2, msg FROM errormessages WHERE client = 'y'
    UNION ALL
    SELECT 4+SUBSTR(class, 7, 1), msg FROM errormessages WHERE class LIKE 'generic_'
    UNION ALL
    SELECT 9999, 'missing error message' FROM dual
    ) ORDER BY ord )
    WHERE ROWNUM =1Or, another option:
    SELECT msg FROM(
    SELECT
      CASE
        WHEN device = 'x' THEN 1
        WHEN client = 'y' THEN 2
        WHEN class LIKE 'generic_' THEN 4+SUBSTR(class, 7, 1)
      END as ord, msg
    FROM (
      SELECT * FROM errormessages WHERE device = 'x' OR  client = 'y' OR class LIKE 'generic_'
      UNION ALL
      SELECT 999, 'missing error' FROM dual
    ) ORDER BY ord
    )WHERE ROWNUM =1As you can see there is a complication in the generic; devices may advertise that they accept 1,2,3 or 4 lines of info, so I want to use the advertised capabiltiy to pick the most relevant message from the generic set if no specifics exist for the device or the client
    Which was would you go?
    Cheers
    Edited by: charred on Feb 11, 2009 4:56 AM - code tags

    charred wrote:
    So tell me guys, do I go for:
    4 queries unioned together
    or
    1 query with 4 ORs in the where clause and a case when to determine priority?It will depend on your conditions, but if you look at your explain plans you should get an idea for which is the better one; typically I would expect this to be the OR method...
    SQL> select * from emp where deptno = 20
      2  union all
      3  select * from emp where job = 'CLERK'
      4  union all
      5  select * from emp where sal > 2500;
    Execution Plan
    Plan hash value: 3153085224
    | Id  | Operation                    | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |          |    14 |   546 |     8  (75)| 00:00:01 |
    |   1 |  UNION-ALL                   |          |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| EMP      |     5 |   195 |     2   (0)| 00:00:01 |
    |*  3 |    INDEX RANGE SCAN          | DEPT_IDX |     5 |       |     1   (0)| 00:00:01 |
    |*  4 |   TABLE ACCESS FULL          | EMP      |     4 |   156 |     3   (0)| 00:00:01 |
    |*  5 |   TABLE ACCESS FULL          | EMP      |     5 |   195 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("DEPTNO"=20)
       4 - filter("JOB"='CLERK')
       5 - filter("SAL">2500)
    Statistics
              1  recursive calls
              0  db block gets
             18  consistent gets
              1  physical reads
              0  redo size
           1328  bytes sent via SQL*Net to client
            396  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
             14  rows processed
    SQL> select * from emp
      2  where deptno = 20 or job = 'CLERK' or sal > 2500;
    Execution Plan
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    10 |   390 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |    10 |   390 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DEPTNO"=20 OR "SAL">2500 OR "JOB"='CLERK')
    Statistics
              1  recursive calls
              0  db block gets
              8  consistent gets
              0  physical reads
              0  redo size
           1146  bytes sent via SQL*Net to client
            396  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              9  rows processed
    SQL>

  • Minus query returning row

    Hi
    One of my sql minus query is returning row even though both the statements are having same value.
    My query is following :
    SELECT UNIQUE EMP_AGG_DW_PAYROLL_TOT_FTE_CNT,EMP_AGG_PAY_DEM_EMP_SKEY
    FROM DW.AGG_EMP_ACCT_COMPENSATIONS
    WHERE EMP_AGG_DW_EFF_START_DT='1-jan-2006'
    AND EMP_AGG_PAY_DEM_EMP_SKEY IN (133607,141955)
    MINUS
    select * from (
    SELECT SUM(CS),PAY_DEM_EMP_SKEY FROM (
    SELECT SUM(CP)/24 CS,PAY_DEM_EMP_SKEY FROM (
    SELECT COUNT(PAY_DEM_DW_PAYROLL_FTE_COUNT) CP,PAY_DEM_EMP_SKEY FROM
    DW.PAYROLL_DEMOGRAPHICS A,MRADMIN_PROFPROCDT MP
    WHERE PAY_DEM_DW_PAYROLL_FTE_COUNT=1
    AND PAY_DEM_DW_PAYROLL_ADJUST_IND = 0
    AND PAY_DEM_EMP_SKEY IN (133607,141955)
    AND (TRUNC(A.PAY_DEM_PAY_DT) BETWEEN TRUNC(MP.D_BEGIN_DATE)
    AND TRUNC(MP.D_END_DATE))
    GROUP BY PAY_DEM_EMP_SKEY)GROUP BY PAY_DEM_EMP_SKEY
    UNION ALL
    SELECT SUM(CP)/48 CS,PAY_DEM_EMP_SKEY FROM (
    SELECT COUNT(PAY_DEM_DW_PAYROLL_FTE_COUNT) CP,PAY_DEM_EMP_SKEY FROM DW.PAYROLL_DEMOGRAPHICS
    WHERE PAY_DEM_DW_PAYROLL_FTE_COUNT=.5
    AND PAY_DEM_DW_PAYROLL_ADJUST_IND = 0
    AND PAY_DEM_EMP_SKEY IN (133607,141955)
    GROUP BY PAY_DEM_EMP_SKEY)GROUP BY PAY_DEM_EMP_SKEY )
    GROUP BY PAY_DEM_EMP_SKEY
    This is returning two rows.
    When I run queries seperatly then i am getting following result :
    EMP_AGG_DW_PAYROLL_TOT_FTE_CNT     EMP_AGG_PAY_DEM_EMP_SKEY
    0.0416666666666667                133607
    0.0416666666666667                    141955
    SUM(CS)          PAY_DEM_EMP_SKEY
    0.0416666666666667 133607
    0.0416666666666667     141955
    I am unable to get the exact reason behind me.
    Any help is higly appreciated.

    Probably some differences that are not shown due to rounding as in example below?
    SQL> set numw 5
    SQL> select 1.666666666666 from dual;
    1.666666666666
             1,667
    Elapsed: 00:00:00.00
    SQL> select 1.666666 from dual;
    1.666666
       1,667
    Elapsed: 00:00:00.00
    SQL> select 1.666666666666 from dual
      2  minus
      3  select 1.666666 from dual;
    1.666666666666
             1,667
    Elapsed: 00:00:00.00
    SQL> Gints Plivna
    http://www.gplivna.eu

  • Query with XMLTABLE returns null rows

    Hello all,
    I'm trying a query with XMLTABLE, but even thought the number of returned rows is correct, the row content is (null).
    DB version is: 10.2.0.4.0
    Here is my query;
    SELECT s.DESCRIPTION
    FROM EXECUTIONPLAN p,
      XMLTABLE
      ('//executionPlan/executionPlanItems/summary'  
       PASSING p.DATA
       COLUMNS
         DESCRIPTION VARCHAR(250) PATH '/taskId'
      ) s
    WHERE
    trunc(extractValue(data, '/executionPlan/executionPlanHeader/statusChanged')) = to_date('2010-03-05','YYYY-MM-DD');Sorry the XML content is quite big -50k lines at average- so can't post the whole XML, but to give an idea;
    /executionPlan
       /executionPlan
          /executionPlanHeader
             /statusChanged
             /x
             /y
          /executionPlanItems
             /summary
                /taskId
             /summary
             /summary
             ...The result looks like;
    1 (null)
    2 (null)
    3 (null)
    4 (null)
    ...Suggestions are very much appreciated :)
    Cheers

    Hi guys,
    Cracked it at last. It seems the column definition part does not like the forward slash in front of it. The following works;
    SELECT s.DESCRIPTION
    FROM EXECUTIONPLAN p,
      XMLTABLE
      ( XmlNamespaces(DEFAULT 'http://www.staffware.com/frameworks/gen/valueobjects'),
       '/executionPlan/executionPlanItems/summary'  
       PASSING p.DATA
       COLUMNS
         DESCRIPTION VARCHAR(250) PATH 'taskId'
      ) s
    WHERE
    trunc(extractValue(p.data, '/executionPlan/executionPlanHeader/statusChanged'
                             , 'xmlns="http://www.staffware.com/frameworks/gen/valueobjects"')) = to_date('2010-03-05','YYYY-MM-DD');I'm not sure if this is the way it is intended since it seems a bit weird to me and is not in line with the docs - or at least my understanding of them.
    Thanks for taking the time to help out. Now on to coding :)

  • SQL query doesn't work in VB program

    Hi:
    The following SQL query doesn't work into a VB program, I'm using Oracle OLEDB to established connection to the DB, ... the query returns 0 rows ...
    When I run this same query from any SQL Plus, works well (returning me something like 119 rows) ...
    Any clue or hint ??
    Thanks in advanced
    Angel Castro
    SELECT OPERADOR, ID_ALIMENTADOR, RB_FSC, NUM_CTROL, COND_OPERA, TRANSITORIO, PENDIENTES, ANORMAL, EDO_REAL, IDENTIFICADOR, CAUSA
    FROM HISTORICO_OPERACION
    WHERE (FECHA BETWEEN '20-AUG-2004' AND '5-NOV-2004')
    AND (HORA BETWEEN '10:00:00' AND '16:00:00')
    ORDER BY ID_ALIMENTADOR ASC;

    Is the column FECHA of datatype DATE?
    Are you running the query with the constant date looking like strings ('20-AUG-2004' in your post, for example) as-is from the VB program?
    If not, are you binding the parameters correctly?
    What is the setting of your NLS_DATE_FORMAT parameter?
    What happens if you do a
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'from your VB program before running the query?

  • VO returning rows though where clause is set to 1=2

    Hi,
    I have a method in AMImpl class with following code
    public void reset()
    testVO vobj = gettestVO1();
    vobj.setwhereclause("1=2");
    vobj.executeQuery() ;
    System.out.println("Query ="+vobj.getQuery().toString());
    System.out.println("Fetched Row Count = "+vobj.getFetchedRowCount());
    System.out.println("Row Count = "+vobj.getRowCount());
    And I'm calling this method from Process Form request method on click of a submit button. When I run the page and click on the button the sop messages shows fetched row count = 2 and row count = 2. But if I execute the query that i got from the sop in sql developer it doesn't returns any rows.
    I'm trying to make the vobj return no rows.
    Can anyone please tell me what is going wrong.
    Thanks
    Sunny

    Hi Gyan,
    I'm getting the same query before and after executing. And here is it.
    SELECT XXCEDPmtRqstLineEO.SUNDRY_LISTING_NUMBER, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_NUMBER, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_PAYEE, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_DESC, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_ADDR, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_CITY, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_STATE, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_ZIP, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_PROJECT, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_TASK, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_EXP_TYPE, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_AMOUNT, XXCEDPmtRqstLineEO.SUNDRY_REQUEST_LINE_ORG, XXCEDPmtRqstLineEO.TIN, XXCEDPmtRqstLineEO.CREATED_BY, XXCEDPmtRqstLineEO.CREATION_DATE, XXCEDPmtRqstLineEO.LAST_UPDATE_DATE, XXCEDPmtRqstLineEO.LAST_UPDATED_BY, XXCEDPmtRqstLineEO.LAST_UPDATE_LOGIN FROM XXCED_AP_SUNDRY_PMT_RQST_LINE XXCEDPmtRqstLineEO WHERE (1=2)
    the row count still shows as 2.
    Thanks
    Sunny

  • Thread-safe and performant way to return rows and then delete them

    Hi all
    I have a table containing rows to be processed by Java. These rows need to be returned to Java, then they willl be processed and sent to a JMS queue, then if that JMS operation is successful they need to be deleted from the Oracle table..
    The current method is:
    Java calls Oracle SP with 'numrows' parameter.
    Oracle SP updates that number of rows in the table with a batch ID from a sequence, and commits.
    Oracle SP returns the Batch_ID to Java.
    Java then selects * from table where batch_id = XXXX;
    Java sends messages to JMS. If JMS transaction is OK, Java deletes from table where batch_Id =xxxx and commits;
    Clearly this isn't very efficient. What I would like to do is this:
    Java calls Oracle SP with 'numrows' parameter
    Oracle SP returns that many rows in a cursor and deletes them from the table simultaneously. Oracle SP does not open a new transaction - transaction is controlled from JAva.
    Java writes to JMS. If JMS is OK, Java commits its DB transaction and thus the rows are deleted.
    Therefore there's only a single DML operation - a DELETE.
    The trouble is, this is not threadsafe - if I have two Java threads calling the Oracle SP, then thread #2 may return rows that thread #1 already got - because thread#1 has not yet committed its delete, and thread#2 can select those rows. Thread#2 will then lock waiting to delete them until thread#1 has finished its delete, then thread#2 will get "0 rows deleted". But Java will stlil have been sent those rows.
    How can I engineer this method to be as efficient as possible while still being threadsafe? The key problem I'm having is that the DELETE operation doesn't prevent the rows being SELECTed by other threads - if there was a way to DELETE without committing but also immediately make those rows unavailable to other threads, that would work I think.
    Any help much appreciated
    Tom

    Hi Tom,
    You forgot to "mention" your version.
    I'm not sure, but I believe [SKIP LOCKED|http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702] is safe to use. At least in 11.1. (I have used in both 9i and 10g where it was unsupported/undocumented)
    There is of course always the boring way: A single thread.
    Regards
    Peter

Maybe you are looking for

  • A problem with threads

    I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be ab

  • Why my iTunes re-open when i close it?

    Sorry for my bad english. do not know why but my iTunes is opened again and again when I close it.  how I could solve this problem????  pls i need help with this is very annoying. Thanks.

  • JSP implementation class for a JSP Page

    Hello, It is very important for me to know ... - Do you consider that a JSP developer should know that each JSP Page becomes at run-time a Java Servlet ? And int the way that the Java code you have wrote in the JSP Page is dispatched in the declarati

  • Address Book duplicates

    Each time I restart Address Book seems to be duplicating <Apple> address. At one time there were over 7,000 exact duplicates of Apple Computer Inc. What am I doing wrong?

  • Has anyone ever been quoted more than $500 to replace a failed logic board?

    Has anyone ever been quoted more than $500 to replace a failed logic board? A Genius buddy of mine swears that it'll never be over $500 but I' convinced he's high out of his mind.