Nested IF Statement in WHERE clause...

Here is a really abridged sample of my package. I need to ensure that if a salesrep has a status of 'I' (for "inactive") that the next salesrep with a status of 'A' (for "active") will be selected in its place.
Should I include a nested loop within the WHERE clause? Any tips on how I should go about it? I'm a newbie...thanks for the help..
SELECT rsa.name rep_name
,rsa.attribute7 rep_phone
,rsa.arrtibute8 rep_ext
FROM ra_salesreps_all rsa
WHERE rsa.status(+) = 'A'

I'm assuming that this is part of your procedure within a package.....
You must be writing a CURSOR here....
Cursors are memory locations that can store retrieved rows and then process them one by one.
create or replace procedure my_proc
(<example_var> IN|OUT TYPE)
IS
cursor my_cursor IS
select <the fields I want>
from <sales type table>
where <my value> = 'A';
BEGIN
<how to process the cursor>
You can write the cursor process 2 ways:
1) FOR x in <name_of_cursor> LOOP
(This does whatever to the data for every record already selected by the cursor)
2) OPEN....FETCH....CLOSE
This is only scratching the surface of cursors...you need to read about these for what you are doing.
Question though...is this something you need to run for a SQL process in Oracle Applications??....if so you don't need to write a package/ procedure. You can write a cursor and load it as type SQL*PLUS, and it will run for you.
null

Similar Messages

  • Case statement in where clause ??

    Hello gurus,
    Can we use case statements in where clause ?? Any example will be great!
    And also i would like to know, besides CASE and DECODE statements, Is there any way we can use IF ELSE statements in SELECT clause or in WHERE clause ?
    Thank you!!

    Hi,
    user642297 wrote:
    Hoek,
    Thanks for the reply
    Whatever you return from 'then' should match your criteria.I didnt get this part...can you elaborate this part ?? Thank you!!Remember what a CASE expression does: it returns a single value in one of the SQL data types (or NULL).
    You're probably familiar with conditions such as
    WHERE   col = 1Inthe example above, col could be replaced by any kind of expression: a function call, and operation (such as "d * 24") or a CASE expression, which is exactly what Hoek posted:
    where  case
             when col = 6 then 1
             when col = 9 then 1
           end = 1;I think what Hoek meant about mnatching was this: since the CASE expression is being compared to a NUMBER, then every THEN clause (as well as the ELSE, if there is one) should return the same data type. You can't have one THEN clause return a NUMBER, and another one in the same CASE expression return a DATE, like this:
    where  case
             when col = 6 then 1
             when col = 9 then SYSDATE     -- WRONG! Raises ORA-00932: inconsistent datatypes
           end = 1; 
    By the way, it's rare when a CASE expression really helps in a WHERE clause. CASE is great for doing conitional stuff in places where you otherwise can't (in the ORDER BY clause, for example), but the WHERE clause was designed for conditions.
    Hoek was just trying to give a simple example. If you really wanted those results, it would be simpler to say:
    where  col = 6
    or     col = 9and simpler still to say
    where  col  IN (6, 9)

  • Case statement within where clause

    How can i write a case statement within Where clause of SQL statement.
    Ex:
    If sysdate is less than Dec 31 of 2009 then run the query for 2009 else run the query for 2010.
    belwo query is not working. Please let me know how can i write a case statement within where clause.
    Select * from table
    where
    Case
    when to_char(sysdate,'yyyymmdd')<=20091231 then tax_year=2009
    else tax_year=2010
    End

    Hi,
    You can get the results you want like this:
    Select  *
    from      table
    where   tax_year = Case
                      when  to_char(sysdate,'yyyymmdd') <= 20091231
                      then  2009
                      else  2010
                 End
    ;A CASE expression returns a single value in one of the SQL data types, such as a NUMBER, VARCHAR2 or DATE. There is no boolean type in SQL.

  • Delete statement with where clause

    Please tell me delete statement for deleting database records from a table with a where clause comprising on composit primary key.
    Eg:-
    How to delete from employee where a=1, b=1, c=1. Employee also have other columns like name,address etc.
    Kindly reply?

    857452 wrote:
    kindly give me example.There are examples in the manual.

  • How to use a case statement in where clause

    Hi All,
    I have a requirement which is to bring all the claims that are created in the last month.So, i wrote a query something like this
    select * from claims
    where
    (Month(ClaimOpenDate) = Month(Getdate())-1 and year(claimopendate) = year(getDate()))
    which would give me any new claims created in last month of current year, but this condition fails if we are in the first month of a new year( lets say if we are in 2016 jan then month(getdate())-1 would be 0 and year(getdate()) would be 2016 so we dont
    find any records where year is 2016 and month is 0 for claimopen).
    So, i would like to use a case statament or something which can help me get around this one.
    Can someone please help me with any suggestions?
    Thanks

    Hi Jason,
    Thanks a lot for your help. This is what exactly i am looking for but i just gave a sample query above below is my original query 
    select
    row_number() over (order by [ClaimNumber]) as DataElementName
    ,c.PolicyNumber as PolicyNum
    , c.FirstName as CustNameF
    ,c.LastName as CustNameL
    ,c.PolicyForm as PolType
    ,'Homesite' as Company
    ,[ClaimNumber] as ClaimNum
    ,E.office as Ofc
    ,e.Supervisior_FullName as Team
    , RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
    , case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
    ,e.AdjusterID as RepC -- not sure
    ,CONVERT ( varchar,c.LossDate ,101) as DOL
    ,convert (varchar,c.ClaimOpenDate,101) as DOR
    ,rtrim(c.Loss_State) as LossSt
    ,c.Loss_ZipCode as LossZIP
    ,c.Loss_City as LossCity
    ,c.LossType as FOL
    ,'' as PR
    ,'' as PRNum
    ,1 as FeaNum
    ,'HO' as FeaType
    ,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
    ,'' as FeaOpen
    ,'' as FeaClosed
    ,s.PaymentIndemnityAmount as PaidAmt
    ,s.ReserveIndemnityAmount as Reserve
    ,'' as Sub
    ,'' as Sal
    ,'' as FeatOwnOfc
    ,e.Supervisior_FullName as FeatOwnTeam
    ,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
    ,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
    ,e.AdjusterID as FeatOwnRepCode
    ,NULL AS Description --not sure
    from [Stg].[HS_DW_RV_Claims] c
    inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
    inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
    left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
    where c.LoadSource = 'CMS'
    and
    (s.PaymentIndemnityAmount <>0 or s.PaymentExpenseAmount <>0)
    and
    ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
    UNION ALL
    select
    row_number() over (order by [ClaimNumber]) as DataElementName
    ,c.PolicyNumber as PolicyNum
    , c.FirstName as CustNameF
    ,c.LastName as CustNameL
    ,c.PolicyForm as PolType
    ,'Homesite' as Company
    ,[ClaimNumber] as ClaimNum
    ,E.office as Ofc
    ,e.Supervisior_FullName as Team
    , RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
    , case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
    ,e.AdjusterID as RepC -- not sure
    ,CONVERT ( varchar,c.LossDate ,101) as DOL
    ,convert (varchar,c.ClaimOpenDate,101) as DOR
    ,rtrim(c.Loss_State) as LossSt
    ,c.Loss_ZipCode as LossZIP
    ,c.Loss_City as LossCity
    ,c.LossType as FOL
    ,'' as PR
    ,'' as PRNum
    ,1 as FeaNum
    ,'HO' as FeaType
    ,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
    ,'' as FeaOpen
    ,'' as FeaClosed
    ,s.PaymentIndemnityAmount as PaidAmt
    ,s.ReserveIndemnityAmount as Reserve
    ,'' as Sub
    ,'' as Sal
    ,'' as FeatOwnOfc
    ,e.Supervisior_FullName as FeatOwnTeam
    ,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
    ,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
    ,e.AdjusterID as FeatOwnRepCode
    ,DESCRIPTION --not sure
    from Stg.IG_Document D
    inner join [Stg].[HS_DW_RV_Claims] c on D.PARENTREF = C.ClaimNumber
    inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
    inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
    left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
    where c.LoadSource = 'CMS'
    and
    DESCRIPTION like '%Denial Letter%'
    and
    ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
    So if i use your logic in the end for both the where clauses its been more than 10 minutes and the query is still running however if i use my old method it doesnt even take a second. Looks like its affecting the execution plan. Any suggestions to get around
    this one please?
    Thanks

  • Case statement with where clause.

    I appreciate that there are much simpler ways to run this query but I wondered if anyone else had come across the following -
    select distinct
    product_table.a,
    product_table.b,
    product_table.c,
    CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'     
    WHEN product_table.b = 'B' THEN 'BBB'
    WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
    WHEN product_table.b IN ('D','DD') THEN 'DDD'
    WHEN product_table.b LIKE 'E%' THEN 'EEE'
    WHEN product_table.b LIKE 'F%' THEN 'FFF'
    WHEN product_table.b LIKE 'G%' THEN 'GGG'
    ELSE 'UNKNOWN' END
    from product_table                    
    where
    ( CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'     
    WHEN product_table.b = 'B' THEN 'BBB'
    WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
    WHEN product_table.b IN ('D','DD') THEN 'DDD'
    WHEN product_table.b LIKE 'E%' THEN 'EEE'
    WHEN product_table.b LIKE 'F%' THEN 'FFF'
    WHEN product_table.b LIKE 'G%' THEN 'GGG'
    ELSE 'UNKNOWN' END) = 'FFF'
    when this query runs its as if the where clause = 'FFF' does not exist and all rows are returned.
    Thanks, Sarah.

    Technical questions should be addressed to one of the technical forums. You'll probably find that the folks in the PL/SQL forum (Products | Database | PL/SQL) have some thoughts.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • If Statement in Where Clause

    Hi,
    Can anybody direct me to the easiest way to do this in sql?
    select
    from table
    where
    if :condition = 1 then fieldA = 'Yes'
    else if :condition = 2 the fieldB = 'Yes';
    I tried to use the CASE statement, but I don't think I have the syntax correct. Is there another way?
    Thanks in advance

    If I am correct and as Todd replied, you can write
    select
    from table
    where ((:condition = 1 and fieldA = 'Yes') or
           (:condition = 2 and fieldB = 'Yes') or
           (:condition = 3 and fieldC = 'Yes')
    and any other condtionsAravind

  • Using Case Statement in Where Clause

    Hello All,
    I wish to conditionally use different columns for retrieving unique row. This will be dependent upon a parameter passed to the Function/Procedure.
    The SQL framed looks as below:
    +select *+
    from Test_Table
    where column_1 = <some_value>
    and case when p_call_location = 'A' then column_2 like '%ABC%'
    when p_call_location = 'B' then column_2 Not Like '%ABC%'
    when p_call_location = 'C' then column_3 like '%EFG%'
    when p_call_location = 'D' then column_3 like '%IJKL%'
    END;
    However, I am not sure if this works, as I am getting a Missing Right Paranthesis error. Major hinderance is the depedency on multiple columns, which would need to be referred for particular scenario.
    Can somebody please help me with an example or a skeleton of how a query should be formed?
    Appreciate an early reply!!!

    HI,
    i think this may solve your issue...get back to me if u have any qry's on this.
    CREATE TABLE Test_Table
    (p_call_location VARCHAR2(10),
    COLUMN_1 VARCHAR2(20),
    COLUMN_2 VARCHAR2(20),
    COLUMN_3 VARCHAR2(20))
    INSERT INTO Test_Table VALUES('A','COMNVAL','ABC_PER','XXXX');
    INSERT INTO Test_Table VALUES('A','COMNVAL','PER','XXXX');
    INSERT INTO Test_Table VALUES('B','COMNVAL','ABC_PER','XXXX');
    INSERT INTO Test_Table VALUES('B','COMNVAL','PER','XXXX');
    INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','EFG_XXXX');
    INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','XXXX');
    INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','EFG_XXXX_IJKL');
    INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','GGG_XXXX');
    SELECT * FROM Test_Table WHERE ROWID IN (
    select case when p_call_location = 'A' AND column_2 like '%ABC%' THEN ROWID
    when p_call_location = 'B' AND column_2 Not Like '%ABC%' THEN ROWID
    when p_call_location = 'C' AND column_3 like '%EFG%' THEN ROWID
    when p_call_location = 'D' AND column_3 like '%IJKL%' THEN ROWID
    END AS KK
    from Test_Table
    where column_1 = 'COMNVAL');
    even u can use the below qry also
    select *
    from test_table
    where column_1 = 'COMNVAL'
    and (case when p_call_location = 'A' and column_2 like '%ABC%' then 'VALID'
    when p_call_location = 'B' and column_2 Not Like '%ABC%' then 'VALID'
    when p_call_location = 'C' and column_3 like '%EFG%' then 'VALID'
    when p_call_location = 'D' and column_3 like '%IJKL%' then 'VALID'
    else 'INVALID'
    END) = 'VALID';
    thanks
    prasuna.
    Edited by: user13820845 on Feb 21, 2011 10:25 PM

  • Insert Statement with Where Clause

    I m using this but giving error "Encounter the Symbol "Where" when expecting one of the following.
    Code is :-
    insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
    values (:sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3)
    where :sizecost.cost_no := :costmain.cost_no;

    Something like this ?
    insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
    select :sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3
    from dual
    where :sizecost.cost_no := :costmain.cost_no;Nicolas.
    : all these are items on form Ok, why not try to use the Form Forum ?
    Message was edited by:
    N. Gasparotto

  • CFC Best Practise : Using cfif statements in Where Clause

    Hi there
    Wondering if anyone can advise on the best route to take for handlings cfcs...
    I have a function set up as so
    <!--- GRAB SONG INFORMATION --->
        <cffunction name="getSong" access="remote" output="false" returntype="query" hint="return song information, filtered by user id">
        <!---Optional Artist Name Argument--->
        <cfargument name="nameArt" type="string" required="false" hint="artist we want to grab song for">       
        <!---Filter by user ID--->
        <cfargument name="idUsr" type="any" required="false" hint="if provided, filter by user id">
        <!---Optional Filter by user name--->
        <cfargument name="nameUsr" required="false" type="string" hint="if supplied, filter by user name">
         <!---Optional song id argument--->
        <cfargument name="idSng" required="false" type="numeric" hint="if supplied, grab information for song with this id">
        <!--- grab song from database --->
         <cfquery name="song" datasource="#APPLICATION.mx#">
             // SELECT WHICHEVER FIELDS NECESARRY
             SELECT.....
             <!---If user id is supplied--->
             <cfif isDefined('ARGUMENTS.idUsr')>
            <!---Filter results by user id--->
             WHERE s.userId = <cfqueryparam value = '#ARGUMENTS.IdUsr#' cfsqltype='CF_SQL_INTEGER'>
             </cfif>
             <!---If user name is supplied--->
              <cfif isDefined('ARGUMENTS.nameUsr')>
            <!---Filter results by user id--->
             WHERE s.userId =     (SELECT iUserID
                                FROM users
                                WHERE name = <cfqueryparam value = '#ARGUMENTS.nameUsr#' cfsqltype='CF_SQL_VARCHAR' maxLength="12">)
             </cfif>
            <cfif isDefined('ARGUMENTS.idSng')>
             WHERE s.iSongID = <cfqueryparam value = '#ARGUMENTS.idSng#' cfsqltype='CF_SQL_INTEGER'>
             </cfif>
             ORDER BY s.iSongID DESC
        </cfquery>
        <!---Return query output--->
            <cfreturn song>
        </cffunction>
    Now im wondering, is it best to have multiple cfifs in the same function, filtering data dependant on what arguments are supplied, or is it best to seperate the function into seperate functions with different filters, without the cfifs?
    Many thanks

    Also keep in mind that some of your logic can be done on the database side instead of the CF side:
    SELECT myFieldA, myFieldB
    FROM myTable
    WHERE myFieldA = CASE WHEN isNULL(@MyDBVar,'') = '' THEN myFieldA ELSE @MyDBVar END
    Will filter your results matching the field myFieldA against the value of the variable @MyDBVar (if it is passed in).  You can also use conditional logic to make larger changes to your database query depending on the DB you are using.

  • Case Statement in a Where clause help

    Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Hello,
    I have an APEX application that I need to build a SQL statement for a LOV (List of Values). I have a hidden filed that contains the customer type which can be an 'R' or 'B'. The query needs to be able to display two different result sets based on the customer type of 'R' or 'B'.
    If the customer type is 'R' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5)
    ORDER BY drg_min_milesIf the customer type is 'B' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5,10,15,20)
    ORDER BY drg_min_milesCan someone help me with what I think needs to be a case statement?
    Thanks,
    Joe

    Hi,
    You can try CASE statement with WHERE clause
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE (CASE param_cust_type
    WHEN(param_cust_type='R') THEN (drg_min_miles IN (0, 5)
    WHEN (param_cust_type='B') THEN (drg_min_miles IN (0,5,10,15,20)
    END;
    Please try and let me know if anything wrong.
    Anyone from the forum comment my code if there is any wrong.
    Thanks!
    Naresh

  • Nested SQL statements for complex, detailed queries.

    Is it  possible to write nested SQL statements for complex, detailed queries. A nested query
    has a WHERE clause that includes a SELECT statement ? Is it true or false ?

    Hi wahid,
    Here are pretty good examples: 
    http://www.databasejournal.com/features/mssql/article.php/3464481/Using-a-Subquery-in-a-T-SQL-Statement.htm
    http://technet.microsoft.com/en-us/library/aa213252(v=sql.80).aspx
    Regards Harsh

  • Problem with DECODE block in WHERE clause

    Hi,
    I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
    SELECT 'hello' FROM DUAL
    WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    I think some problem is there in my WHERE clause.
    But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
    SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    FROM DUAL;
    Please help me to get out of this problem. Thank you so much in advance.
    Thanks,
    Ramji.

    The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
    'sample1', 'sample2', 'sample3' is a single string. Consider it x.
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
    is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
    or
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
    For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
    also does'nt work.
    Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'.

  • Function is called in Where clause

    I am analyzing the script and found one function is called within the SQL statement in where clause. I like to know is there any alternate way to improve the performance.
    If I move the function call prior to this select statement and update the result of function value in new column in existing table/ are in new tmp table. Will there be performance improvement
    Or any other better way... Plz suggest me.
    - Mahesh

    You should include the query code as well as the execution plan.
    I figure out you mean your arguments in the where clause are evaluating a function and this prevents the index from being used, provoking a reduced query performance. If this is the case, then you should consider using function based indexes instead.
    ~ Madrid
    http://hrivera99.blogspot.com/

  • Merge with where clause after matched and unmatched

    Hai,
    Can anybody give me one example of merge statement with
    where clause after matched condition and after the unmatched condition.
    MERGE INTO V1 VV1
    USING (SELECT     A.CNO XXCNO, A.SUNITS XXSU, A.DDATE XXDD, XX.SUM_UNITS SUMMED
    FROM V1 A,
    (SELECT                
    SUM(SUNITS) SUM_UNITS FROM V1 B                                   
    GROUP BY CNO) c
    WHERE
    A.DDATE=0 AND A.SUNITS <>0 AND
    A.ROWID=(SELECT MAX(ROWID) FROM V1 )) XX
    ON (1=1)
    WHEN MATCHED THEN UPDATE SET
    VV1.SUNITS=XX.SUMMED
    WHERE XX.XXDD=0
    WHEN NOT MATCHED THEN INSERT
    (VV1.CNO, VV1.SUNITS, VV1.SUNITS)
    VALUES (XX.XXCNO, XX.XXSU, XX.XXDD)
    WHERE XX.XXDD<>0
    i am getting the error
    WHERE XX.XXDD=0
    ERROR at line 13:
    ORA-00905: missing keyword
    Thanks,
    Pal

    One of the example is there:
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_9016.htm#sthref7014
    What Oracle version do you use ?
    Besides the condition (1=1) is non-deterministic,
    I would expect there an exception like "unable to get a stable set of rows".
    Rgds.

Maybe you are looking for