Incorrect result with SQL query

Dear all,

When I run the following query, it should return 55 but returning 24 instead of 55.

Select TO_CHAR (TO_DATE (April 25, 2009 ',' MON-DD-YYYY'), 'JJ')
-TO_CHAR (TO_DATE ('01 - MAR - 2009 "," DD-MON-YYYY '), 'DD') DAYS OF DOUBLE;

Can help any one on this?

Thank you

As you use the wrong data type for arithmatic operations.

SQL> select TO_DATE('25-APR-2009', 'DD-MON-YYYY') - TO_DATE('01-MAR-2009', 'DD-MON-YYYY')  DAYS FROM DUAL;

      DAYS
----------
        55

Never compare strings as dates.

Tags: Database

Similar Questions

  • Help with SQL query for SQL experts!

    Hi all

    For the very expert on SQL.

    ------------------

    create table t1 (STEP number);

    Insert into t1 select rownum from dba_tables where rownum < 11;

    commit;

    create table t2 (the STEP number, name varchar2 (4), varchar2 (1)) of the State;

    insert into t2 values (1, 'TOTO', ' A');

    insert into t2 values (3, 'TOTO', 'C');

    insert into t2 values (4, 'TOTO', ');

    insert into t2 values (1, 'FIFI', ' A');

    insert into t2 values (6, 'FIFI', 'B');

    commit;

    ----------------

    My goal is to list the STATE in the NAME of all the STEPS, even if measures do not exist for a NAME.

    In other words, my query should return a result like this: (query on t1 and t2, of course)

    STEP   1      2             3            4               5            6

    TOTO A C D NO NO NO

    FIFI HAS NO NO NO NO D

    Thank you in advance.

    with the data as)
    Select
    T1. Step step
    name
    State
    Of
    T1, t2
    where
    T1. Step = T2. Step (+)
    )

    Select
    *
    from the data
    Pivot (max (state))
    for step (1,2,3,4,5,6,7,8,9,10)
    )
    where the name is not null

    NAME 1 2 3 4 5 6 7 8 9 10
    TOTO A - C D - - - - - -
    FIFI A - - - - B - - - -

    If the column name must be the stage instead of the name

    with the data as)
    Select
    Step 1 T1. Step
    name as step
    State
    Of
    T1, t2
    where
    T1. Step = T2. Step (+)
    )

    Select
    *
    from the data
    Pivot (max (state))
    for step 1 in (1,2,3,4,5,6,7,8,9,10)
    )
    where the step is not null

  • Help with SQL Query (Subselects)

    Hello community,

    IAM a new Member in this forum. The first excuse my English, my native language is German.
    In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
    I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.

    In this case, I have 2 tables:
    Table 1:
    ID; ORDER_NR; DESCRIPTION; CREATE_DATE
    1; A500236; CLEAN HOUSE; 20/02/2012
    2; A623555; REPAIR CAR; 10/01/2012
    3; A866944; MAINTAIN EQUIPMENT; 11/02/2012

    Table 2:
    ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
    1; A500236; A; 21/02/2012; W0010
    2; A500239; F; 21/02/2012; W0010
    3; A500239; S; 22/02/2012; W0027
    4; A500239; R; 23/02/2012; H0034
    5; A500239; U; 25/02/2012; L0099
    6; A263555; A; 15/01/2012; G0009
    7; A263555; C; 17/01/2012; S0039
    5 V A263555; R; 18/01/2012; K0059
    9; A263555; U; 19/01/2012; A0048
    10; A866944; A; 13/02/2012; H0034
    11; A866944; B; 13/02/2012; L0035
    12; A866944; G; 17/02/2012; D0084
    13; A866944; U; 23/02/2012; S0039

    And the result of my query should look like this:
    ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
    A500236; OWN HOME; 20/02/2012; 5; 3; 1
    A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
    A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3

    The age of my query result should be calculated from the date of the creation of the order.
    I would like to know 2 things, one is how old was the order when they reached this status, R and U.
    The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
    It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column

    I hope you all know what I mean and what result to expect.

    Thanks for your help.

    Reinhard W.

    Hi, Reinhard,

    990524 wrote:
    Hi Frank,.

    I thank you for your professional response and excuse my non-professional way to clarify my question.
    I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?

    You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
    All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.

    I have already noticed that the syntax SQL for Oracle differ from other DBMSS.

    Yes and some features are different in different products.

    Your query works perfectly, thank you.

    Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.

    Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.

    My table contains the Date and time in a row, I forgot to mention that.

    After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.

    I tried something like this:

    SYSDATE - MIN ( CASE
                        WHEN  t2.wo_step = 'A'
                  THEN  t2.step_date
              END
               ) AS Age_A
    

    But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.

    There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.

  • Help me with SQL Query to retrieve data from a view

    Hello Guru,

    I need help in my sql query.
    I use SQL TeraData.
    I want an Oracle result in the following form-

    Open tickets
    Open months failure / Repair Service s/o improvement request Total general
    2009-01-2 4 4 5 15
    2009-02 1 0 2 3 6
    2009-03 4 1 2 2 9
    Grand Total 7 5 8 10 30


    I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.

    Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
    COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
    FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
    WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
    AND (CASE
    WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
    WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
    WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
    END) = 1
    GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)

    After executing the query, I get the following error:
    3076: syntax Error: Data Type 'Time' does not match a defined Type name.
    :( Kindly help me with this and let me know where I'm wrong... Please.

    Messages indicates something wrong with your data... It would seem that the data does not match your format mask.

    Thus, the data or the format mask.

  • getting bad results with a query

    I have a column with the VARCHAR2 data type name (2) into a table and another table with a column named OFFICER_ZONE with the VARCHAR2 data type (1). What I'm trying to do is to compare these data and then insert it in the second table. But before you insert the data, if the AREA is equal to a number in double digits with a zero in front of her, then I need to CUT 0. If the BOX has a number greater than 9, then I have just these values to NULL. With the query below, I get the upper to 9 zones to be null, which is correct, but I also have those who are the two numbers with a zero not significant, which is not correct.

    For example:
    Area
    1
    2
    5
    07
    15
    19
    14
    6
    02
    d
    c
    e
    b

    Results:
    Bad area: 07
    Bad box: 15
    Bad area: 19
    Bad box: 14
    Bad area: 02

          --ZONE BAD DATA
          IF CR.ZONE NOT IN ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
              'v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
              '0','1','2','3','4','5','6','7','8','9')
          THEN
              V_OFFICER_ZONE := NULL; 
              DBMS_OUTPUT.PUT_LINE('ZONE NOT VALID:'||CR.LOCCASENUM||CR.ZONE);
              insert into pursuits.pursuit_exception(case_number,table_name,error_message)
              values(cr.loccasenum,'PURSUIT','Bad Zone: '||v_officer_zone||','||cr.zone);
          ELSE
              V_OFFICER_ZONE := TRIM(LEADING 0 FROM CR.ZONE);
          END IF;
    with t as (
               select '1' zone from dual union all
               select '2' from dual union all
               select '5' from dual union all
               select '07' from dual union all
               select '15' from dual union all
               select '19' from dual union all
               select '14' from dual union all
               select '6' from dual union all
               select '02' from dual union all
               select '0' from dual union all
               select '00' from dual union all
               select 'd' from dual union all
               select 'c' from dual union all
               select 'e' from dual union all
               select 'b' from dual
              )
    select  zone,
            case
              when length(zone) = 1
                then zone
              when zone between '00' and '09'
                then substr(zone,2)
              else null
            end officer_zone
      from  t
    /
    
    ZONE OFFICER_ZONE
    ---- ------------
    1    1
    2    2
    5    5
    07   7
    15
    19
    14
    6    6
    02   2
    0    0
    00   0
    
    ZONE OFFICER_ZONE
    ---- ------------
    d    d
    c    c
    e    e
    b    b
    
    15 rows selected.
    
    SQL> 
    

    SY.

  • How do I get the data of "Regulatory BOM" Formulation with SQL query output

    Hello

    We would like to implement a State of BiPublisher that displays "Regulation BOM" (wording-> click on TAB Formulation on exit Popup-> TAB Composition) information table.

    How could get us this information with an SQL query?

    Thank you

    Annarosa

    Hi, given 'Regulatory BOM' output of the Formulation are more complicated than expected. Attached is an example. You can test and make the appropriate changes to your report.

  • need help with sql query dates

    Hello

    I have a sql query I need to extract some info between data dates. Where clause in this query is:

    WHERE CPD_BUS_UNIT =: ESI_PRM_1
    AND CPD_VOUCHER_DATE > =: P_DATE_FROM
    AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).

    When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
    But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.

    Please suggest how to rewrite the query.

    Can you please give it a try?

    WHERE CPD_BUS_UNIT=:ESI_PRM_1
    AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM)
    AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1) 
    

    Concerning

  • Need help with sql query

    Dear all,

    I have a sql like query below

    SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER

    MTL_TXN_REQUEST_HEADERS D,.

    MTL_TXN_REQUEST_LINES, E.

    MTL_MATERIAL_TRANSACTIONS G,.

    Mtl_Transaction_Types I have

    WHERE D.HEADER_ID = E.HEADER_ID

    AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID

    AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')

    AND E.LINE_ID = G.MOVE_ORDER_LINE_ID

    AND D.MOVE_ORDER_TYPE = 5

    TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')

    D.REQUEST_NUMBER GROUP

    I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.

    above query is back under results

    results.jpg

    If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.

    so in the example above, it must return

    FIRST REQUEST NUMBER LAST NUMBER

    2383                                      1886

    Thank you

    select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min
         , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max
      from (
            select min(g.transaction_date) transaction_date
                 , d.request_number
              from mtl_txn_request_headers d
                 , mtl_txn_request_lines e
                 , mtl_material_transactions g
                 , mtl_transaction_types i
             where d.header_id                    = e.header_id
               and g.transaction_type_id          = i.transaction_type_id
               and upper(i.transaction_type_name) = upper('WIP Issue')
               and e.line_id                      = g.move_order_line_id
               and d.move_order_type              = 5
               and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014')
             group
                by d.request_number
           )
    
  • Need help with SQL Query - change of name history of audit table.

    I need your help to find the result in the following way...


    Emp No    New_name    Old_Name
    -----------------------------------------------
    1           Name3        Name2
    1           Name2        Name1
    create table emp(emp_id number(10),
    emp_name varchar(50),
    constraints emp_pk primary key(emp_id) );
    
    
    
    create table emp_audit(
    audit_id number(10),
    emp_id number(10),
    emp_name varchar(50),
    audit_date date,
    constraints emp_audit_pk primary key (audit_id),
    constraints  emp_audit_emp_fk foreign key(emp_id)  references emp(emp_id));
    
    insert into emp values(1,'Name3');
    
    
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy'));
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy'));
    commit;
    Thank you...

    Dipabkar Bédard (DB) wrote:

    We write is the query without using "partition by" in oracle...?

    with t as (
               select  audit_id,
                       emp_id,
                       emp_name,
                       row_number() over(order by audit_id) rn
                 from  emp_audit
                 order by emp_id,
                          audit_id
              )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t a left join t b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ------------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    And without analytical functions:

    with t1 as (
                select  audit_id,
                        emp_id,
                        emp_name
                  from  emp_audit
                  order by emp_id,
                           audit_id
               ),
         t2 as (
                select  audit_id,
                        emp_id,
                        emp_name,
                        rownum rn
                  from  t1
               )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t2 a left join t2 b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ----------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    SY.

  • The Variable value based on the results of SQL query

    With the help of OBIEE 11.1

    Is it possible to set the value of a variable presentation of the results of a SQL statement?

    Scenario:

    I have 2 topics.

    SubjectArea1

    Text1

    Date1

    SubjectArea2

    Field1

    Field2

    UpdateDate

    I have an analysis that uses only the SubjectArea2.

    Using a dashboard quickly, the user must be able to select Text1 in the other topic area (SubjectArea1).

    Assuming that selection will be stored in a variable of presentation (SelectedText),

    The filter in the analysis should be something like

    Upper UpdateDate to @{SelectedDate}

    How can I set a variable (SelectedDate) using a SQL statement?

    Something like this:

    SELECT "Date1" TO "SubjectArea1" WHERE "Text1" = @{SelectedText}

    So the command prompt text selection should give a date that is used to filter the second review?

    If so:

    The prompt on SA1.textCol

    hidden analysis who is invited on SA1.texCol has SA1.dateCol in the criteria

    Analysis SA2.dateCol is filetered on basis of the results of another analysis (any value analysis hidden SA1.dateCol)

  • Need help with sql query performance

    Dear all,

    I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.

    Select rownum LINE_NUM,

    A.LINE_ID,

    TO_CHAR (A.INVITMID),

    TO_NUMBER (A.PICKQTY),

    UNLOADINGPNT NULL,

    RRNUM NULL,

    WORKORDNUM NULL,

    WORKORDDESC NULL,

    A.PONUM,

    DTR_DUMB NULL,

    A.DESCRIPTION,

    FROM_SUB NULL,

    TO_SUB NULL,

    NO SOURCE,

    ASSET_NUMBER NULL,

    A.RECEIPTNUM,

    MOVEORD NULL,

    FROM_LOC NULL,

    TO_LOC NULL,

    MSD_NUM NULL,

    CONTAIN_LINE NULL,

    A.UOM,

    A.PO_RELEASE

    de)

    Select headerid Po.Po_Header_Id,

    rcv1. Po_Line_Id LINE_ID,

    rcv1.item_id INVITMID,

    (NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,

    Po.Segment1 PONUM,

    Rcv1.Receipt_Num RECEIPTNUM,

    Rcv1.Item_Desc DESCRIPTION,

    Rcv1.Transact_Uom GLU,

    Rcv1.Po_release

    Po_Headers_All in.,.

    (Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "EXPENSES".

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    UNION ALL

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND B.ITEM_ID IS NULL

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "WORKSHOP".

    D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3

    GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),

    (SELECT A.PO_LINE_ID,

    Sum (A.Quantity) transact_qty,

    A.PO_HEADER_ID,

    C.RECEIPT_NUM

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2

    Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)

    And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)

    And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)

    And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)

    Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has

    Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Please find the attached PLAN to EXPLAIN.

    EXPLAINPLAN.jpg

    Thank you

    May be essentially the same join (between a, b, c and d) twice instead of three times

    sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2

    We can work on what we can see only

    Select rownum line_num,

    rcv1.po_line_id line_id,

    TO_CHAR (rcv1.item_id) invitmid,

    NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,

    unloadingpnt null,

    rrnum null,

    workordnum null,

    workorddesc null,

    Po. Ponum Segment1,

    dtr_dumb null,

    description of the rcv1.item_desc,

    from_sub null,

    to_sub null,

    No source,

    asset_number null,

    rcv1.receipt_num receiptnum,

    moveord null,

    from_loc null,

    to_loc null,

    msd_num null,

    contain_line null,

    Glu rcv1.transact_uom,

    rcv1.po_release

    of po_headers_all in.

    left outer join

    (select a.po_header_id,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description item_desc,

    a.unit_of_measure transact_uom,

    Sum (a.Quantity) transact_qty,

    d.release_num po_release

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    po_line_id,

    destination_type_code,

    unit_of_measure,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "to DELIVER".

    and upper (a.destination_type_code) ('charge', 'WORKSHOP')

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    where upper (a.destination_type_code) = "EXPENSES".

    or (upper (a.destination_type_code) = 'WORKSHOP'

    and b.item_id is null

    )

    A.po_header_id group,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description,

    a.unit_of_measure,

    d.release_num

    ) rcv1

    On po.po_header_id = rcv1.po_header_id

    left outer join

    (select a.po_line_id,

    Sum (a.Quantity) transact_qty,

    a.po_header_id,

    c.receipt_num

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    A.po_line_id group,

    a.po_header_id,

    c.receipt_num

    ) rcv2

    On rcv1.po_line_id = rcv2.po_line_id

    and rcv1.receipt_num = rcv2.receipt_num

    where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)

    Concerning

    Etbin

  • Confused with SQL query plan numbers

    Hi all

    I'm on Oracle 11.2 "Standard Edition" under Windows.

    Here is a simple query plan and the predicate shown after the plan. I'm a little confused by the numbers indicated on the plan and not able to understand why the index is not used. The query is generated from Cognos front end, I captured using dbms_xplan.display_cursor (when the query was actually being run).

    SQL > select * from table (dbms_xplan.display_cursor ('& sqlid', 0));

    Enter the value of sqlid: 8yd0uu78jzqpg

    old 1: select * from table (dbms_xplan.display_cursor ('& sqlid', 0))

    new 1: select * from table (dbms_xplan.display_cursor('8yd0uu78jzqpg',0))

    PLAN_TABLE_OUTPUT

    ------------------------------------------------------------------------------------------------------------------------------------

    SQL_ID, 8yd0uu78jzqpg, number of children 0

    -------------------------------------

    Select distinct CASE WHEN (CASE WHEN ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" IS "

    NULL NULL) THEN ELSE ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" | " -") END IS NULL)"

    OR ("MY_TRANSACTION_TABLE3". ("' EMP_NM ' IS NULL) THEN NO OTHER (CASE

    WHEN ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" IS NULL), THEN ANOTHER NULL "

    ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" | " -")

    END | "" MY_TRANSACTION_TABLE3 ". ("" EMP_NM END ")"Officer_Name. "

    'MY_TRANSACTION_TABLE3 '. ' ' NEW_OFFCR_CD ' 'Officer_Code' of

    'FDS_LDN_APLOWNER '. ' ' MY_TRANSACTION_TABLE ' 'MY_TRANSACTION_TABLE3' where

    'MY_TRANSACTION_TABLE3 '. » M » (« A », « E », « U », « F ») et

    'MY_TRANSACTION_TABLE3 '. ' BASE_DT ' =: PQ1 and.

    'MY_TRANSACTION_TABLE3 '. "" NEW_OFFCR_CD "as 'LO %' order by

    'Officer_Code' asc nulls last

    Hash value of plan: 1213358407

    --------------------------------------------------------------------------------------------

    | ID | Operation | Name                  | Lines | Bytes | Cost (% CPU). Time |

    --------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                       |       |       | 42146 (100) |          |

    |   1.  UNIQUE FATE |                       |   230.  5750 | 42145 (1) | 00:08:26 |

    |*  2 |   TABLE ACCESS FULL | MY_TRANSACTION_TABLE |  4283.   104K | 42144 (1) | 00:08:26 |

    --------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 filter (("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" AS "% LO %' AND

    'MY_TRANSACTION_TABLE3 '. ' BASE_DT ' =: PQ1 AND.

    INTERNAL_FUNCTION ("MY_TRANSACTION_TABLE3". "M") AND "

    'MY_TRANSACTION_TABLE3 '. (("' NEW_OFFCR_CD ' IS NOT NULL))

    MY_TRANSACTION_TABLE has 1.3 million records. There is an index made up of 4 columns, first column is BASE_DT and none of the other columns is used here in the predicate.

    Questions-

    (1) the number the ROWS column in the plan, I guess it's number of selected records in the query (and not the records read by the query). Fix?

    (2) there is an index on this table from BASE_DT (but other 3 columns in the index are not used). Each base_dt will select approximately 1.3 M. 80000 records why the index is not used?

    (3) the column of time in the plan. Step 1 made by 08:26 minutes and not 2A crossed 08:26 minutes? or steps 1 and 2 together have 08:26 mins?

    Thanks in advance

    1 LINES - shows the no. of rows estimated by the optimizer for this operation. This estimate is made using the table and column statistics (+ a few formulas can be)

    2. with the help of the index is decided by the optimizer based on profit he would get him. Internally, the database comes up with a lot of plan and selects a plan and at low cost. She stated that in light of current statistics rather than index, scanning, beneficial full table scan - so index have not been used.

    3. it is worth cumulative - CBO estimated a total 08:26 minutes - similar to the cost. But this chronology may not be necessarily the actual execution time.

    Read this link: http://www.oracle.com/technetwork/database/bi-datawarehousing/twp-explain-the-explain-plan-052011-393674.pdf it has almost all the information about the execution plan.

  • Help with sql query / a subquery to perform the COUNT

    Hello everyone,

    Co-worker colleague asked me to post a request here in hopes of getting more support.  Here's the question:

    There are 3 tables associated with this request.  A table of the application, which displays a number of application open for a particular request, an audit table that shows you all employees who worked on this application and one employee who shows you the details of the employee table.  My colleague is trying to understand what, how to see only applications that have been published by a wizard, but not a Manager.  There are a few applications that worked on both, but he won't see this request in its results.

    Here are the tables

    EMP

    ID FULL_NAME
    1234John Doe
    5467Jane Doe
    2345Clark Kent
    5432June Cleaver

    Unfortunately, this table does not have a title column (which was created provider, so we cannot change the internal structure).  My colleague knows who is the Assistant and the Director, then in this case, the first two of the id:

    1234 and 5467 are managers and the other 2 are assistants

    T_APPLICATION

    app_id app_number date_opened app_type
    901854778JANUARY 10, 2014NETWORK
    901954779JANUARY 11, 2014DATABASE
    901055000MARCH 12, 2014MATERIAL

    T_APP_AUDIT

    APP_ID PROCESSED_BY
    90181234
    90182345
    90185432
    90192345
    90195432
    90105432

    So, here is the actual query, I was given: it is actually to check the number of times that each application has been published per person:

    Select a.app_id, c.full_name, count (*) that controls

    t_application a, t_app_audit b, c of the emp

    where a.app_id = b.app_id and b.processed_by = c.id and

    a.app_type in ('NETWORK', "DATABASE")

    and b.processed not in ('1234, ' 5467')

    GROUP OF A.APP_ID, c.full_name;

    IF I won't see 9018 in my results, since at one time it was edited by a Manager (1234).  Unfortunately, this request does not eliminate the app_id 9018, it eliminates only the name of handlers appear in the query.  I hope I've explained this properly, and any help to point us in the right direction is welcomed.  Thanks in advance.

    Select

    a.app_id

    c.full_name

    , count (*) as the controls

    of t_application one

    t_app_audit b

    c of the emp

    where a.app_id = b.app_id

    and b.processed_by = c.id

    and a.app_type in ('NETWORK', "DATABASE")

    and b.app_id by (not in

    Select app_id

    of t_app_audit

    where processed_by in ('1234, ' 5467')

    )

    GROUP OF A.APP_ID, c.full_name;

  • Need help with SQL query (10 years since I have SQL)

    Hi guys,.

    I tried to remove some rust SQL. I did not go to SQL within a certain time.

    Here are the tables (% = ent $ = varcchar)
    -----------------
    RESULT
    -----------------
    % RESULT_ID-$ RC-% YEAR_ID - PERIOD_ID-% CONTRACT_NO-% value %
    20841---1439---83---37---010427102---1
    20842---1439---83---41---010427102---2
    20843---1439---84---37---010427102---3
    20844---1439---84---41---010427102---4
    20845---1439---83---34---010427102---5

    -----------------
    YEARS
    -----------------
    YEAR_ID - YEAR_DESC
    83 2010-2011
    84 2011-2012

    -----------------
    PERIOD
    -----------------
    PERIOD_ID - PERIOD_DESC
    34 14
    37 02
    41 03

    What I want is to get the last period of each year in the RESULT table. (I'll work the rest of the WHERE statement myself, because I have omitted some news, or columns for simplicity)
    Note that I can't rely on the ID of the period, as the chronological order is not respected.

    In the scenario above, I should GET
    % RESULT_ID-$ RC - YEAR_ID - PERIOD_ID-% CONTRACT_NO-% % value %
    20844---1439---84---41---010427102---4
    20845---1439---83---34---010427102---5



    I have the following, but it only returns values if the year is the last time!

    SELECT DISTINCT RESULTS. RESULT_ID, RESULT. RC, RESULT. PERIOD_ID, RESULT. YEAR_ID, RESULT. CONTRACT_NO, YEARS. YEAR_DESC
    RESULT, YEARS
    WHERE TO TRAIN. YEAR_ID = YEARS. YEAR_ID AND - it is my problem, I want the last period for each year.
    RESULT. PERIOD_ID = (SELECT PERIOD_ID FROM PERIOD WHERE CAST (PERIOD_DESC AS INT) = (Select MAX (CAST (PERIOD_DESC AS INT)) of the period)) - I think it works fine I'm able to get the last period
    ORDER BY YEARS. YEAR_DESC;

    Published by: 935079 on May 17, 2012 11:32
    Add space not formatted tabs

    Published by: 935079 on May 17, 2012 11:35

    Your way to present the data that makes it very tedious to create test data. Next time please simply provide CREATE TABLE and INSERT statements so that we can all share the same test data.

    Without test data, I think you want Frank solution with a very minor change: order value instead of id, then the number of line 1 is the highest value.

    with GOT_R_NUM as (
      SELECT r.* -- or list the columns you want
      , ROW_NUMBER() over(partition by R.YEAR_ID, R.CONTRACT_NO
        order by
    --    P.PERIOD_ID
        P.PERIOD_VALUE
        DESC NULLS LAST) AS r_num
      FROM result r
      JOIN period p ON r.period_id = p.period_id
      )
    SELECT * -- or list all columns except r_num
    FROM got_r_num
    WHERE r_num = 1;
    
  • TARGET RESULT COMPLEX SQL QUERY

    Hello

    I'm writing a sql, for the scenario below, but don't get it.

    There are two Table TEMP_AAA and TEMP_BBB,
    Under the table, we have values in descending order C_ID,

    Now to give a value in D_ID,.
    We must find the value of C_ID
    and if this C_ID value is contained in the B_ID,
    then we should display the value of allowance A_ID,

    The complexity here is,
    When you come down (in fact different levels) lines of C_ID,
    already consumed values should not be used.

    In this example,.
    for D_ID ABC says
    We have 1234 as C_ID and
    B_ID is 12345 which contains C_ID
    A_ID coresponding is 111 and 222.

    Next step for D_ID (same level): DEF since the C_ID is the same as the process described above
    We have A_ID 111 and 222.

    Then for D_ID GHI.
    We have 12 as C_ID and
    B_ID is 12345,12345,12045, which contains the C_ID
    A_ID coresponding allocation is 111,222,333,
    Now since 111 and 222 is already used in the ABC/DEF D_ID we would not have considered.
    A_ID would be 333

    Then for D_ID MNO.
    We have NULL as C_ID, which means all B_ID default matches (special account)
    B_ID is 12345,12345,12045,10045, which contains C_ID (default)
    A_ID coresponding allocation is 111,222,333,444
    Now given that 111,222,333 is already used in D_ID ABC/DEF/GHI/JKL we would not have considered.
    A_ID would be 444.



    Here is the Script and exit

     
    
    CREATE TABLE TEMP_AAA( A_ID VARCHAR2(10),  B_ID VARCHAR2(10));
    CREATE TABLE TEMP_BBB( C_ID VARCHAR2(10),  D_ID VARCHAR2(10));
    
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('111','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('222','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('333','12000');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('444','10000');
    
    INSERT INTO TEMP_BBB(C_ID,D_ID) VALUES('1234','ABC');
    INSERT INTO TEMP_BBB(C_ID,D_ID) VALUES('1234','DEF');
    INSERT INTO TEMP_BBB(C_ID,D_ID) VALUES('12','GHI');
    INSERT INTO TEMP_BBB(C_ID,D_ID) VALUES('12','JKL');
    INSERT INTO TEMP_BBB(C_ID,D_ID) VALUES(NULL,'MNO');
    EXPECTED RESULTS
    ---------------
     
    
    D_ID      RESULT A_ID
    ---------------
    ABC     111
    ABC     222
    DEF     111
    DEF     222
    GHI     333
    JKL     333
    MNO     444

    Hello

    Thanks for posting the CREATE TABLE and INSERT statements; This helps a lot.

    Interesting problem!
    For each allocation a_id, you have to find the number of times where a c_id equaled and choose only the lines where it is the 1st time.
    This sounds like a job for the analytic RANK function:

    WITH     got_c_id_rank     AS
    (
         SELECT       b.d_id
         ,       a.a_id
         ,       RANK () OVER ( PARTITION BY  a_id
                                     ORDER BY      c_id     DESC     NULLS LAST
                          ) AS c_id_rank
         FROM       temp_aaa     a
         JOIN       temp_bbb     b     ON     a.b_id     LIKE b.c_id || '%'
    )
    SELECT       d_id
    ,       a_id          AS result_a_id
    FROM       got_c_id_rank
    WHERE       c_id_rank     = 1
    ORDER BY  d_id
    ,            result_a_id
    ;
    

Maybe you are looking for

  • Why is it impossible to import contactfiles from Office Outlook?

    I try to import this file as an Excelfile comma (csv), but it will not be copied or cut to import bi

  • Windows XP Pro guard updates Netware download

    Windows XP Pro prevents the download of updates of Netware, installed to keep some, but not others and these download and try to install. I have not a Network.It is a standalone PC?John-* E-mail address is removed from the privacy *.

  • HP Pavilion 14-d040la

    Hello I installed Windows 7 pro 64 in HP Pavilion 14-d040la and now need the drivers for the wireless, video, sound, etc. Can yo help me? Tanks. Best regards

  • N4050 WiFi problem

    I bought the new Inspiron N4050 and installed Windows 7 64 bit in it. It does not connect to the WiFi and whenever I turn on the Wifi in my laptop the led remains lit for a while and then turns off. I checked the control panel to see if the drivers m

  • Ripping out exactly what I see in the control screen, bad elimination deinterlacing lines

    Well, here's one for you gurus of EI.THE PROBLEM I AM TRYING TO FIX:Ship a 29.97 progressive YUV QT 10-bit uncompressed file.  However, it seems that they have imported extracts in their project to FCP7 and cut into their sequence without correctly d