Decode Fucntion Question

Hi,
I am trying to run this select query below and the IF-THEN-ELSE statement is not working... I am basically trying to update the CUSTOMER.CUST_OPT_IN_RENTAL_IND column with 'N' flag to 'Y' WHERE cust_classif_tr3_FULL_NM ='VIP Program'
and CUST_OPT_IN_RENTAL_IND ='N'
and CUST_EMAIL_ADDR_IND = 'Y'
AND CUST_STAT_TR2_FULL_NM='Active' to be included in the query below. can anyone help please?
SELECT
CUSTOMER.CUSTOMER_SSKEY CUSTOMER_sskey,
TO_CHAR(( CUSTOMER.DATE_MODIFIED ),'MM/DD/YYYY') date_modified,
NVL(( CUSTOMER.SRC_CUST_ID ),( 'UNKNOWN' )) SRC_CUST_ID,
NVL(( CUSTOMER.EXTNL_CUST_ID ),( 'UNKNOWN' )) EXTNL_CUST_ID,
NVL(( TO_CHAR(( CUSTOMER.LAST_UPDATE_DT ),'MM/DD/YYYY') ),( '01/01/1900' )) LAST_UPDATE_DT,
NVL(( CUSTOMER.SUB_CONTNT_CD ),( 'UNKNO' )) SUB_CONTNT_CD,
NVL(( CUSTOMER.SUB_CONTNT_NM ),( 'UNKNOWN' )) SUB_CONTNT_NM,
DECODE((CUST_EMAIL_ADDR_IND ),( 'N' ),( '-')
, ( 'Y' ), ( 'EPITEST'|| LPAD(MOD(ROWNUM,100),3,'0')||'@INTERVALINTL.COM')
) email_address,
IF CUSTOMER.CUST_OPT_IN_RENTAL_IND :='N' THEN result :='Y';
ELSIF CUSTOMER.CUST_OPT_IN_RENTAL_IND :='N' THEN result := 'VIP Program' cust_classif_tr3_FULL_NM;
ELSIF CUSTOMER.CUST_OPT_IN_RENTAL_IND :='N' THEN result := 'Y' CUST_EMAIL_ADDR_IND;
ELSIF CUSTOMER.CUST_OPT_IN_RENTAL_IND :='N' THEN result := 'Active' CUST_STAT_TR2_FULL_NM;
ELSIF
END IF;
NVL(( CUSTOMER.EMAIL_FORMAT_PREF ),( 'UNKNOWN' )) email_format_pref,
NVL(( TRUNC( CUSTOMER.EMAIL_UNDELIVERABLE_COUNT ) ),( -1 )) email_undeliverable_count,
NVL(( CUSTOMER.EMAIL_HTML_CAPABILITY ),( 'UNKNOWN' )) email_html_capability,
NVL(( CUSTOMER.EMAIL_UNSUBSCRIBE ),( 'UNKNOWN' )) email_unsubscribe,
NVL(( CUSTOMER.CUST_ID ),( 0 )) CUST_ID,
NVL(( CUSTOMER.ONLINE_PROFILE_FIRST_NAME ),( 'UNKNOWN' )) ONLINE_PROFILE_FIRST_NAME,
NVL(( CUSTOMER.ONLINE_PROFILE_LAST_NAME ),( 'UNKNOWN' )) ONLINE_PROFILE_LAST_NAME,
NVL(( CUSTOMER.GOLD_BILL_TYPE_TR1_CD ),( 'UNKNO' )) GOLD_BILL_TYPE_TR1_CD,
NVL(( CUSTOMER.GOLD_BILL_TYPE_TR1_FULL_NM ),( 'UNKNOWN' )) GOLD_BILL_TYPE_TR1_FULL_NM,
NVL(( CUSTOMER.GOLD_BILL_TYPE_TR2_CD ),( 'UNKNO' )) GOLD_BILL_TYPE_TR2_CD
FROM
     CUSTOMERSTAGE CUSTOMER
Thanks,
Soph

Hi, Soph,
Welcome to the forum!
Whenever you hav a question, post a little sample data (CREATE TABLE and INSERT statments) and the resutls you want from that data.
In the case of a DML problem (such as UPDATE), the sample data should show what the tabels are like before the change, and the reuslts will be the contents of the changed table after it.
Always say what version of Oracle you're using.
Without that, people will still try to help you as much as they can, but that won't be much.
IF-THEN-ELSE is PL/SQL. You can't use PL/SQL statements in the middle of a SQL staement, such as SELECT, even if the SQL statement is being doen within PL/SQL.
Instead of IF-THEN-ELSE, you can use CASE in SQL, or, in some special situations, DECODE.
Here's an example of using CASE:
Say you have a column in your table called cust_opt_in_rental, and it could have the values 'N'. 'N1', 'N2' or 'N3'.
You want to produce a column in your result set called result, which will be derived from cust_opt_in_rental.
If cust_opt_in_rental is 'N', then result should be ''Y'
If cust_opt_in_rental is 'N1', then result should be 'VIP Program' followed by the column cust_classif_tr3_FULL_NM
If cust_opt_in_rental is 'N2', then result should be 'Y' followed by the column CUST_EMAIL_ADDR_IND
If cust_opt_in_rental is 'N3', then result should be 'Active' fololowed by the column CUST_STAT_TR2_FULL_NM
You can do that using CASE like this:
SELECT  CASE     customer.cust_opt_in_rental_ind
          WHEN  'N'   THEN  'Y';
          WHEN  'N1'  THEN  'VIP Program '  || cust_classif_tr3_full_nm
          WHEN  'N2'  THEN  'Y '         || cust_email_addr_ind
          WHEN  'N3'  THEN  'Active '       || cust_stat_tr2_full_nm
     END             AS result
FROM     ...This is one situation where DECODE would work as well.

Similar Messages

  • DECODE SQL Question.

    Hello all -
    I'm trying to use the DECODE function in a SQL statement I'm building but what I'm trying to do, I've never done before. Below is the portion that I'm struggling with in that I'm receiving an error message but can't understand why I am as all parenthesis have been accounted for. Any help would be greatly appreciated as I have run out of options.
    SELECT
    DECODE(golfer1_score - 148, (golfer1_score - 148 < 0), (golfer1_score - 148) * -1, golfer1_score - 148) golferdiff1
    FROM......
    DECODE(golfer1_score - 148, (golfer1_score - 148 < 0), (golfer1_score - 148) * -1, golfer1_score - 148) golferdiff1,
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    (NOTE: The "*" is over the "<" compare)
    Thanks,
    Mark

    Gabe,
    Thanks for your help with the absolute function. It worked perfectly.
    Thanks,
    Mark

  • Analytical fucntion question?

    hello all. I have an analytical question. I have found couple good examples on how to concatenate several rows into one. But I have not been able to get this to work a specific way.
    Oracle 9.2.0.6.0
    Given the following data:
    table fred.
    ORDER_NUMBER_HW                        ORDER_NUMBER_SVC                       SERIAL_NUMBER                
    11                                     123                                    bb                           
    11                                     123                                    aa                           
    11                                     456                                    bb                            I would like to see the following output
    ORDER_NUMBER_HW                        SERVICE_ORDERS          SERIAL_NUMBERS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    11                                     123,456                 aa,bb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        I have used the following sql to come up with the results below, but i do not want to see the duplicate values in the concatenated strings.
    This is what i get now. Any suggestions on how to fix this so I don't get the duplicate info in the concatenated strings?
    ORDER_NUMBER_HW                        SERVICE_ORDERS      SERIAL_NUMBERS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    11                                     123,123,456         bb,aa,bb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    SELECT     order_number_hw
              ,LTRIM(SYS_CONNECT_BY_PATH(order_number_svc, ','), ',') service_orders
              ,LTRIM(SYS_CONNECT_BY_PATH(serial_number, ','), ',') serial_numbers
          FROM (SELECT order_number_hw
                      ,order_number_svc
                      ,serial_number
                      ,ROW_NUMBER() OVER(PARTITION BY order_number_hw ORDER BY order_number_svc) rn
                      ,COUNT(*) OVER(PARTITION BY order_number_hw) cnt
                  FROM fred)
         WHERE rn = cnt
    START WITH rn = 1
    CONNECT BY PRIOR order_number_hw = order_number_hw AND PRIOR rn = rn - 1
      ORDER BY serial_number;
    table creation.
    CREATE TABLE FRED
      ORDER_NUMBER_HW   NUMBER                      NOT NULL,
      ORDER_NUMBER_SVC  NUMBER                      NOT NULL,
      SERIAL_NUMBER     VARCHAR2(30 BYTE)
    SET DEFINE OFF;
    Insert into FRED
       (ORDER_NUMBER_HW, ORDER_NUMBER_SVC, SERIAL_NUMBER)
    Values
       (11, 123, 'bb');
    Insert into FRED
       (ORDER_NUMBER_HW, ORDER_NUMBER_SVC, SERIAL_NUMBER)
    Values
       (11, 123, 'aa');
    Insert into FRED
       (ORDER_NUMBER_HW, ORDER_NUMBER_SVC, SERIAL_NUMBER)
    Values
       (11, 456, 'bb');
    COMMIT;

    SQL> select order_number_hw,
      2         replace(replace(replace(LTRIM(SYS_CONNECT_BY_PATH(col1, ','), ','),',',',@'),'@,'),'@') service_orders,
      3         replace(replace(replace(LTRIM(SYS_CONNECT_BY_PATH(col2, ','), ','),',',',@'),'@,'),'@') serial_numbers
      4    from (select t.*,
      5                 lag(null, 1, order_number_svc) over(partition by order_number_hw, order_number_svc order by 1) col1,
      6                 lag(null, 1, serial_number) over(partition by order_number_hw, serial_number order by 1) col2,
      7                 row_number() over(partition by order_number_hw order by order_number_svc) rn,
      8                 COUNT(*) OVER(PARTITION BY order_number_hw) cnt
      9            from fred t)
    10   where rn = cnt
    11   START WITH rn = 1
    12  CONNECT BY PRIOR order_number_hw = order_number_hw
    13         AND PRIOR rn = rn - 1
    14  /
    ORDER_NUMBER_HW SERVICE_ORDERS      SERIAL_NUMBERS
                 11 123,456             aa,bb
    SQL>

  • Decoder/Encoder Question

    I have a G4 Ti 4200 8X with the built-in Philips Decoder/Encoder. I haven't used it and wanted to give it a try. What do I need to do so I can use an older, 8mm analog camcorder to capture from? It has standard RCA style video output. Do I just plug it into the the adaptor plug on the back of the card and start the software? Is there an optimal way to capture for decent quality? I just got a DVD burner and would like to be able to burn the 8mm tapes to DVD for long-term storage.
    Also, what about audio?
    Thanks.

    If the Camcorder has a S-video out jack, (Yellow) you plug that into the GFX S-video in jack.
    For sound, you need to plug the Camcorders audio ports (RED & WHITE) into your PC's sound card LINE in port. you may need a converter for this.
    Then the program should be able to record sound and Video at the same time.

  • Siri is not responding to any question

    Siri is not responding.  latest 8.1.2 iOS.  I have started and restarted many times.  Any question whatsoever is met with the same response "sorry, i can't find that right now, please try again."   ANY question - what time is it, what is the temperature, what is my name, dial John, etc.  Completely non responsive.  Do i just take the phone to Apple to be replaced????

    Before restoring your iPhone...
    Are you sure to have sufficient Internet for your iPhone? Preferably Wifi?
    Siri relies on being able to communicate with apple servers in order to decode your question. I get the message you get often when trying to use siri in areas with bad cellular reception and no wifi.
    So... watch some youtube videos. do they work?

  • ORA-1850: hor must be between 0 and 23 error

    Hi All
    i have the following table for creating and inserting i included only two fileds as these are the fields that i'm getting errors on.
    WITH     sample_data     AS
         SELECT     '50709' AS start_date, '2400' AS start_time  FROM dual     UNION ALL
         SELECT     '082510',              '0000'                  FROM dual
    SELECT       *
    FROM       sample_data
    ;DATA:
    START_DATE     START_TIME
    50709                        2400
    082510                        0000And now when i run the query against the table:
    SELECT   direction, car_count_pos, truck_count_pos,
             (car_count_pos + 2 * (truck_count_pos)) AS adjusted, car_count_neg,
             truck_count_neg,
             (car_count_neg + 2 * (truck_count_neg)) AS adjusted_neg,
             TO_DATE (start_date, 'MMDDYY') AS start_date,
             TO_DATE (end_date, 'MMDDYY') AS end_date,
             ROUND (TO_CHAR (TO_DATE (LPAD (start_time, 4, '0'), 'HH24MI'),
                             'HH24.MI'
                   ) AS start_time,
             start_time,
             (TO_DATE (end_date, 'MMDDYY') - TO_DATE (start_date, 'MMDDYY')
             ) AS days
        FROM (SELECT   (CASE
                           WHEN t1.direction = '1'
                              THEN (  COUNT (t1.bin_1_data)
                                    + COUNT (t1.bin_2_data)
                                    + COUNT (t1.bin_3_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS car_count_pos,
                       t1.direction,
                       (CASE
                           WHEN t1.direction = '1'
                              THEN (  COUNT (t1.bin_4_data)
                                    + COUNT (t1.bin_5_data)
                                    + COUNT (t1.bin_6_data)
                                    + COUNT (t1.bin_7_data)
                                    + COUNT (t1.bin_8_data)
                                    + COUNT (t1.bin_9_data)
                                    + COUNT (t1.bin_10_data)
                                    + COUNT (t1.bin_11_data)
                                    + COUNT (t1.bin_12_data)
                                    + COUNT (t1.bin_13_data)
                                    + COUNT (t1.bin_14_data)
                                    + COUNT (t1.bin_15_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS truck_count_pos,
                       (CASE
                           WHEN t1.direction = '3'
                              THEN (  COUNT (t1.bin_1_data)
                                    + COUNT (t1.bin_2_data)
                                    + COUNT (t1.bin_3_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS car_count_neg,
                       (CASE
                           WHEN t1.direction = '3'
                              THEN (  COUNT (t1.bin_4_data)
                                    + COUNT (t1.bin_5_data)
                                    + COUNT (t1.bin_6_data)
                                    + COUNT (t1.bin_7_data)
                                    + COUNT (t1.bin_8_data)
                                    + COUNT (t1.bin_9_data)
                                    + COUNT (t1.bin_10_data)
                                    + COUNT (t1.bin_11_data)
                                    + COUNT (t1.bin_12_data)
                                    + COUNT (t1.bin_13_data)
                                    + COUNT (t1.bin_14_data)
                                    + COUNT (t1.bin_15_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS truck_count_neg,
                       t2.start_date, t2.start_time, t2.end_date, t2.end_time
                  FROM bin_data t1, traffic_sample t2
                 WHERE t1.traffic_sample_id = t2.traffic_sample_id
              GROUP BY t1.direction,
                       t2.start_date,
                       t2.start_time,
                       t2.end_date,
                       t2.end_time)
       WHERE direction IN ('1', '3')
    GROUP BY TO_DATE (start_date, 'MMDDYY'),
             direction,
             car_count_pos,
             truck_count_pos,
             (car_count_pos + 2 * (truck_count_pos)),
             truck_count_neg,
             (car_count_neg + 2 * (truck_count_neg)),
             TO_DATE (end_date, 'MMDDYY'),
             ROUND (TO_CHAR (TO_DATE (LPAD (start_time, 4, '0'), 'HH24MI'),
                             'HH24.MI'
             start_time,
             car_count_negI'm getting the error
    ORA-1850: Hour must be between 0 and 23
    But as you see there is a value 2400 in the table is there any way to get around this? please need help.
    Thanks
    Edited by: thinkingeye on Aug 26, 2010 8:42 AM

    Thanks AP but i came up with something different which i guess sserved the same purpose i used the DECODE fucntion in the INNER query.
    SELECT   direction, car_count_pos, truck_count_pos,
             (car_count_pos + 2 * (truck_count_pos)) AS adjusted, car_count_neg,
             truck_count_neg,
             (car_count_neg + 2 * (truck_count_neg)) AS adjusted_neg,
             TO_DATE (start_date, 'MMDDYY') AS start_date,
             TO_DATE (end_date, 'MMDDYY') AS end_date,
             ROUND (TO_CHAR (TO_DATE (LPAD (start_time, 4, '0'), 'HH24MI'),
                             'HH24.MI'
                   ) AS start_time,
                   ROUND (TO_CHAR (TO_DATE (LPAD (end_time, 4, '0'), 'HH24MI'),
                             'HH24.MI'
                   ) AS end_time,
             start_time,
             (TO_DATE (end_date, 'MMDDYY') - TO_DATE (start_date, 'MMDDYY')
             ) AS days,
             CITY,COUNTY,LOCATION,ROUTE_NBR,ROUTE_TYPE
        FROM (SELECT   (CASE
                           WHEN t1.direction = '1'
                              THEN (  COUNT (t1.bin_1_data)
                                    + COUNT (t1.bin_2_data)
                                    + COUNT (t1.bin_3_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS car_count_pos,
                       t1.direction,
                       (CASE
                           WHEN t1.direction = '1'
                              THEN (  COUNT (t1.bin_4_data)
                                    + COUNT (t1.bin_5_data)
                                    + COUNT (t1.bin_6_data)
                                    + COUNT (t1.bin_7_data)
                                    + COUNT (t1.bin_8_data)
                                    + COUNT (t1.bin_9_data)
                                    + COUNT (t1.bin_10_data)
                                    + COUNT (t1.bin_11_data)
                                    + COUNT (t1.bin_12_data)
                                    + COUNT (t1.bin_13_data)
                                    + COUNT (t1.bin_14_data)
                                    + COUNT (t1.bin_15_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS truck_count_pos,
                       (CASE
                           WHEN t1.direction = '3'
                              THEN (  COUNT (t1.bin_1_data)
                                    + COUNT (t1.bin_2_data)
                                    + COUNT (t1.bin_3_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS car_count_neg,
                       (CASE
                           WHEN t1.direction = '3'
                              THEN (  COUNT (t1.bin_4_data)
                                    + COUNT (t1.bin_5_data)
                                    + COUNT (t1.bin_6_data)
                                    + COUNT (t1.bin_7_data)
                                    + COUNT (t1.bin_8_data)
                                    + COUNT (t1.bin_9_data)
                                    + COUNT (t1.bin_10_data)
                                    + COUNT (t1.bin_11_data)
                                    + COUNT (t1.bin_12_data)
                                    + COUNT (t1.bin_13_data)
                                    + COUNT (t1.bin_14_data)
                                    + COUNT (t1.bin_15_data) * 0.981 * 1.019
                           ELSE NULL
                        END
                       ) AS truck_count_neg,
                       t2.start_date, t2.start_time, t2.end_date,*decode(t2.END_TIME,2400,'2359',t2.end_time) as end_time*,t3.CITY, t3.COUNTY,t3.LOCATION,t3.ROUTE_NBR, t3.ROUTE_TYPE
                  FROM bin_data t1, traffic_sample t2,location_details t3
                 WHERE t1.traffic_sample_id = t2.traffic_sample_id
                 and t2.TRAFFIC_SAMPLE_ID=t3.TRAFFIC_SAMPLE_ID
              GROUP BY t1.direction,
                       t2.start_date,
                       t2.start_time,
                       t2.end_date,
                       t2.end_time,
                       t3.CITY, t3.COUNTY,t3.LOCATION,t3.ROUTE_NBR, t3.ROUTE_TYPE)
       WHERE direction IN ('1', '3')
    GROUP BY TO_DATE (start_date, 'MMDDYY'),
             direction,
             car_count_pos,
             truck_count_pos,
             (car_count_pos + 2 * (truck_count_pos)),
             truck_count_neg,
             (car_count_neg + 2 * (truck_count_neg)),
             TO_DATE (end_date, 'MMDDYY'),
             ROUND (TO_CHAR (TO_DATE (LPAD (start_time, 4, '0'), 'HH24MI'),
                             'HH24.MI'
             start_time,
             car_count_neg,
             end_time,
             CITY,COUNTY,LOCATION,ROUTE_NBR,ROUTE_TYPE

  • Question regarding decode function.

    Hi friends,
    I have a question regarding using decode.
    I'm try'g to explain my problem using emp table.
    Can you guys please help me out.
    For example consider emp table, now i want to get all manager id's concatenated for 2 employees.
    I tried using following code
    declare
    v_mgr_code  number(10);
    v_mgr1      number(4);
    v_mgr2      number(4);
    begin
    select  mgr into    v_mgr1
    from    scott.emp
    where   empno = 7369;
    select  mgr into    v_mgr2
    from    scott.emp
    where   empno = 7499;
    select v_mgr1||'-'||v_mgr2 into v_mgr_code from dual;
    end;now instead of writing 2 select statements can i write one select statement using decode function ?
    Edited by: user642856 on Mar 8, 2009 11:18 PM

    i don't know wheter your looking for this or not.if i am wrong correct me.
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7902),
            'Do Not Know')  Manager from empor
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7902)) manager
    from empEdited by: user4587979 on Mar 8, 2009 9:52 PM

  • DECODE QUESTION

    I have 4 columns that I want to test for the existance of a value greater than 0 in order of last to first and then return the value of the first column found that has a value > 0.
    I have columns discount_2,discount_1,supplier_2 and supplier_1. When I try to decode these columns it will return a value when there is a value in discount_1 or 2 but not when there is not a value in discount_1 or 2 and there is a value in supplier_1 or 2.
    My decode statement looks like:
    DECODE(DISCOUNT_2,NULL,DISCOUNT_1,
    DECODE(DISCOUNT_1,NULL,SUPPLIER_2),SUPPLIER_1) AS "ORIG_COST"
    Will the decode work in this example or would CASE work better and what would it look like?

    Hi,
    [email protected] wrote:
    Yes this worked well an is more legible than the COALESCE a glance.
    ThanksGlad to help!
    Be aware that
    CASE
         WHEN  discount2 > 0     THEN discount2
         WHEN  discount1 > 0     THEN discount1
         WHEN  supplier2 > 0     THEN supplier2
         WHEN  supplier1 > 0     THEN supplier1
    ENDis NOT the same as
    COALESCE ( discount2
          , discount1
          , supplier2
          , supplier1
          )if any of the values are less that or equal to 0.

  • Question on Decode function.

    I have the following table structure.
    Table name: TMP_tab_1
    Columns: role_id
    : comm_code
    : amount
    I need to write a sql statement for
    If role_id = 280 and comm_code <> 330 then
    sum(amount)
    end if
    Please advise how to use decode to resolve the above issue.
    Thanks.

    Why decode?
    select sum(amount) from TMP_tab_1 where role_id=280 and comm_code<>330;
    Above returns the amount summed for all rows.
    If you have non-distinct role/comm and you want amounts summed at that level
    select role_id, comm_code, sum(amount)
    from TMP_tab_1
    where role_id=280 and comm_code<>330
    group by role_id, comm_code;
    If you need to see everybody but suppress amount for many, then
    select role_id, comm_code, sum(decode(role_id, 280,decode(comm_code, 330,0, amount), 0))
    from TMP_tab_1
    group by role_id, comm_code;

  • Question with decode

    What I want to do is have 'o.supplier_id = w.city' not only display the name of the city, but to add the word "warehouse" at the end automatically each time. How would I do that here?
    select o.ord_id,
    decode(o.order_status, 'C', 'Order completed', 'o.supplier_id = w.city') Order_destination,
    from orders o,
    warehouses w
    where o.ord_id = w.city
    group by o.ord_id;

    Hi,
    Are you saying the query is working okay now, but instead of 'o.supplier_id = w.city' you want it to say 'o.supplier_id = w.city warehouse'?
    If so, change 'o.supplier_id = w.city' to 'o.supplier_id = w.city warehouse'
    select    o.ord_id,
              decode ( o.order_status,
                   'C',             'Order completed',
                              'o.supplier_id = w.city warehouse'
               ) Order_destination,
    from      orders o,
              warehouses w
    where     o.ord_id = w.city
    group by  o.ord_idIf you want something else (e.g., if status is not 'C', then you want to compare o.supplier_id to w.city) then post a little sample data, and the results you want from that data (formatted, between tags).
    You'll almost certainly want to use CASE instead of DECODE.  If you have to ask about how to do something in DECODE, then the solution is going to be needlessly complicated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Base64 encode decode question

    Hi
    I use the auclair base64 class to encode and decode base64 locally and it works great.
    But when I send the string to my server and back (aspx), I cannot decode it I have the 2030 error from flash.
    When I compare the encoded string from both end they look the same.
    I make sure it is fully loaded before attempting the decode.
    Is this a common bug or I'm I wrong somewhere?
    Thanks
    I use the latest air.

    The -d switch on the openssl base64 command enables debugging; it's the short version of the --debug switch.  Probably not what you're after, either.  The -D switch would be more typical, that's the short version of --decode switch, and probably what you had intended.
    The -i (--input) and -o (--output) switches allow you to specify input and output files, which is one way to pass a whole lot of data into that command.
    Do you have an example of some of the text that you're working with?

  • Question about decode

    hi all
    i have a table called employee_report
    PRCNT_DOWN number(5,2)
    i want to show the precent with the sign %
    lets say that the values are
    PRCNT_DOWN
    0
    0
    5
    3
    so i did like this
    select decode(0,0,(to_char(PRCNT_DOWN,'999.99')||'%')) as aa from employee_report the problem is that when PRCNT_DOWN equal 0 the result is .00%
    i want that if the precent is 0 it will show nothing ,
    so i did
    select decode(0,' ',(to_char(PRCNT_DOWN,'999.99')||'%')) as aa from employee_report
    so it shows space to all of the column even if they contain a value , what is the solution to this kind of problem ?
    Thanks
    Naama

    naama wrote:
    select decode(0,0,(to_char(PRCNT_DOWN,'999.99')||'%')) as aa from employee_report the problem is that when PRCNT_DOWN equal 0 the result is .00%
    i want that if the precent is 0 it will show nothing ,you almost had it. Just use the column as the first parameter in the decode. Then add the values that need special handling and add the "else" part as the very last parameter.
    such as here
    select decode(PRCNT_DOWN
                         ,0,NULL
                        ,to_char(PRCNT_DOWN,'FM9G990D00')||'%'
                        ) as aa
    from employee_report
    example
    select decode(9.876
                     ,0,null
                     ,to_char(9.876,'FM9G990D00')||'%'
    from dual;
    9.88%Edited by: Sven W. on Dec 16, 2010 1:51 PM - changed formating

  • Simple decode question

    I got a table called customer_issue_tab which has a column called "IS_AUTH".
    If the value of "IS_AUTH" is true then i shoudl display the row else I should check the status of the "CUST_ORDER_TAB" and if the status = "released" then display the row.
    How do i put these into a select stmt using a DECODE function
    code sample would be ideal
    Thanks
    Parsh
    Edited by: [email protected] on Jul 6, 2009 9:28 AM

    Hi,
    The answer to "How can I ... using DECODE?' is always "Don't use DECODE." If you have to ask, then it's too complicated.
    CASE is the most common alternative to DECODE.
    If you wanted to use the results in a WHERE clause, why not use the conditions in a WHERE clause, without DECODE?
    Something like this, perhaps:
    {code}
    WHERE     is_auth = 'TRUE'
    OR     EXISTS ( SELECT 1
              FROM     cust_order_tab
              WHERE     status = 'released'
              AND     order_no = customer_issue_tab.order_no
    {code}
    If you need help, post a little sample data, and the results you want from that data.

  • Question about encoding/decoding a custom UIComponent

    Hello,
    I am trying to create a custom JSF component using the following code :
    class UICustomCTP extends UIInput {
          * Component that holds a list of Norms
         public static final String COMPONENT_TYPE = "org.alfresco.faces.CustomCTPInput";
         public static final String COMPONENT_FAMILY = "javax.faces.UIInput";
         // ID's
         private static final String ID_CTPKEY_FLD = "-ctpkey-field";
         private static final String ID_CTPDESC_LST = "-ctpdesc-list";
         @Override
         public String getFamily() {
              return COMPONENT_FAMILY;
         @Override
         public void encodeBegin(FacesContext context) throws IOException {
              // Set-up the dynamic id's
              String idClient = getClientId(context);
              String idCtpKey = idClient + ID_CTPKEY_FLD;
              String idCtpDescList = idClient + ID_CTPDESC_LST;
              ResponseWriter writer = context.getResponseWriter();
              writer.startElement("div", this);
              writer.writeAttribute("id", "ctp-container-part", null);
              writer.writeAttribute("class", "ctp-container-part-style", null);
              writer.write("R�sum� :");
              writer.startElement("input", this);
              writer.writeAttribute("id", idCtpKey, idCtpKey); // is the property name should be the same as the key?
              writer.writeAttribute("type", "text", null);
              writer.writeAttribute("value", "", null);
              writer.writeAttribute("style", "width:20px", null);
              writer.endElement("input");
              writer.startElement("select", this);
              writer.writeAttribute("id", idCtpDescList, idCtpDescList); // is the property name should be the same as the key?
              writer.writeAttribute("size", "5", null);
              writer.writeAttribute("style", "width:300px", null);
              writer.writeAttribute("multiple", "1", null);     
                   there's many option items here
              writer.endElement("select");
              writer.endElement("div");
              super.encodeBegin(context);
         @Override
         public void decode(FacesContext context) {
              super.decode(context);
              // Set-up the dynamic id's
              String idClient = getClientId(context);
              String idCtpKey = idClient + ID_CTPKEY_FLD;
              String idCtpDescList = idClient + ID_CTPDESC_LST;
              // retrieve the request
              Map requestParamMap = context.getExternalContext().getRequestParameterMap();
              String ctpKeyInputValue = (String) requestParamMap.get(idCtpKey);
              List<String> ctpDescInputValueList = (List<String>) requestParamMap.get(idCtpDescList);
              Object ctp = new CTPItem(ctpKeyInputValue, ctpDescInputValueList);
              setSubmittedValue(ctp);
              setValid(true);
         @Override
         protected Object getConvertedValue(FacesContext context, Object submittedValue) {
              CTPItem ctpItem = (CTPItem)submittedValue;
              return ctpItem;
         } I don't have, and don't need and I cannot use renderer, tag definition, taglib definition because this component is generated through Alfresco ECM
    (and I don't have access to the JSP (not authorised)).
    My problem:
    When I try to read the inputs through request parameters :
          String ctpKeyInputValue = (String) requestParamMap.get(idCtpKey);
          List<String> ctpDescInputValueList = (List<String>) requestParamMap.get(idCtpDescList);It returns always null.
    It's is not very clear what value to put in the third parameters in writeAttribute and what is the logic behind with that property.
    It looks like I forget to implements something but cannot find what. I read many tutorials and forums but didn t find any solution.
    Thanks if somebody can help me.

    Silly me... just forget that id and name are not the same...
    Thanks, it work perfectly with name attributes.
    Regards,
    Patrick

  • DVD decoder question

    The majority of DVD decoders are available online for download. Problem is the computer I want to install the decoder onto does NOT have the internet. Could I purchase a physical CD with a DVD decoder on it or maybe download the DVD decoder on a computer with the internet then burn it to a CD?
    Suggestions.
    Thanks
    Points up for grabs

    Certainly .. I take it that you are backing up a DVD you already own? If you need to "decode" a DVD, use Mac The Ripper.
    http://www.mactheripper.org/
    You can then make a burnable folder (right click on desktop or ctrl+click and choose new burn folder). Place the downloaded .dmg file in this folder. Double-click on the folder and select Burn. Insert a blank CD-Rom and you're off!
    HTH-Gary
    Note: Don't delete the original .dmg file until after the burn. You will be placing an alias to the original file in the burn folder.

Maybe you are looking for

  • Can a Mac and a Win share the same music library on an external?

    I have a Powerbook, my wife a Toshiba laptop, both are authorized under my account. She's relatively new to iTunes and ipod so she has a small library on her Win machine. My Itunes library has grown so large I'm about to move it to an external drive.

  • Does it exist a manual for learning to use Oracle Forms?

    What I'm looking for is a manual or tutorial for using Oracle Forms. Looking at Oracle Documentation link http://www.oracle.com/technetwork/developer-tools/forms/documentation/10g-forms-091309.html I haven't found an user or developer guide. On the w

  • Auto copying to clipboard

    I am recieving this message when auto copying to clipboard, "signed.applets.codebase_principal_support=true" which is not allowing me to pick up the data from web pages that I copy from, grateful for any directions to solve this, many thanks

  • How do I get rid of script chrome://tavgp/content/libs/include.js:595. It stops me from starting.

    When I launch firefox, it stalls and I get a message that a script is already running. Do I want to continue or end script. When I hit end, it will work.

  • Firefox 12 keeps starting in full-screen mode.

    Ever since upgrading to Firefox 12, it wants to start up in full screen mode. I dopn't mean the extreme full screen mode where even the menu bar is hidden. I mean the more "typical" full screen mode where it just gets as large as possible but has the