Update statement with case statement

Hi
The following code is thorwing an error like
=====CODE==========
BEGIN
UPDATE emp SET SAL = CASE
WHEN ENAME = 'SCOTT' THEN SAL = 300
ELSE NULL;
END CASE;
END;
=====ERROR=======
ORA-06550: line 3, column 32:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 2, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 5, column 6:
PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
; 1.
2. BEGIN
3. UPDATE emp SET SAL = CASE
4. WHEN ENAME = 'SCOTT' THEN SAL = 300
5. ELSE NULL;
Any suggession?
Regards
Balaji

Hi,
Yes you are right, but it is not working for the multiple case statement like the following code
BEGIN
UPDATE emp SET SAL = CASE
WHEN ENAME='JONES' THEN '4';
WHEN ENAME='BLAKE' THEN '5'
WHEN ENAME='CLARK' THEN '6'
WHEN ENAME='TURNER' THEN '7'
WHEN ENAME='MILLER' THEN '8'
WHEN ENAME='MARTIN' THEN '9'
WHEN ENAME='WARD' THEN '10'
WHEN ENAME='ADAMS' THEN '11'
WHEN ENAME='JAMES' THEN '12'
WHEN ENAME='SMITH' THEN '13'
ELSE NULL END;
END;
The above code show the following error
===========ERROR==========
ORA-06550: line 3, column 29:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 2, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 4, column 2:
PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
1. BEGIN
2. UPDATE emp SET SAL = CASE
3. WHEN ENAME='JONES' THEN '4';
4. WHEN ENAME='BLAKE' THEN '5'
5. WHEN ENAME='CLARK' THEN '6'
Regards
Balaji
Edited by: 904493 on Jan 13, 2012 4:18 AM

Similar Messages

  • 11g outer join with case statement - strange results.

    Hello All,
    I am experiencing a strange issues in 11g while using case statement.
    I am not able to reproduce this using sample data. Not sure what is wrong.
    I am not narrowing it to say the usage of case statemnt is giving wrong results, but that is my observation when I am doing trail and error testing.
    Here are the details.
    My Version
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    SQL> My Query
    SELECT *
      FROM (SELECT DISTINCT mf.schedule,
                            mf.cptcode,
                            NVL (mf.modifier, '00') modifier2,
                            CASE
                               WHEN mf.feetype = 'H'
                                AND mf.multiplier IS NOT NULL THEN
                                  '      0.00'
                               WHEN (mf.feetype != 'H'
                                  OR  mf.feetype IS NULL)
                                AND mf.rbrvsvalue IS NOT NULL
                                AND mf.multiplier IS NOT NULL THEN
                                  LPAD ( TRIM (TO_CHAR ( (mf.rbrvsvalue * mf.multiplier) / 100, 9999999.99)), 10)
                               ELSE
                                  NULL
                            END
                               fee
              FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
             WHERE mf.schedule = 'SAPG1'
               AND mf.cptcode = vld.cptcode
               AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
           (SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
              FROM mpi_udffee.udffeeancfeedata arc
             WHERE monthofextract = '201202'
               AND arc.schedule = 'SAPG1'
               AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
    WHERE inline_fee.schedule = inline_data.col1(+)
       AND inline_fee.cptcode = inline_data.col2(+)
       AND inline_fee.modifier2 = inline_data.col3(+);
    In the above query the inline view inline_data returns zero rows. but NVL is still getting applied for col3 and I am getting 00 in the results( strange ).
    Results:
    SCHEDULE        CPTCO MODIFIER2  FEE             COL1  COL2  COL3
    SAPG1           49590 00             667.32                  00
    SAPG1           49611 00             781.03                  00
    SAPG1           49905 00             443.79                  00
    SAPG1           50205 00             883.56                  00
    SAPG1           50220 00            1315.15                  00
    SAPG1           50230 00            1638.74                  00
    SAPG1           50234 00            1666.16                  00
    SAPG1           50250 00            1566.14                  00
    SAPG1           50327 00             262.04                  00
    SAPG1           50541 00            1183.31                  00
    SAPG1           50620 00            1156.88                  00
    SAPG1           50650 00            1321.96                  00
    497 rows selected.
    Just the inline view inline_data,
    SQL> SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
      2            FROM mpi_udffee.udffeeancfeedata arc
      3           WHERE monthofextract = '201202'
      4             AND arc.schedule = 'SAPG1'
      5             AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate;
    no rows selectedMuch unusual thing is when I just remove the case statement from the inline view "inline_fee", I am getting right results,
    SELECT *
      FROM (SELECT DISTINCT mf.schedule,
                            mf.cptcode,
                            NVL (mf.modifier, '00') modifier2          <-- Removed Case statement here
              FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
             WHERE mf.schedule = 'SAPG1'
               AND mf.cptcode = vld.cptcode
               AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
           (SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
              FROM mpi_udffee.udffeeancfeedata arc
             WHERE monthofextract = '201202'
               AND arc.schedule = 'SAPG1'
               AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
    WHERE inline_fee.schedule = inline_data.col1(+)
       AND inline_fee.cptcode = inline_data.col2(+)
       AND inline_fee.modifier2 = inline_data.col3(+);
    SCHEDULE        CPTCO MODIFIER2  COL1  COL2  COL3
    SAPG1           46730 00
    SAPG1           46735 00
    SAPG1           46748 00
    SAPG1           46760 00
    SAPG1           46942 00
    SAPG1           46945 00
    SAPG1           47015 00
    SAPG1           47125 00
    SAPG1           47350 00
    SAPG1           47505 00
    SAPG1           47553 00interestingly explain plan for both the statements are exactly same,
    SELECT STATEMENT  ALL_ROWSCost: 138  Bytes: 1,078,274  Cardinality: 11,471                                
         9 HASH JOIN RIGHT OUTER  Cost: 138  Bytes: 1,078,274  Cardinality: 11,471                           
              2 PARTITION RANGE EMPTY  Cost: 2  Bytes: 150  Cardinality: 3                      
                   1 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEANCFEEDATA Cost: 2  Bytes: 150  Cardinality: 3                 
              8 VIEW MPI_UDFFEE. Cost: 135  Bytes: 504,724  Cardinality: 11,471                      
                   7 HASH UNIQUE  Cost: 135  Bytes: 539,137  Cardinality: 11,471                 
                        6 HASH JOIN  Cost: 134  Bytes: 539,137  Cardinality: 11,471            
                             3 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEACTIVECPTCODES Cost: 13  Bytes: 177,345  Cardinality: 25,335       
                             5 PARTITION LIST SINGLE  Cost: 120  Bytes: 600,600  Cardinality: 15,015  Partition #: 8       
                                  4 INDEX RANGE SCAN INDEX (UNIQUE) REPRICE.PK_MPIFEE Cost: 120  Bytes: 600,600  Cardinality: 15,015  Partition #: 9  Partitions accessed #11Is there anything wrong with the query? If not have anyone come across this issue or posted it as a bug or is there a patch?
    Update:
    when I set the parameter "_complex_view_merging"=false I am getting the right results even with case statement. But I don want to do some thing unsupported.
    Are there any other viable solutions?
    I appreciate the help.
    Thanks,
    G.
    Edited by: Ganesh Srivatsav on Apr 10, 2012 12:37 PM

    Hi Tubby,
    Right, the query transformation is going wrong. Following is from trace,
    SELECT "INLINE_FEE"."SCHEDULE" "SCHEDULE",
           "INLINE_FEE"."CPTCODE" "CPTCODE",
           "INLINE_FEE"."MODIFIER2" "MODIFIER2",
           "INLINE_FEE"."FEE" "FEE",
           "ARC"."SCHEDULE" "COL1",
           "ARC"."PROCEDURECODE" "COL2",
           CASE
              WHEN "ARC".ROWID IS NOT NULL THEN NVL ("ARC"."MODIFIER", '00')
              ELSE NULL
           END
              "COL3"
      FROM (SELECT DISTINCT "MF"."SCHEDULE" "SCHEDULE",
                            "MF"."CPTCODE" "CPTCODE",
                            NVL ("MF"."MODIFIER", :B2) "MODIFIER2",
                            CASE
                               WHEN ("MF"."FEETYPE" = :B3
                                 AND "MF"."MULTIPLIER" IS NOT NULL) THEN
                                  :B4
                               WHEN ( ("MF"."FEETYPE" <> :B5
                                    OR  "MF"."FEETYPE" IS NULL)
                                 AND "MF"."RBRVSVALUE" IS NOT NULL
                                 AND "MF"."MULTIPLIER" IS NOT NULL) THEN
                                  LPAD ( TRIM (TO_CHAR ( "MF"."RBRVSVALUE" * "MF"."MULTIPLIER" / :B6, :B7)), :B8)
                               ELSE
                                  NULL
                            END
                               "FEE"
              FROM "PROVIDER"."MPIFEE" "MF", "MPI_UDFFEE"."UDFFEEACTIVECPTCODES" "VLD"
             WHERE "MF"."SCHEDULE" = 'SAPG1'
               AND "MF"."CPTCODE" = "VLD"."CPTCODE"
               AND NVL ("MF"."MODIFIER", 'NULL') = NVL ("VLD"."MODIFIER", 'NULL')) "INLINE_FEE",
           "MPI_UDFFEE"."UDFFEEANCFEEDATA" "ARC"
    WHERE "INLINE_FEE"."SCHEDULE" = "ARC"."SCHEDULE"(+)
       AND "INLINE_FEE"."CPTCODE" = "ARC"."PROCEDURECODE"(+)
       AND "INLINE_FEE"."MODIFIER2" = CASE
                                         WHEN ("ARC".ROWID(+) IS NOT NULL) THEN NVL ("ARC"."MODIFIER"(+), '00')
                                         ELSE NULL
                                      END
       AND "ARC"."MONTHOFEXTRACT"(+) = '201202'
       AND "ARC"."SCHEDULE"(+) = 'SAPG1'
       AND TRUNC (SYSDATE-10) >= "ARC"."RECORDEFFECTIVEDATE"(+)
       AND TRUNC (SYSDATE-10) <= "ARC"."RECORDTERMINATIONDATE"(+)Does this refer to a specific bug?
    Thanks,
    G.

  • Using Presentation variables..along with case statements..

    Hi All.
    I have a issue using presentation variable along with CASE statements. My approach is
    1) I have a dashboard prompt, which is being set as Presentation variable.
    Based on the value selected in prompt, for ex the values of prompt can be 'ABC' and 'DEF'.
    I have a calculated column, the calculation goes this way...
    The forumal is
    CASE WHEN @{Presentation Variable Name} = 'ABC' THEN xxxxxxxxxx ELSE IF @{Presentation Variable Name} = 'DEF' END. It gives error of "no table being referenced"..
    Is this is the right approach??
    Can i get the values of variable in a column formula, so that a column can have values selected in prompt?
    Can anybody pls help me here..
    Thanks in advance...

    Hi
    Thanks for the quick response..
    I agree to ur point..
    But the requirement is
    Based on the value of the prompt I need to switch the calculation in one of the formula area of one column..
    If Prompt value is ABC then one kind of calculation in Fx and If the prompt value is DEF then one kind of calculation in the same Fx..
    How can I acheive this?
    Thanks in advance..

  • Update with case statement problem.

    Hi,
    I have this statement
    update tab_tr set col_rate =
      case
      when col_ern_type in ('031','035','036') then (1.5 * col_rate)
      when col_ern_type in ('041','045','046') then (2 * col_rate)
    end;this statement updated some 2 million rows in the table tab_tr. But the total count of rows for col_ern_type in ('031','035','036', '041','045','046') yeild only around 222642 rows.
    select count(*) from tab_tr where col_ern_type in ('031','035','036', '041','045','046');  --> 222642 rowswhat is the problem with the above update statement.
    Thank you,

    Hi,
    DBA_1976 wrote:
    ... I thought the case statement conditions are counted as the where condition. But ......A CASE expression just takes the place of some other expression, such as a literal, a function, or a column.
    For example, which rows do you think this should update?
    UPDATE  tab_tr
    SET     col_rate  = 100;It would update all rows, of course.
    How about this statement?
    UPDATE  tab_tr
    SET     col_rate  = column_x;Will it only change the rows where column_x are a certain value, or not NULL, or in any way depend on column_x? No, of course not. It will update all rows.
    How about this statement?
    UPDATE  tab_tr
    SET     col_rate  = function_y (col_ern_type);Will it only change the rows where the fucntion returns a certain value? Will it depend on the value in col_ern_type? No, of course not. It calls the function for each row, and whatever the function returns (even if the function returns NULL), that's what goes into col_rate on each row.
    A CASE expression is just something that you can substitute in place of any other expression, such as the literal 100, or the column column_x, or the function function_y in the statements above. Naturally, the value that gets put into col_rate will depend on what the CASE expression returns, but the behavior of the UPDATE statement as a whole will not.

  • Update statement with Case

    Hi,
    I need to construct an SQL Update statement that uses a case statement.
    I was able to construct one:
    UPDATE tableB
    SET col1 = CASE WHEN (0, 0) = (SELECT col1, col2
    FROM tableA
    WHERE <tableA constraints> )
    THEN "this value"
    ELSE "that value"
    END
    WHERE <tableB constraints>;
    But what I need to do now is to have some comparison inside the CASE WHEN statement, like:
    UPDATE tableB
    SET col1 = CASE WHEN (SELECT col1 from tableA WHERE <tableA constraints> > 0
    AND
    SELECT col2 from tableA WHERE <tableA constraints> > 0
    THEN "this value"
    ELSE "that value"
    END
    WHERE <tableB constraints>;
    Basically, the case would need to pass two (or more) constraints before updating the valuefor tableB.
    By the way, I was able to do this with just one constraint inside the case statement, but I need to pass more than one constraint inside the case.
    Your inputs would be highly appreciated. Thanks.
    Regards,
    Edited by: BatutaBunsing on Jul 22, 2009 6:42 PM

    Example Test
    UPDATE emp
    SET    ename = CASE
                     WHEN (SELECT 1
                           FROM   dual
                           WHERE  1 = 1) > 0 --// condition TRUE
                          AND (SELECT 1
                               FROM   dual
                               WHERE  1 = 1) > 0  --// condition TRUE
                     THEN 'this value'
                     ELSE 'that value'
                   END
    WHERE  empno = 7369
    1 row updated.
    SQL> select * from emp ;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 this value CLERK           7902 17-DEC-80        800                    99
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
    UPDATE emp
    SET    ename = CASE
                      WHEN (SELECT 1
                            FROM   dual
                            WHERE  1 = 2) > 0 --// condition FALSE
                           AND (SELECT 1
                                FROM   dual
                                WHERE  1 = 1) > 0 --// condition TRUE
                      THEN 'this value'
                      ELSE 'that value'
                    END
    WHERE  empno = 7369
    1 row updated.
    SQL> select * from emp ;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 that value CLERK           7902 17-DEC-80        800                    99
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    ...SS

  • Update statement with CASE and banding

    Hello Folks,
    I am stuck and am going nowhere.
    I have two tables
    MinuteCategory
    Minute
    MinuteCategory
    MinuteLookup
    MinuteCategoryId (surrogate key)
    MinuteLow
    MinuteHigh
    MinuteCategory
    Sample from Minute Lookup table ..
    1 1
    15 <15 min
    2 16
    30 <30 min
    3 31
    45 <45 min
    4 46
    60 <60 minutes
    5 61
    75 <1 hour 15 minutes
    I am trying to update the MinuteCategory column in the MinuteCategory table using the MinuteLookup table.
    For example if the minute = 33 then the corresponding lookup value would be 3 (from the lookup table), because the 
    33rd minute falls in between 31 min and 45 min and the corresponding surrogate key is 3
    Is this possible with an Update statement in SQL? The only thing i can think of is use case statement as the join key between
    the two tables but i don't think it's going to work :(
    UPDATE
    SET MinuteCategory = ml.MinuteCategoryId
    FROM MinuteCategory mc join MinuteLookup ml on mc.Minute = 
    CASE WHEN mc.Minute between ml.MinuteLow and ml.MinuteHigh THEN ml.MinuteCategoryId ELSE NULL
    END
    Would appreciate any help.
    SS

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have two tables <<
    Have you read any book on data, so you have some idea what a “<something>_category” means? THINK!! A minute is unit of temporal measurement. By definition, it cannot be a category. 
    There is no such thing as a “<something>_category_id”; a data element is a “<something>_category” or a “<something>_id”, as per basic data modeling. 
    Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton. 
    CREATE TABLE Timeslots
    (slot_start_time TIME(1) NOT NULL PRIMARY KEY,
     slot_end_time TIME(1) NOT NULL,
     CHECK (start_time < end_time));
    INSERT INTO Timeslots  --15 min intervals
    VALUES ('00:00:00.0', '00:14:59.9'),
    ('00:15:00.0', '00:29:59.9'),
    ('00:30:00.0', '00:44:59.9'),
    ('00:45:00.0', '01:00:59.9'), 
    ('23:45:00.0', '23:59:59.9'); 
    Here is the basic query for rounding down to a time slot. 
    SELECT CAST (@in_timestamp AS DATE), T.start_time
      FROM Timeslots AS T
     WHERE CAST (@in_timestamp AS TIME)
           BETWEEN T.slot_start_time 
               AND T.slot_end_time;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Update statement with Case syntax

    I want to put case statement in an update statement using Oracle 10g
    I'm getting a syntax error on the last line Ora-00933: SQL command not properly ended
    Help please
    UPDATE EMP a
    SET EMP.TYPE = CASE
    WHEN 'Y' = 'A' THEN 'DIV'
    WHEN 'Y' = '1' THEN 'DEF'
    END CASE;

    Hi,
    Samim wrote:
    I want to put case statement in an update statement using Oracle 10g
    I'm getting a syntax error on the last line Ora-00933: SQL command not properly ended
    Help please
    UPDATE EMP a
    SET EMP.TYPE = CASE
    WHEN 'Y' = 'A' THEN 'DIV'
    WHEN 'Y' = '1' THEN 'DEF'
    END CASE;The closing keyword that corresponds to "CASE" is "END", not "END *CASE* ".
    The string 'Y' is never equal to 'A', or to '1'.
    If you have a column named y in the table, then you might want to say:
    UPDATE EMP
    SET EMP.TYPE = CASE
                        WHEN Y = 'A' THEN 'DIV'
                        WHEN Y = '1' THEN 'DEF'
                  END;I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statemnts to re-create your emp table as it exists before the UPDATE), and the results you want from that data (that is, the contents of the emp table after the UPDATE).

  • Insert data with Case Statement

    Good Morning,
    I created table:
    CREATE TABLE DWG_LOG
    (     DL_ID_PK NUMBER NOT NULL ENABLE,
         DL_DRWNG_ID_FK"NUMBER,
         DL_REQUESTOR VARCHAR2(400 BYTE),
         DL_PHONE VARCHAR2(40 BYTE),
         DL_DATE_COPIED DATE,
         DL_APPROVER VARCHAR2(400 BYTE),
         DL_NOTES VARCHAR2(100 BYTE),
         DL_REQ_EMAIL VARCHAR2(60 BYTE),
         DL_DATE_DUE DATE,
         DL_PAST_DUE VARCHAR2(400 BYTE))
    The goal is to populate the DL_PAST_DUE field with a 1 if the date is greater than 90 days else leave NULL. With the help of other more senior developers from OTN I have narrowed my logic to using a CASE Statement instead of a FUNCTION. Below is the projected CASE statement that I am trying to use:
    DECLARE
    v_copied_date DWG_LOG.DL_DATE_COPIED%TYPE;
    v_curr_date SYSDATE;
    BEGIN
    SELECT DL_DATE_COPIED INTO v_copied_date
    FROM DWG_LOG
    CASE
    WHEN (v_curr_date - v_copied_date) > 90 THEN
    INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('1');
    ELSE
    INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('0');
    END CASE;
    END;
    I am getting the following errors when I run this code in SQL*PLus:
    ERROR at line 10:
    ORA-06550: line 10, column 4:
    PL/SQL: ORA-00933: SQL command not properly ended
    ORA-06550: line 7, column 4:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 12, column 4:
    PLS-00103: Encountered the symbol "ELSE" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimite
    ORA-06550: line 14, column 8:
    PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
    if
    PLEASE, point me in the right direction I know my syntax is off I just don't know where. I will continue to research and refine my script.
    HUMBLY SUBMITTED
    Markus

    I APOLOGIZE
    Good Morning, I created table:
    CREATE TABLE DWG_LOG (
    DL_ID_PK NUMBER NOT NULL ENABLE,
    DL_DRWNG_ID_FK"NUMBER,
    DL_REQUESTOR VARCHAR2(400 BYTE),
    DL_PHONE VARCHAR2(40 BYTE),
    DL_DATE_COPIED DATE,
    DL_APPROVER VARCHAR2(400 BYTE),
    DL_NOTES VARCHAR2(100 BYTE),
    DL_REQ_EMAIL VARCHAR2(60 BYTE),
    DL_DATE_DUE DATE,
    DL_PAST_DUE VARCHAR2(400 BYTE))
    [pre/]
    The goal is to populate the DL_PAST_DUE field with a 1 if the date is greater than 90 days else leave NULL. With the help of other more senior developers from OTN I have narrowed my logic to using a CASE Statement instead of a FUNCTION. Below is the projected CASE statement that I am trying to use:
    DECLARE
    v_copied_date DWG_LOG.DL_DATE_COPIED%TYPE;
    v_curr_date SYSDATE;
    BEGIN
    SELECT DL_DATE_COPIED INTO v_copied_date
    FROM DWG_LOG;
    CASE
    WHEN    (v_curr_date - v_copied_date) > 90 THEN
    INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('1');
    ELSE
    INSERT INTO DWG_LOG (DL_PAST_DUE) VALUES ('0');
    END CASE;
    END;
    I am getting the following errors when I run this code in SQL*PLus: ERROR at line 10: ORA-06550: line 10, column 4: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 7, column 4: PL/SQL: SQL Statement ignored ORA-06550: line 12, column 4: PLS-00103: Encountered the symbol "ELSE" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimite ORA-06550: line 14, column 8:
    PLS-00103: Encountered the symbol “CASE” when expecting one of the following:
    if                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Update in a Case statement

    hi
    I have a case statement as
    SELECT BB.ID,
    CASE WHEN BB.TITLE != AA.PREFIX THEN AA.PREFIX ELSE NULL END "PREFIX",
    CASE WHEN BB.LST_NAME != AA.SPRIDEN_LAST_NAME THEN AA.LAST_NAME ELSE NULL END "LAST_NAME",
         CASE WHEN BB.FST_NAME != AA.FIRST_NAME THEN AA.FIRST_NAME ELSE NULL END "FIRST_NAME",
    FROM NAME1 BB, NAME2 AA WHERE NAME1.ID = AA.NAME2.ID
    I would like to take the results into a new table NAME3
    with coulumns NAME_ID,NAME_PREFIX,NAME_LAST_NAME,NAME_FIRST_NAME
    like CASE WHEN WHEN BB.TITLE != AA.PREFIX THEN (UPDATE TABLE NAME3 SET name_prefix= AA.PREFIX WHERE NAME1.ID=NAME.ID)
    please help me with the syntax

    Hi,
    If you are updating Name3 then you can use the below query
    UPDATE table NAME3 NAME3
       SET (NAME_ID,NAME_PREFIX,NAME_LAST_NAME,NAME_FIRST_NAME) =
    SELECT BB.ID,
    CASE WHEN BB.TITLE != AA.PREFIX THEN AA.PREFIX ELSE NULL END "PREFIX",
    CASE WHEN BB.LST_NAME != AA.SPRIDEN_LAST_NAME THEN AA.LAST_NAME ELSE NULL END "LAST_NAME",
    CASE WHEN BB.FST_NAME != AA.FIRST_NAME THEN AA.FIRST_NAME ELSE NULL END "FIRST_NAME",
    FROM NAME1 BB, NAME2 AA WHERE NAME1.ID = AA.NAME2.ID AND NAME1.ID = NAME3.id)If you are inserting into NAME3, then please search on the net for "Multitable Insert ALL".
    Regards
    Aks

  • SQL Expression Field - Combine Declared Variable With Case Statement

    Hello All, I have been using Crystal & Business Objects for a few months now and have figured out quite a bit on my own. This is the first real time I have struggled with something and while I could do this as a Formula Field I would like to know how to do this as a SQL Expression. Basically I want to create a SQL Expression that uses a CASE statement but I wanted to make the code a little more efficient and employ a variable to hold a string and then use the variable in the CASE statement. The expression editor accepts the CASE statement OK but I don't know how to declare the variable. Please assist with the syntax?
    This is what I have:
    CASE
       WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Hu2019 THEN u2018Hedgeu2019
       WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Pu2019 THEN u2018PVIu2019
       ELSE u2018Noneu2019
    END
    This is what I want:
    DECLARE strVar AS VARCHAR(25)
    strVar =  u201CDatabaseu201D.u201DFieldu201D
    CASE
       WHEN strVar = u2018Hu2019 THEN u2018Hedgeu2019
       WHEN strVar = u2018Pu2019 THEN u2018PVIu2019
       ELSE u2018Noneu2019
    END

    Hi Todd,
    Please use the following for loop; your problem will be solved.
    Local StringVar str := "";
    Local NumberVar strLen := Length ({Database.Field});
    Local NumberVar i;
    For i := 1 To strLen Do
           if {Database.Field} <i> = "H" then str := "Hedge"
            else if {Database.Field} <i> = "P" then str := "PVI"
            else str := "None"; exit for
    str
    Let me know once done!
    Thank you,
    Ashok

  • Problem with Case statement

    I friends,
    I am using a case statement for a number field like this
    case when (customer_no is null or customer_no ='') then t.customer_no else gv.customer_no end as customer_no
    When i complie this i get an errror ORa-00932 inconsistent data types expected char got number....
    when i remove the case statement the query runs fine so i am sure its the case statement thats wrong here..Am i checking it the wrong way...
    Thank you in advance

    874167 wrote:
    I friends,
    I am using a case statement for a number field like this
    case when (customer_no is null or customer_no ='') then t.customer_no else gv.customer_no end as customer_no
    When i complie this i get an errror ORa-00932 inconsistent data types expected char got number....
    when i remove the case statement the query runs fine so i am sure its the case statement thats wrong here..Am i checking it the wrong way...
    Thank you in advancewith Oracle strings are enclosed in single quote marks
    so Oracle is confused & unhappy with line below
    customer_no =''
    since CUSTOMEER_NO is a NUMBER
    why do you compare number to a string?

  • Handling Exceptions with case statement - convert Exception to int value

    Hi,
    I'm developing a web app, with servlets.
    I'm catching Exceptions in my servlets, for example I would like a user to insert data into a form. If the data cannot be converted into a integer value a java.lang.NumberormatException is thrown.
    I would like to catch this and then create a message giving a more specific clue to what happened. Unfortunatly it's possible that other exceptions could be caught, so I want to be able to check which type of Exception has been caught.
    I started writing a getErrorMessage(int Code) class. The method has a case statement which just checks the code and return the appropriate message.
    This worked well for SQL exceptions as they provide a getErrorCode method. But I was wondering is there any way to convert other Exceptions such as
    java.lang.NumberormatException into an integer value?
    Cheers

    Exceptions have their types (classes) and messages (and maybe an embedded exception). That is, they have much richer internal status then an integer.
    Why should they be "converted" to integers?
    FLAME on
    Gone are the days of good old errno.
    FLAME off

  • How to use Substring function with Case statement.

    Hello Everyone,
    I have one requirement where I have to use substring function on the field for report criteria.
    E.G.
    I have Branch Name Field where I have all branch names information, Now some of the branch names are too big with some extension after the name .
    now i want to substing it but the character length varies for each branch.
    so is there any way where we can use case statement where we can define that if branch name character are exceeding some value then substing it with this length.

    Try something like this:
    CASE WHEN LENGTH(tablename.Branch_Name) > n THEN SUBSTRING(...) ELSE tablename.Branch_Name END
    where n is the number of characters you want to start the break.

  • Issue with case statement

    100*ifnull(x,1)/case when ifnull(yagox,1)=0 then 1 else yagox end)
    based on above condition my result should be like below
    99.8
    101.1
    99.4
    97.7
    Current displaying result like below
    99.8
    1,22,345,000
    99.4
    97.7
    2,34,567,400
    i need to display those two values also in %
    it may be happen denominater(yagox value is 1)
    could please give the proper case statement for resolving the issue
    betham
    Edited by: 961992 on Oct 22, 2012 10:15 PM

    Dear betham,
    welcome to the forum, could you please share the table structure and some sample data and also what your select statement is. This will help people come up with solution faster and also it would avoid going in loops.

  • CLOB with case statement not working getting error

    Can anyone help on this
    I write this sql
    select Case when to_clob(PROPERTY) = 'is_intradesk=Y' then 'Internal' end
    from JPM_CP;
    Where PROPERTY column is clob column and its giving the error "ORA-00932: inconsistent datatypes: expected - got CLOB"
    Is it not possible to use clob columns with case or decode !

    Its working but it does not fulfill my purpose
    In you answer it is looking for position right! means, does the column contain the value('Intradesk=Y' ) or not. means
    I am looking for exact match with CLOB column values, that is Clob column(PROPERTY) contains the exact value that value which I am comparing with i.e 'Intradesk=Y'
    I need this
    select * from table where clob_column = 'value' (exact).
    Edited by: sajalkdas on Feb 4, 2011 3:28 PM

Maybe you are looking for

  • Video format?

    I want to include some video in my iphone app, which will be embedded into the .ipa file. What is the best format of video to use, and should it be embedded in Flash or external? Regards Simon

  • Create cursor using dynamic query

    Hi, I declare a query: l_query VARCHAR2(32000):= 'select distinct '||:P_ITEM||' from OCM_CUSTOMER'; How can i assign this query to cursor? I tried this, but failed. Declare l_query VARCHAR2(32000):= 'select distinct '||:P_ITEM||' from OCM_CUSTOMER';

  • BI JDBC Connection fails to connect to SQL Server 2000

    Hello SDNs, I have configured my JDBC connector to connect to MS SQL Server 2000(Third party in my case) using the document How to Configure UD connect on the J2EE server for JDBC Access to External Drivers. I have given the following properties for

  • Problem extracting data from R/3 to BW using infopackage?

    Hi all, I am trying to extract data from R/3 to BI7.0 through infopackage and its giving below error. Request still running Diagnosis No errors found. The current process has probably not finished yet. System Response The ALE inbox of BI is identical

  • IWeb Can soundfiles be played by another player than Quicktime?

    iWeb Can soundfiles be played by another player than Quicktime? Some Windows users are not allowed to install Quicktime for Windows (e.i. a workcomputer with limitations) and they cannot play the soundexamples on my webpage! Is it possible to change