Decode the query help

Hello
I'm new to the development of Oracle.
Oracle 10 g 2

My original query:

SELECT APP, count (*)
TRANSACTION
WHERE TYPE in ('ShipmentConfirmPR', 'ShipmentConfirm', 'ShipConfirm')
and the APP ("SAPPI", "SAPPI", "SAPR3") and INTERVENE ('9320 ', '9332','1208 ')
GROUP BY APP TYPE
order of the APP

the result of this query:
SAPPI 100
SAPPI 600
SAPR3 440

My requirement
And I want to have something like output

LDCS 100
TSW 600
PDC 440

IE.the APPP and STEP combinations. Must return the specified values
SAPPI & 9320-> LOC (here SAPPI IE APP is the same for both... but it's a coincidence IE APP can be sliced also)
SAPPI & 9332-> tsw
SAPR3 & 1208-> pdc

Options, I tried:
Query provided by one of the Forum members...
SELECT THE CHECK BOX
WHEN APP = "SAPP1" THEN DECODE (step, '9320', 'LSW', '9332', "TSW")
WHEN APP = "SAPR3" step = '1208' AND 'PDC '.
END app
COUNT (*)
TRANSACTION
WHERE TYPE in ('ShipmentConfirmPR', 'ShipmentConfirm', 'ShipConfirm')
AND THE APP ("SAPPI", "SAPPI", "SAPR3")
AND STEP IN ('9320', '9332', ' 1208')
GROUP BY APP, STEP
ORDER OF THE APP.

EXECUTION PLAN

| ID | Operation | Name |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT |
| 1. GROUP SORT BY |
| 2. INLIST ITERATOR.
| 3. TABLE ACCESS BY INDEX ROWID | TRANSACTION |
| 4. INDEX RANGE SCAN | TRANSACTION_IDX |


The output of the query (as above) must partially match the following query (a particular combination of CLO)

SELECT count (1)
TIBCO. TRANSACTION_HISTORY
WHERE TYPE = 'ShipmentConfirm '.
and APP in ("SAPPI") and INTERVENE ('9332')


My Questions:

1.*There are indexes on all 3 APP passes it's IE, STEP and TYPE *. I don't want a FULL table Scan (as one would use the index). Can change us the query / use of indices, etc. to make it faster?

2. is the right to approach? Would the use of the concat operator in the function decode work better for my needs?
Something like

Select decode (APP |) STEP, 'SAPP9332', 'X') of TRANSACTION_HISTORY where < COND >

If Yes can you please provide the query?

3. ANY other approach / request for my requirement.

Thanks in advance.

Hello

user13517642 wrote:
... EXECUTION PLAN

| ID | Operation | Name |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT |
| 1. GROUP SORT BY |
| 2. INLIST ITERATOR.
| 3. TABLE ACCESS BY INDEX ROWID | TRANSACTION |
| 4. INDEX RANGE SCAN | TRANSACTION_IDX |

The output of the query (as above) must partially match the following query (a particular combination of CLO)

SELECT count (1)
TIBCO. TRANSACTION_HISTORY
WHERE TYPE = 'ShipmentConfirm '.
and APP in ("SAPPI") and INTERVENE ('9332')

My Questions:

1.*There are indexes on all 3 APP passes it's IE, STEP and TYPE *. I don't want a FULL table Scan (as one would use the index). Can change us the query / use of indices, etc. to make it faster?

A full table scan might be the fastest way to get results. Do you have any reason to think that it would be faster to go through the index? How selective are the clues? In other words, what is the percentage of rows in the table correspond to each of the values in the WHERE clause?

2. is the right to approach?

It depends on what you're trying to do, which is not at all clear to me.

Would the use of the concat operator in the function decode work better for my needs?
Something like

Select decode (APP |) STEP, 'SAPP9332', 'X') of TRANSACTION_HISTORY where

If you use this approach, look out for the problem Ab asse crevit . For example, if you have these 4 rows and 2 columns:

str1     str2
----     ----
(NULL)     FOO
F     OO
FO     O
FOO     (NULL)

There are 4 values of distict of str1 (counting NULL) and 4 separate values of str2, str1 but | str2 is the same for each of them. In the above example, it there is no way to know, just by looking at the concatenated string, including str1 and str2 ends begins. Maybe it's not the case for your specific data (for example, if the application is still exactly 5 characters long). otherwise, you may need to add some kind of delimiter, like this

app || '+' || step

where you know that '+' never occurs in one of these columns.

3. ANY other approach / request for my requirement.

CASES, as I mentioned in your previous message:
Decode the help function
and as you have used above.

In this thread, you said "I have to use the decode function. Why? It is a competition of school Etudieeo DECODE is explicitly required? Why you don't want in the best way, what that turns out to be?

Your WHERE clause:

AND APP IN ('SAPPI', 'SAPPI', 'SAPR3')
AND STEP IN ('9320', '9332', '1208')

admits 6 possible combinations of APA and step:

app     step
-----     ----
SAPP1     9320
SAPP1     9332
SAPP1     1208
SAPP3     9320
SAPP3     9332
SAPP3     1208

but you are looking for only 3 of these combinations in DECODE it or the expression BOX. (Have 2 copies of 'SAPP1' e list won't do any good, but it does hurt real, either.)
By the way, is "SAPPI" app with the letter 'I' at the end, or "SAPP1", with the number '1' at the end?

Published by: Frank Kulash, March 24, 2011 19:44

Tags: Database

Similar Questions

  • calculate the value of the query help

    Hi all
    Following the script nicely:
    CREATE TABLE ACCOUNT_LOOCKUP
    (
      SERIAL_ID     NUMBER,
      ACCOUNT_ID    NUMBER,
      ACCOUNT_RATE  NUMBER,
      ACCOUNT_MAX   NUMBER
    )
    
    ALTER TABLE ACCOUNT_LOOCKUP ADD (
      CONSTRAINT PK_ACCOUNT_LOOCKUP
     PRIMARY KEY
     (SERIAL_ID, ACCOUNT_ID));
    
    
    
    Insert into ACCOUNT_LOOCKUP
       (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
     Values
       (1, 1, 10, 200);
    Insert into ACCOUNT_LOOCKUP
       (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
     Values
       (2, 1, 12, 150);
    Insert into ACCOUNT_LOOCKUP
       (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
     Values
       (3, 1, 8, 400);
    Insert into ACCOUNT_LOOCKUP
       (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
     Values
       (1, 2, 7, 100);
    Insert into ACCOUNT_LOOCKUP
       (SERIAL_ID, ACCOUNT_ID, ACCOUNT_RATE, ACCOUNT_MAX)
     Values
       (2, 2, 5, 200);
    COMMIT;
    
    
    SELECT * FROM ACCOUNT_LOOCKUP
    
     SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX
    ---------- ---------- ------------ -----------
             1          1           10         200
             2          1           12         150
             3          1            8         400
             1          2            7         100
             2          2            5         200
             
             
    CREATE TABLE ACCOUNT_AMOUNT(
    ACCOUNT_ID NUMBER(10),
    ACCOUNT_AMNT NUMBER(10))
    
    
    Insert into ACCOUNT_AMOUNT
       (ACCOUNT_ID, ACCOUNT_AMNT)
     Values
       (1, 9);
    Insert into ACCOUNT_AMOUNT
       (ACCOUNT_ID, ACCOUNT_AMNT)
     Values
       (1, 35);
    COMMIT;
     
    SELECT * FROM ACCOUNT_AMOUNT
     
    ACCOUNT_ID ACCOUNT_AMNT
    ---------- ---------------
             1               9
             1              35
           
    I want by select query calculte ACCOUNT_TOTAL every ACCOUNT_ID exists in table ACCOUNT_AMOUNT as below ,
    
    1. every ACCOUNT_ID have SERIAL_ID and ACCOUNT_RATE and ACCOUNT_MAX in table ACCOUNT_LOOCKUP,
    2. to calculte ACCOUNT_TOTAL every ACCOUNT_ID : 
       
       - order ascending SERIAL_ID exists in table ACCOUNT_LOOCKUP to every ACCOUNT_ID exists in table ACCOUNT_AMOUNT ,
       - make sum ACCOUNT_AMNT every ACCOUNT_ID in table ACCOUNT_AMOUNT,
       - then, copmare result (sum ACCOUNT_AMNT) with first record after ascending SERIAL_ID,
       - product (sum ACCOUNT_AMNT) * ACCOUNT_RATE  result as ACCOUNT_TOTAL,(in ex: sum ACCOUNT_AMNT  = 44   ) ,
       - if ACCOUNT_TOTAL > ACCOUNT_MAX then 
             * ACCOUNT_TOTAL = ACCOUNT_MAX for first record(in ex SERIAL_ID = 1 ) ,
             * Goto the second record by ascending (in ex SERIAL_ID = 2 ) ,
               make ( ACCOUNT_TOTAL / ACCOUNT_RATE ) for first record ,
               ( 200 / 10 ) result 20 >>
               
             * calculate Remainder ACCOUNT_AMNT =  the sum ACCOUNT_AMNT 44 - 20 = 24 
             
                *Goto the second record by ascending (in ex SERIAL_ID = 2 ) ,   
                   Remainder ACCOUNT_AMNT 24 * (12) ACCOUNT_RATE for second record = 288 as ACCOUNT_TOTAL 
                   -if ACCOUNT_TOTAL > ACCOUNT_MAX then 
                   * ACCOUNT_TOTAL = ACCOUNT_MAX for second record(in ex SERIAL_ID = 2 ) ,
                      * Goto the third record by ascending (in ex SERIAL_ID = 3 ) ,
                      make ( ACCOUNT_TOTAL / ACCOUNT_RATE ) for second record ,
                       ( 150 / 12 ) result 12.5
                   
                        * calculate Remainder ACCOUNT_AMNT =  the sum ACCOUNT_AMNT 24 - 12.5 = 11.5 
                        Remainder ACCOUNT_AMNT 9.5 * (12) ACCOUNT_RATE for third record = 92 result as ACCOUNT_TOTAL 
                        if result <= ACCOUNT_MAX then 
                            ACCOUNT_TOTAL = 92 
    except result
    ------------
    
    SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX   ACCOUNT_TOTAL          ** explain ** 
    ---------- ---------- ------------ -----------  -------------  *****  sum ACCOUNT_AMNT  = 44 for ACCOUNT_ID = 1from table ACCOUNT_AMOUNT ******
             1          1           10         200          200  >> (44 * 10 ) = 440 >>  200 /10 rate = 20 >> 44 - 20 = 24 Remainder ACCOUNT_AMNT
             2          1           12         150          150  >> (22 * 12 ) = 288 >>  150 /12 rate = 12.5 >> 24 - 12.5 = 11.5 Remainder ACCOUNT_AMNT
             3          1            8         400           92  >> (11.5 * 8)  = 92  And so on ....
        
    another insert 
    Insert into ACCOUNT_AMOUNT
       (ACCOUNT_ID, ACCOUNT_AMNT)
     Values
       (2, 10);         
       
       
    SELECT * FROM ACCOUNT_AMOUNT
     
    ACCOUNT_ID ACCOUNT_AMNT
    ---------- ---------------
             1               9
             1              35
             2              10    
             
    
    except result
    ------------
      
    
    SERIAL_ID ACCOUNT_ID ACCOUNT_RATE ACCOUNT_MAX   ACCOUNT_TOTAL          ** explain ** 
    ---------- ---------- ------------ -----------  -------------  *****  sum ACCOUNT_AMNT  = 10 for ACCOUNT_ID = 2 from table ACCOUNT_AMOUNT ******
             1          1           10         200          200  
             2          1           12         150          150  
             3          1            8         400           92           
             1          2            7         100           70    10 * 7 = 70 
    Help me please
    Thanks in advance

    Published by: 900510 on December 5, 2011 08:05

    900510 wrote:
    Hi all

    First I want to apologize for my English, this isn't flunet.

    Following the script nicely:

    CREATE OR REPLACE VIEW V_ACCOUNT (ACCOUNT_ID,ID,ACCOUNT_RATE,ACCOUNT_MAX,ACCOUNT_TOTAL)
    AS
    SELECT  1, 2, 10 ,200 , 0 FROM DUAL
    UNION
    SELECT  1, 5, 12 ,150 , 0 FROM DUAL
    UNION
    SELECT  1, 9, 8  ,400 , 0 FROM DUAL
    UNION
    SELECT  2 ,1, 7  ,100 , 0 FROM DUAL
    UNION
    SELECT  2 ,3 ,5  ,200 , 0 FROM DUAL
    ORDER BY 1,2
    
    ACCOUNT_ID         ID ACCOUNT_RATE ACCOUNT_MAX ACCOUNT_TOTAL
    ---------- ---------- ------------ ----------- -------------
    1          2           10         200             0
    1          5           12         150             0
    1          9            8         400             0
    2          1            7         100             0
    2          3            5         200             0
    

    I must be missing something... in your opinion, by definition does only selected literals 5 double. How you expect what you do for any other table to change those returned by the view?

    Published by: EdStevens on December 5, 2011 08:51

  • The query help

    Dear Experts,

    Need to convert several lines in a row

    CREATE TABLE TESTING_PIVOT

    (

    IDENTIFICATION NUMBER,

    NUMBER OF PRICE_AMOUNT

    NUMBER OF RATE_PERCENT

    );

    INSERT INTO TESTING_PIVOT VALUES (1,100,55);

    INSERT INTO TESTING_PIVOT VALUES (1,200,85);

    INSERT INTO TESTING_PIVOT VALUES (1,300,64);

    INSERT INTO TESTING_PIVOT VALUES (2,400,94);

    INSERT INTO TESTING_PIVOT VALUES (2,500,59);

    INSERT INTO TESTING_PIVOT VALUES (2,600,49);

    COMMIT;

    SELECT * FROM TESTING_PIVOT;

    DESIREE OUTPUT

    ID PRICE_AMOUNT_1 PRICE_AMOUNT_1 PRICE_AMOUNT_1 RATE_PERCENT_1 RATE_PERCENT_2 RATE_PERCENT_3

    1               100                              200                                                  300                                   55                                        85                                   64

    2               400                              500                                                  600                                   94                                        59                                   49

    Help, please

    Try this

    Select

    ID,

    MAX (CASE WHEN RN = 1 THEN PRICE_AMOUNT END) PRICE_AMOUNT1,.

    MAX (CASE WHEN RN = 2 THEN PRICE_AMOUNT END) PRICE_AMOUNT2,.

    MAX (CASE WHEN RN = 3 THEN PRICE_AMOUNT END) PRICE_AMOUNT3,.

    MAX (CASE WHEN RN = 1 THEN RATE_PERCENT END) RATE_PERCENT1,.

    MAX (CASE WHEN RN = 2 THEN RATE_PERCENT END) RATE_PERCENT2,.

    MAX (CASE WHEN RN = 3 THEN RATE_PERCENT END) RATE_PERCENT3

    Of

    (select id, PRICE_AMOUNT, RATE_PERCENT, ROW_NUMBER() over (PARTITION BY ORDER of the ROWNUM ID) RN OF TESTING_PIVOT)

    Group by id;

  • Decode the simple query

    Decode the query
    Simplified version of the query below.

    SELECT
    d.REG,
    d.DP,
    c.CHANNEL
    Of
    CUSTOMER c,.
    ACCOUNT d
    WHERE c.ID = d.ID
    D.REG GROUP, d.DP, c.CHANNEL


    Channel field in the Customer Table contains several store ID (1 Store, tray 2, tray 3, store 4 etc.) - basically, I want to use decode on the channel field so that instead of all the store ID being issued what is fate of the channel are
    Store 1 = "big".
    Store 2 = 'average '.
    Store 3 = "Small".
    All other stores = 'other '.

    Where the decode to insert statement and what should be the format - attempt below
    DECODE (c.CHANNEL, "keep 1, 'Big', ' Store 2', 'Medium', 'Store' 3', small ', 'Other' ') of

    Hello

    This should be what you are looking for:

    SELECT   d.REG,
             d.DP,
             DECODE (c.CHANNEL, 'Store 1','Large', 'Store 2','Medium', 'Store 3','Small', 'Other') Channel
    FROM     CUSTOMER c,
             ACCOUNT d
    WHERE    c.ID = d.ID
    GROUP BY d.REG,
             d.DP,
             c.CHANNEL
    

    City where to move them in decoding...

  • Need help with the query. Help, please

    Hey everyone, need your help.  Thank you in advance.  In my view, there is function Pivot.  Just do not know how to use this function.  I have the query that works.  The result is:

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 dental plan pre-tax amount 29,65

    11-111-1111 Vlad 16505 01/04/2013 dental pre-tax 5 August 13 Plan level EE + SP

    11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Option TOP dental plan

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax dental care plan pay the value

    11-111-1111 16505 Vlad 01/04/2013 dental pre-tax 5 August 13 Plan period Type

    11-111-1111 Vlad 16505 01/04/2013 amount pre-tax medical Plan of 5 August 13 149

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Medical Plan level EE + SP

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan medical Option MED

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 plan pre-tax pay value

    11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Medical Plan period Type

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan PPO medical Plan

    11-111-1111 Vlad 16505 01/04/2013 5 August 13 Vision Plan amount 5.94 pre-tax

    But I need the result to be

    Amount of SSN ID name item level Option PayValue period Type

    11-111-1111 Vlad 16505 01/04/2013 null null high of 5 August 13 pre-tax Dental Plan 29,65 EE + SP

    11-111-1111 Vlad 16505 01/04/2013 null null MED 5 August 13 149 medical plan pre-tax EE + SP

    11-111-1111 Vlad 16505 01/04/2013 Vision Plan before taxes of 5 August 13

    Select distinct
    ' 11-111-1111 "as ssn,
    WOMEN'S WEAR. Employee_number,
    "Vlad" as EMPLOYEE_FULL_NAME,
    TO_CHAR (papf.start_date, "MM/DD/YYYY") as Date_Of_Hire
    a.effective_start_date,
    PETF.element_name,
    pivf. Name,
    peevf.screen_entry_value

    Of
    PER_all_PEOPLE_F women's wear
    per_assignments_f A
    pay_element_types_f petf
    pay_element_links_f pelf
    PAY_ELEMENT_ENTRIES_F penf
    PAY_ELEMENT_ENTRY_VALUES_F peevf
    pay_input_values_f pivf
    WHERE
    PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
    and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
    and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
    and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
    and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
    and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
    and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
    AND papf.employee_number IS NOT NULL
    AND A.assignment_type = 'E '.
    AND A.person_id = papf.person_id
    and papf.effective_end_date > sysdate
    and a.effective_end_date > sysdate
    and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
    and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
    and a.assignment_id = 42643
    and a.assignment_status_type_id = '1'
    order of petf.element_name;

    Change with your query

    SELECT * FROM (select distinct)

    ' 11-111-1111 "as ssn,

    WOMEN'S WEAR. Employee_number,

    "Vlad" as employee_full_name,

    TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire

    a.effective_start_date,

    PETF.element_name,

    pivf. Name,

    peevf.screen_entry_value

    Of

    PER_all_PEOPLE_F women's wear

    per_assignments_f A

    pay_element_types_f petf

    pay_element_links_f pelf

    PAY_ELEMENT_ENTRIES_F penf

    PAY_ELEMENT_ENTRY_VALUES_F peevf

    pay_input_values_f pivf

    WHERE

    PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")

    and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID

    and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)

    and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)

    and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)

    and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID

    and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID

    AND papf.employee_number IS NOT NULL

    AND A.assignment_type = 'E '.

    AND A.person_id = papf.person_id

    and papf.effective_end_date > sysdate

    and a.effective_end_date > sysdate

    and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)

    and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)

    and a.assignment_id = 42643

    and a.assignment_status_type_id = '1')

    PIVOT (MAX (screen_entry_value) FOR (name) TO ("Amount" AS 'Amount', 'level' AS 'level', 'Option High' AS 'High Option', 'Pay the value' AS 'Value to pay', 'Period of Type' AS 'Type period'))

    order by element_name;

    (GOLD)

    SELECT ssn,

    Employee_number,

    employee_full_name,

    date_of_hire,

    effective_start_date,

    element_name,

    Max (decode (Name, 'Amount', screen_entry_value)) 'amount. "

    Max (decode (Name, 'Level', screen_entry_value)) 'level ',.

    MAX (DECODE (name, "High Option", screen_entry_value)) "High Option",

    MAX (DECODE (name, 'Value of pay', screen_entry_value)) 'value of pay. "

    MAX (DECODE (name, 'Period Type', screen_entry_value)) 'period of Type '.

    FROM (select distinct)

    ' 11-111-1111 "as ssn,

    WOMEN'S WEAR. Employee_number,

    "Vlad" as employee_full_name,

    TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire

    a.effective_start_date,

    PETF.element_name,

    pivf. Name,

    peevf.screen_entry_value

    Of

    PER_all_PEOPLE_F women's wear

    per_assignments_f A

    pay_element_types_f petf

    pay_element_links_f pelf

    PAY_ELEMENT_ENTRIES_F penf

    PAY_ELEMENT_ENTRY_VALUES_F peevf

    pay_input_values_f pivf

    WHERE

    PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")

    and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID

    and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)

    and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)

    and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)

    and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID

    and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID

    AND papf.employee_number IS NOT NULL

    AND A.assignment_type = 'E '.

    AND A.person_id = papf.person_id

    and papf.effective_end_date > sysdate

    and a.effective_end_date > sysdate

    and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)

    and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)

    and a.assignment_id = 42643

    and a.assignment_status_type_id = '1')

    GROUP BY ssn, employee_number, employee_full_name, date_of_hire, effective_start_date, NOM_ELEMENT

    order by element_name;

  • Helps with the exclusion of the query items

    I compare two identical tables between databases using the links to the db and I'm having issues getting my correct join show lines that exist in a table and not the other. The purpose of the request is to view the items that exist in one but not the other and where the value is different between the elements. The Grp, layer and Name columns are PKs.

    So take the following data:
    DB1
    Grp     Name        Layer       Value
    Alpha   Key_One     ModA        1
    Beta    Key_Two     ModA        1
    Gamma   Key_Three   ModB        0
    Delta   Key_Four    ModA        True
    Epsilon Key_Five    ModB        Hat
    Zeta    Key_Six     ModB        Red
    
    DB2
    Grp     Name        Layer       Value
    Alpha   Key_One     ModA        0
    Beta    Key_Two     ModA        1
    Gamma   Key_Three   ModB        0
    Delta   Key_Four    ModA        False
    Epsilon Key_Five    ModA        Hat
    Eta     Key_Seven   ModB        0
    The result of the query should be:
    Grp     Name        Layer       DB1.Value    DB2.Value
    Alpha   Key_One     ModA        1            0
    Delta   Key_Four    ModA        True         False
    Epsilon Key_Five    ModA                     Hat
    Epsilon Key_Five    ModB        Hat
    Zeta    Key_Six     ModB        Red
    Eta     Key_Seven   ModB                     0
    I've been able to get the query to pull the differences when the record exists in both tables, but were not able to get when recording exists only in a single table. If it's important, I'm on 10.2.0.4.
    CREATE TABLE tab1 (grp VARCHAR2 (10), nm VARCHAR2 (15), layer VARCHAR2 (4), rec_value VARCHAR2 (10));
    CREATE TABLE tab2 (grp VARCHAR2 (10), nm VARCHAR2 (15), layer VARCHAR2 (4), rec_value VARCHAR2 (10));
    
    INSERT INTO tab1 VALUES ('Alpha', 'Key_One', 'ModA', '1');
    INSERT INTO tab1 VALUES ('Beta', 'Key_Two', 'ModA', '1');
    INSERT INTO tab1 VALUES ('Gamma', 'Key_Three', 'ModB', '0');
    INSERT INTO tab1 VALUES ('Delta', 'Key_Four', 'ModA', 'True');
    INSERT INTO tab1 VALUES ('Epsilon', 'Key_Five', 'ModB', 'Hat');
    INSERT INTO tab1 VALUES ('Zeta', 'Key_Six', 'ModB', 'Red');
    
    INSERT INTO tab2 VALUES ('Alpha', 'Key_One', 'ModA', '0');
    INSERT INTO tab2 VALUES ('Beta', 'Key_Two', 'ModA', '1');
    INSERT INTO tab2 VALUES ('Gamma', 'Key_Three', 'ModB', '0');
    INSERT INTO tab2 VALUES ('Delta', 'Key_Four', 'ModA', 'False');
    INSERT INTO tab2 VALUES ('Epsilon', 'Key_Five', 'ModA', 'Hat');
    INSERT INTO tab2 VALUES ('Eta', 'Key_Seven', 'ModB', '0');
    COMMIT;
    After the implementation of the above, I can run the following script which returns all but I want to exclude records where they correspond, in the example above, are GRPs beta and Gamma.
      SELECT NVL (tab1.grp, tab2.grp) grp, NVL (tab1.nm, tab2.nm) nm, NVL (tab1.layer, tab2.layer) layer, tab1.rec_value tab1_value,
             tab2.rec_value tab2_value
        FROM tab1 FULL OUTER JOIN tab2 ON tab1.grp = tab2.grp AND tab1.nm = tab2.nm AND tab1.layer = tab2.layer
    ORDER BY 1,2,3;
    
    GRP        NM              LAYER TAB1_VALUE TAB2_VALUE
    ---------- --------------- ----- ---------- ----------
    Alpha      Key_One         ModA  1          0         
    Beta       Key_Two         ModA  1          1         
    Delta      Key_Four        ModA  True       False     
    Epsilon    Key_Five        ModA             Hat       
    Epsilon    Key_Five        ModB  Hat                  
    Eta        Key_Seven       ModB             0         
    Gamma      Key_Three       ModB  0          0         
    Zeta       Key_Six         ModB  Red                  
    
    8 rows selected.
    Any help would be appreciated.

    Hello

    Just add a WHERE clause that makes tab1.rec_value and tab_2.rec_value are different, accounting for NULL values. (The only change I made to your application, in addition to the formatting, was to add a WHERE clause).
    If rec_value may not actually be NULL:

    SELECT  NVL (tab1.grp,          tab2.grp)     grp
    ,     NVL (tab1.nm,           tab2.nm)     nm
    ,     NVL (tab1.layer,      tab2.layer)      layer
    ,     tab1.rec_value                     tab1_value
    ,       tab2.rec_value                    tab2_value
    FROM           tab1
    FULL OUTER JOIN tab2     ON     tab1.grp   = tab2.grp
                           AND     tab1.nm        = tab2.nm
                   AND     tab1.layer = tab2.layer
    WHERE   DECODE ( tab1.rec_value
                , tab2.rec_value, 1
                          , 0
                ) = 0
    ORDER BY 1,2,3;
    

    If rec_value can be null, we must distinguish between the ranks, which is NULL because he wasn't match (and therefore should be included) and the lines where the two are really NULL (and therefore, should not be displayed).
    If one of the columns used to join the tables is NULL, the row is missing in one of the tables, and so forge displayed regardless of whether the rec_values is, so we can add a condtion to the WHERE clause:

    SELECT  NVL (tab1.grp,          tab2.grp)     grp
    ,     NVL (tab1.nm,           tab2.nm)     nm
    ,     NVL (tab1.layer,      tab2.layer)      layer
    ,     tab1.rec_value                     tab1_value
    ,       tab2.rec_value                    tab2_value
    FROM           tab1
    FULL OUTER JOIN tab2     ON     tab1.grp   = tab2.grp
                           AND     tab1.nm        = tab2.nm
                   AND     tab1.layer = tab2.layer
    WHERE   DECODE ( tab1.rec_value
                , tab2.rec_value, 1
                          , 0
                ) = 0
    OR     LEAST (tab1.grp, tab2.grp)     IS NULL
    ORDER BY 1,2,3;
    

    To test this, I added these 3 rows to the data:

    INSERT INTO tab1 VALUES ('Theta', 'Key_Seven', 'ModB', NULL);
    
    INSERT INTO tab2 VALUES ('Theta', 'Key_Seven', 'ModB', NULL);
    INSERT INTO tab2 VALUES ('Iota',  'Key_Seven', 'ModB', NULL);
    

    GRP = "Theta" should appear not, because the lines are identical in both tables.
    GRP = 'Iota' should be displayed, because it is present only in tab2.

  • SQL query takes too long to run (1 h 25 min)... pls help how to set up the query.

    Hello

    Could someone please help how to tune the query as its takes a long time to retrieve the results.

    Select

    col1,

    col2,

    col3,

    COL4,

    col5,

    col6,

    col7,

    COL8,

    col9,

    col10,

    Col11,

    col12,

    Sum (volume1),

    Sum (volume2),

    Sum (volume3),

    Sum (volume4),

    Sum (volume5),

    Sum (volume6),

    Sum (volume7),

    Sum (volume8),

    Sum (volume9),

    Sum (volume10),

    Sum (volume11),

    Sum (volume12),

    Sum (volume13),

    Sum (volume14),

    Sum (volume15),

    Sum (volume16),

    Sum (volume17),

    Sum (Volume18),

    Sum (volume19),

    Sum (volume20),

    Sum (rate1),

    Sum (rate2),

    Sum (rate3),

    Sum (rate4),

    Sum (rate5),

    Sum (rate6),

    Sum (rate7),

    Sum (rate8),

    Sum (rate9),

    Sum (rate10),

    Sum (rate11),

    Sum (rate12),

    Sum (rate13),

    Sum (rate14),

    Sum (rate15),

    Sum (rate16),

    Sum (rate17),

    Sum (rate18)

    Sum (rate19),

    Sum (rate20)

    Of

    Table 1 - 13, 25, 99, 400 records

    Table2 - 13, 45, 1000 records

    Table 3 - 4, 50, 000 records

    Table 4 - 1,00,000 records

    table5 - 30 000 records

    where tabl1.col1 = table2.col2,

    Table1.Col1 = table3.col1.

    table2.col2 = table3.col2...

    Group

    Sum (volume1),

    Sum (volume2),

    Sum (volume3),

    Sum (volume4),

    Sum (volume5),

    Sum (volume6),

    Sum (volume7),

    Sum (volume8),

    Sum (volume9),

    Sum (volume10),

    Sum (volume11),

    Sum (volume12),

    Sum (volume13),

    Sum (volume14),

    Sum (volume15),

    Sum (volume16),

    Sum (volume17),

    Sum (Volume18),

    Sum (volume19),

    Sum (volume20),

    Sum (rate1),

    Sum (rate2),

    Sum (rate3),

    Sum (rate4),

    Sum (rate5),

    Sum (rate6),

    Sum (rate7),

    Sum (rate8),

    Sum (rate9),

    Sum (rate10),

    Sum (rate11),

    Sum (rate12),

    Sum (rate13),

    Sum (rate14),

    Sum (rate15),

    Sum (rate16),

    Sum (rate17),

    Sum (rate18)

    Sum (rate19),

    Sum (rate20)

    Thank you

    Prasad.

    > Could someone please help how to tune the query as its takes a long time to retrieve the results.

    The query you posted is obviously fake.

    If you ask to give us a request that you do not post and we cannot see.

    For real?

  • Need help to understand the query result

    Hi gurus

    I was reading one of the question here in this forum and its link is below:

    Query required for scenario

    I had some confusion related to this code and don't understand the logic of the out put, see query below:

    Query

    with sub_services as

    (

    Select su_seq 12323, 'HLR1' so_id, 1 seq Union double all the

    Select su_seq 12323, "HLR2' so_id, seq 2 Union double all the

    Select su_seq 12323, "A09" so_id, seq 3 of all the double union

    Select su_seq 12333, "MO1" so_id, seq 4 Union double all the

    Select su_seq 12333, "MO2' so_id, seq 5 Union double all the

    Select su_seq 12333, "A09" so_id, 6 seq in union double all the

    Select su_seq 12333, 'M0CR' so_id, seq 7 Union double all the

    Select su_seq 12999, "LOL1' so_id, seq 8 Union double all the

    Select su_seq 12999, "LOL2' so_id, seq 9 double

    )

    Select *.

    of sub_services b

    where exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    )

    order by 2;

    The query result

    12323 A09 3

    12333 6 A09

    12323 HLR1 1

    12323 HLR2 2

    12333 M0CR 7

    12333 4 MO1

    12333 5 MO2

    According to my understanding, the above query should return records in red only because of her is below command

    It exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    but don't know why he's back 7 files, can someone help me understand the result...

    It is query is functionally identical to the PL/SQL block, but much more effective.

    declare

    number of l_res;

    Start

    for line (select *)

    sub_services) loop

    Start

    Select 1 from l_res

    of sub_services

    where su_seq = row.su_seq and

    so_id = "A09" and

    rownum = 1;

    exception when

    NO_DATA_FOUND then

    null;

    end;

    end loop;

    end;

    Essentially every row in the outer query are tested against him exists query.  Given the correlation between two requests is based only on su_seq each line with a su_seq value returned by him is returned in the output.

    Another way to think he uses instead a join condition.  This query is equivalent to the query to exist

    Select the main

    of main sub_services

    Join select (separate su_seq

    of sub_services

    where so_id = "A09") cond

    We main.su_seq = cond.su_seq;

    John

  • I want to loop through the data from two different tables using for loop where the query should be replaced at runtime, please help me

    I have the data into two table with the structure of similar column, I want to loop through the data in these two tables

    based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    declare

    l_statement varchar2 (2000);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: =' select * ab ';

    on the other

    l_statement: =' select * from bc';

    end if

    I'm in execute immediate l_statement - something like that, but I don't know

    loop

    dbms_output.put_line (i.a);

    end loop;

    end;

    Something like that, but this isn't a peace of the code work.

    Try this and adapt according to your needs:

    declare

    l_statement varchar2 (2000);

    c SYS_REFCURSOR;

    l_a number;

    l_b varchar2 (20);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: = "select a, b, AB;

    on the other

    l_statement: = "select a, b from bc;

    end if;

    --

    Open c for l_statement;

    --

    loop

    extract the c in l_a, l_b;

    When the output c % notfound;

    dbms_output.put_line (l_a |') -' || l_b);

    end loop;

    close c;

    end;

    /

  • Help with the query

    Hi, can someone help me with the query. I try to display comm based on calculation below

    SAL < 5000 then 10%

    5000 - 10000 then 15%

    > 10000 then 20%

    This is the query

    DECLARE

    v_comm number (7.2);

    v_Name emp.ename%type;

    v_empno emp.empno%type;

    v_sal emp.sal%type;

    BEGIN

    SELECT ename, empno, sal IN

    v_Name, v_empno, v_sal

    EMP;

    v_comm: = (IF v_sal < v_sal*.10 then 5000;)

    ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;

    Of ANOTHER v_sal > 10001 THEN v_sal*.20;

    END IF ;);

    dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);

    END; /

    also tried

    DECLARE

    v_comm number (7.2);

    v_Name emp.ename%type;

    v_empno emp.empno%type;

    v_sal emp.sal%type;

    BEGIN

    SELECT ename, empno, sal IN

    v_Name, v_empno, v_sal

    EMP;

    IF v_sal < v_comm then 5000: = v_sal*.10;

    ELSIF v_sal between 5001 AND 10000 THEN v_comm: = v_sal*.15;

    Of ANOTHER v_sal > 10001 THEN v_comm: = v_sal*.20;

    END IF ;);

    dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);

    END;

    /

    Hello

    Look at the syntax of the IF in the PL/SQL manual.  Comapre to the instruction BOX and also the expression BOX.

    Perhaps, instead of an IF statement

    v_comm: = (IF v_sal<5000 then="">

    ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;

    ELSE v_sal > 10001 THEN v_sal*.20;

    END IF ;);

    you wanted to write an expression BOX, like this:

    v_comm: = BOX

    WHEN v_sal< 5000                ="" then="" v_sal="" *="">

    WHEN v_sal BETWEEN 5001 AND 10000 THEN v_sal *.15

    WHEN v_sal > 10001 THEN v_sal *.20

    END;

    Or perhaps cela:

    v_comm: = v_sal * CASE

    WHEN v_sal<=  5000="" then="">

    WHEN v_sal<= 10000="" then="">

    OF AUTRE.20

    END;

    You can also use a CASE expression in the SELECT statement.

  • Helps the query in the effects control.

    Hello everyone, I hope that someone can help you.

    I have a little trouble trying to move images around the screen in my sequence to create an animation of a cursor moving to another location. The problem is when I put a marker in the query in the effect control to it's own journey sometimes going upward or down or left or right. I see that there are lines that are the focus of the image, as well as those of the tool pen in Photoshop and I think that that is what is causing the image of the cursor moving on its own. The two same lines by an image to make a smooth arch of movement these lines of travel to smooth the movement rather than a simple at the following location.

    I was wandering because this is the case whenever I put a new marker in the motion effects controls if there is something that is originally what I can disable. I can move these lines from the central point, but that does not make the smoother actions in my sequence.

    Any help is really appreciated.

    You set keyframes on linear:

    Adobe Premiere Pro help. Control to make changes using keyframe interpolation

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

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

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Need help to write the query to extract the value of the previous row - Lag not help


    Hello

    I created follwing table.

    Create table test

    (number of fi,

    number of fo_fv

    number of jup_fv

    action varchar2 (10)

    );

    insert into TEST(1,1,1,'LOAD');

    Insert into TEST (2, NULL, 2, "ROLL");

    insert into TEST(3,,3,'ROLL');

    insert into TEST(4,,4,ROLL);

    insert into TEST (5,2,5,LOAD);

    I want the result of the query as below:

    FI FO_FV JUP_FV ACTION

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

    1          1                    1                    LOAD

    2          1                    2                    ROLL

    3          1                    3                    ROLL

    4          1                    4                    ROLL

    5          2                    5                    LOAD

    Help, please.

    Thank you!

    SQL > select fi
    2, max (fo_fv) on fo_fv (fi control)
    3, jup_fv
    4, action
    5 of the test;

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

    OR

    SQL > select *.
    2 test
    model 3
    Dimension 4 by (fi)
    5 measures (fo_fv, jup_fv, action)
    6 rules
    7   (
    8 fo_fv [any] = case when fo_fv [cv ()] is null
    9. can fo_fv [cv () - 1]
    10 fo_fv [cv () else]
    11 end
    (12);

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

  • need help with the query, thx

    Hello
    I need a little help with the query I have to write;
    the table has 4 columns:
    col1               col2         col3       col4
    emp_name     empl_id    salary      year
    
    content of data:
    
    col1               col2         col3       col4
    smith             12           1200      1999
    smith             12           1340      2000
    smith             12           1500      2001
    jones             13           1550      1999 
    jones             13           1600      2000
    aron              14           1200      2002
    what I am asking is the following result: salary according to the latest available year
    i.e.
    smith         12         1500        2001
    jones         13         1600        2000
    aron          14         1200        2002
    ID appreciate some guidance on how to achieve
    Thank you
    Rgds
    select *from
    (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc)  rn  from 
    ) where rn=1
    
  • When no rows returned in the query loop, replace Null - need help

    Hello

    I have a requirement where I have a request in the loop for and based on the results of the query, I do some operations.

    But even if the query does not match, I should get back something like 'No Data'.

    My loop is:

    FOR V_SL IN)
    SELECT ID, CATEGORY, DI_CD, REV_CD, SL_ID
    OF SB, SLOT_2001 S2 SLOT_DATA WHERE
    PBM BENEFIT_ID = S2. BENEFIT_ID AND
    REV_CD = IN_REV_CD AND
    (PROC_CD IS NULL OR PROC_CD = IN_PROC_CD)
    ORDER OF DIAGCODE, PROCEDURECODE)
    LOOP
    END LOOP;

    I do some operations inside the loop for. I want the loop to run even if the query returns no rows.

    Can someone help me out here.

    Thank you
    Rambeau

    Frank. I am really surprised to see this coming from you. A slider to not find all the lines loop does not cause an exception no_data_found.

Maybe you are looking for

  • Inbox, Outbox and drafts of files that have been deleted, but they do not show in the box of

    My Inbox, sent, and projects files are several hundred megebytes of size. If I check with a hex editor, I find messages that are years old, even though I have specified that messages about six months are automatically deleted. When I look at the file

  • Can I upgrade my 4 GB ao722 memory 8 GB? Of memory should what brand I use?

    I have an AO722-0825.  I am looking to increase the speed and performance of this machine, and I wanted to upgrade the memory (and possibly Exchange in an SSD).  So my questions are: (1) is it possible to upgrade the memory on this machine? (2) what

  • (Redirected) Alienware X 51 R3 availability in India

    Hello world Anyone have an idea on the Alienware X 51 R3 launch date, price and availability in India? A crossed a lot of Web sites, could not find anything. :(

  • Screen does not persist

    Hi all! I created an application that uses WS. I have a screen to enter parameters for the research and then I call WS, this WS returns a list of details cust. I am able to get this list and I can analyze it too much. When I call getUiEngine () .push

  • Application and transport layer connection problems

    I'm running a redundant configuration: PIX 515E 6.3 (1). I have the following problems to servers on the Internet but only from certain sites. FTP - finishes negotiating 3 lanes and the 4th package which is used at the login prompt takes about 90 sec