Can we use where clause in Update on Merge statement?

Hi All,
I tried to execute the following Merge Query:
When this query is executed without ‘Where clause’ in Update statement its working fine. When executed with ‘Where clause’ it throwing the following error:
ORA-00905: missing keyword.
Following is the sample query which I tried to execute:
MERGE INTO TABLE_NAME
USING (SELECT COLUMN FORM TABLES)
ON (CONDITION)
WHEN MATCHED THEN
UPDATE SET
     COLUMN UPATES
WHERE CONDITION -- Can we use where clause here?
WHEN NOT MATCHED THEN
INSERT
INSERT VALUES;
Can some one help on this?
Thanks in advance.
Darius

Yes:
SQL> drop table emp1;
Table dropped.
SQL> create table emp1 as select * from emp where deptno = 30;
Table created.
SQL> update emp1 set sal = sal*2;
6 rows updated.
SQL> commit;
Commit complete.
SQL> select ename,sal from emp1;
ENAME             SAL
ALLEN            3200
WARD             2500
MARTIN           2500
BLAKE            5700
TURNER           3000
JAMES            1900
6 rows selected.
SQL> MERGE INTO emp1
  2  USING(select * from emp) emp
  3  ON (emp1.empno = emp.empno)
  4  WHEN MATCHED THEN
  5  UPDATE SET sal = emp.sal WHERE ename = 'TURNER'
  6  WHEN NOT MATCHED THEN
  7  INSERT(ename,sal) VALUES(emp.ename,emp.sal);
9 rows merged.
SQL> select ename,sal from emp1;
ENAME             SAL
ALLEN            3200
WARD             2500
MARTIN           2500
BLAKE            5700
TURNER 1500
JAMES            1900
SMITH             800
JONES            2975
CLARK            2450
SCOTT            3000
KING             5000
ENAME             SAL
ADAMS            1100
FORD             3000
MILLER           1300
14 rows selected.
SQL> SY.

Similar Messages

  • Can we use where clause in for-each: tag_name ?- urgent

    Hi All,
    I am using templated builder 5.5
    1)2 G_LINE Repeating Groups will exist for every Invoice Line. Each will have an INVOICE_LINE_TYPE element, set as either ‘Line’ or ‘Tax’. Both of the G_LINE groups will be used to create the Invoice Lines output for a consolidated invoice.
    2)<?for-each:G_LINES WHERE ORDER_LINE_TYPE = ‘LINE’?>
    Data to be displayed...
    <?end FOR-EACH?>
    Repeating group to display all of the invoice lines associated with a particular consolidated invoice.
    The XML Element to base repeating group on is G_LINES
    Is it possible to use the above tags, if yes how an d if no, will this be suppoerted in 5.6.1 version?
    Thanks in advance

    Hi
    You'll have to add the code but you can use XPATH to limit the data to the LINE data:
    <?for-each:G_LINES[ORDER_LINE_TYPE = ‘LINE’]?>
    this limits the rows to just those that satisfy the condition.
    If you want to show the LINE and TAX data you would be better to loop over the G_LINES and then use an 'if' statement across the group. So you would have a two row table to hold the LINE and TAX data and then use a if@row statement to filter on LINE and TAX data.
    Regards, Tim

  • Can I use a select and update statement in a single jsp file?

    I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
    note: I used a seperate table in BUY and SELL transaction
    After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
    select * from test, test1;
    update test
    set total_shares=total_shares-Stotal;
    where stock_code=Scode AND name_broker=Sbroker;
    Can i have both of these statements in the same jsp file in oder to update the buy table?
    Or can anyone suggest how can process that update?THANKS!
    --------------------

    Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?

  • How to use WHERE Clause in BPEL

    Hi ,
    i am trying to use where clause in DB adapter but its not working.
    my query is "select empname from employee where empid = &a"
    can any body tell me what is the reason its npt working?
    and how can i retrive data form DB?

    Hi,
    You are thinking perfectly fine. The solution what I suggested was
    select ename from emp where empno=?
    And the solution provided by you was
    SELECT first_name, last_name FROM per_all_people_f WHERE person_id = #p_person_id
    There is no problem with the above mentioned select statements.
    I just want to say that if you see closely, internal logic changes #parameter name to ?. So both the logics are right.
    Cheers,
    Abhi...

  • Performance hit using "where" clause in the query

    Hi All,
    I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
    1. SELECT * FROM Employee
    2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
    There is no difference in Query Execution Time for both queries.
    Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
    Rows returned are more in first case as compared to second case.(ratio - 1:4)
    Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
    Does anybody know the reason of unexpected time difference for the business logic in the second case?

    Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
    Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
    First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
    Second, you may need your DBA to enable autotracing, if it's not already:
    http://asktom.oracle.com/~tkyte/article1/autotrace.html
    http://www.samoratech.com/tips/swenableautotrace.htm
    Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
    For example:
    SQL> set autotrace on
    SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
      COUNT(*)
            11
    Execution Plan
    Plan hash value: 2983758974
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            |     1 |     4 |     1   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE   |            |     1 |     4 |            |          |
    |*  2 |   INDEX RANGE SCAN| TICKET_N10 |    12 |    48 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
    Statistics
              0  recursive calls
              0  db block gets
              1  consistent gets
              0  physical reads
              0  redo size
            515  bytes sent via SQL*Net to client
            469  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
    the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
    If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
    since sql*plus is not a JDBC thing...
    Oh, and sql*plus can also give you easier access to timing information, with "set timing on".

  • How to Get the required List Item values by using Where Clause

    I have two tables named "TAX_RULES","BILL"
    1. " Tax_Rules" (Sub_Head_Code,Tax_ID,Tax_Percentage)
    { While "Sub_Head_Code" field is unique,
    Tax_ID describes that there are two kinds of Tax_IDs based on Tax_percentage which is 6% for some Sub_Head_Codes and 3.5% for the remainng Sub_Head_Codes. I have given Tax_ID 1 for 6% and Tax_ID 2 for Sub_Head_codes having 3.5%. }
    2. "BILL" (Bill_ID,Sub_Head_Code,Tax_ID,Bill_Amount)
    {While "Bill_ID" describes unique Bill Identification Number,
    Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table}
    I have design form for both tables.
    In BILL form i am trying to get values of Tax_ID from Tax_Rules table at run-time by using WHEN-NEW-FORM-INSTANCE.
    For this whenever i select a Sub_Head_Code in Bill Form, all the Tax_IDs that i have recorded against each Sub_Head_Code which is either 1 or 2 against 6% and 3.5% respectively.
    But I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code ahould come in the LIST ITEM.
    I have used WHERE clause but that is useless.
    Following is the Code that i have applied in the WHE-NEW-ITEM-INSTANCE Trigger at FORM LEVEL
    <CODE>
    DECLARE
         rg_n1 VARCHAR2(40) :='TAX_ID';
         rg_idn1 RecordGroup;
         gc_idn1 GroupColumn;
         errcode NUMBER;
    BEGIN
         CLEAR_LIST('BILL.TAX_ID');
         rg_idn1 := Find_Group(rg_n1);
    IF      Id_Null(rg_idn1) then
              rg_idn1 := Create_Group(rg_n1);
         gc_idn1 := Add_Group_Column(rg_idn1,'EXPLAIN',CHAR_COLUMN,60);     
              gc_idn1 := Add_Group_Column(rg_idn1,'TAX_ID',CHAR_COLUMN,3);
         END IF;
         errcode := Populate_Group_With_Query(rg_idn1,'select TAX_ID,TAX_ID from TAX_RULES');
         POPULATE_LIST('BILL.TAX_ID',RG_IDn1);
    END;
    </CODE>

    In the Tax Rules table, you state:
    "Sub_Head_Code" field is unique
    In the Bill table, you state:
    Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table
    If the Sub_Head_Code is unique, then it's acting as a primary key, so Sub_Head_Code and Tax_ID in the Bill table are not behaving like a composite foreign key. The Sub_Head_Code is a foreign key, and the Tax_ID is irrelevant as far as keys are concerned.
    It is not clear what it is you want to do.
    If you want to display the Tax_IDs from the Bill table when you select a Sub_Head_Code from the Tax_Rules table, then change your query to:
    select TAX_ID, TAX_ID from BILL where Sub_Head_Code = :Tax_Rules.Sub_Head_Code
    If you want to display the Tax_IDs from the Tax_Rules table when you select a Sub_Head_Code from the Bill table, then change your query to:
    select TAX_ID, TAX_ID from TAX_RULES where Sub_Head_Code = :Bill.Sub_Head_Code
    If this is not what you want, then clarify what it is you want to do. Don't say:
    "I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code"
    because it is not clear what tables you are referring to.

  • My friend gave me ipod touch with all his accounts, i created new accounts but when i went on the appstore and tried to update apps installed by him,i was asked his account's password! i dont know his password.how can i use my account to update apps?

    my friend gave me ipod touch with all his accounts, i created new accounts but when i went on the appstore and tried to update apps installed by him,i was asked his account's password! i dont know his password.how can i use my account to update apps?

    You can't.  Apps and really all content purchased/downloaded through one Apple ID is forever tied to that Apple ID.  In the case of Apps they will always request that Apple ID to update as they are licensed to that Apple ID.
    In reality, the Apps were licensed to that Apple ID by the developer.  And cannot simply be given away to you for you to use.
    He should have wiped the iPod clean so you could set it up for your use without any of his accounts or purchased content as you are not really licensed to any of those Apps.
    Your friend should have followed this support document before giving the iPod to you:
    What to do before selling or giving away your iPhone, iPad, or iPod touch - Apple Support

  • Can I use cellular data for updating ios 7.0.2 to 7.0.4 in iPhone 5

    Can I use cellular data for updating ios 7.0.2 to 7.0.4 in iPhone 5.  I just want to know coz i only have 3G cellular data ....

    No.

  • Query using where clause

    I am not able to run a SQL query using where clause.
    the query is as follows:
    I extract the text input by the user in a text field say 'a' and
    store it in string 'y'.
    String y= a.getText();
    //running the query
    Select A from B where B.x=y;
    how do we run a where clause when y is a string variable instead of value?

    Use the following :
    String y = a.getText();
    String query ="select A.CODE from Port A where A.NAME=" + "'" + y + "'" ;
    ResultSet rs= stmt.executeQuery(query);

  • Can i use my emac to update my ipad system?

    can i use my emac to update my ipad system software?

    If you mean iMac yes you can use it to update your iPad but it appears your iPad has  already been  updated.

  • I can't use Lr5.6 after update Lr5.5 to Lr5.6

    i can't use Lr5.6 after update Lr5.5 to Lr5.6 and Now it ask me serial number or 30day
    Please help me Thank u so much

    If you are running the LR 5 from Creative Cloud Photography Program, then try the procedure outlined, here:
    https://helpx.adobe.com/lightroom/kb/unable-launch-lightroom-55.html
    If you are running LR5 as a standalone serial-number-licensed version, then enter your serial number, again.

  • When updating my apps it stoped half way through and won't start so now I can not use the app recently updated it to ios7

    and won't start so now I can not use the app recently updated it to ios7 I have tried turn the device on and off still hasn't work and I would like to actually use my apps and I can not download new apps

    If the apps are waiting:
    Fix iOS Apps Stuck on “Waiting…” During Download & Install
    Otherwise:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Download the apps to your computer and sysnc
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             

  • HT201068 Can I use this to have someone in another state do my QuickBooks input?

    Can I use this to have someone in another state do my QuickBooks input?

    Hi examinernews,
    After reading your post it seems you would like the ability to allow a remote user to control your Mac. That can be done by using Screen Sharing, a feature of your Mac. I have linked to an article which explains how to use it:
    OS X Mavericks: Share your screen
    You can let others view your computer screen on their own Mac. While your screen is being shared, the user of the other Mac sees what’s on your screen and can open, move, and close files and windows, open apps, and even restart your Mac.
    Open Sharing preferences if it isn’t already open (choose Apple menu > System Preferences, then click Sharing).
    Select the Screen Sharing checkbox.If Remote Management is selected, you must deselect it before you can select Screen Sharing.
    To specify who can share your screen, select one of the following:            
    Option
    Description
    All users:
    Anyone with a user account on your Mac can share your screen.
    Only these users:
    Screen sharing is restricted to specific users.
    If you selected “Only these users,” click Add (+) at the bottom of the Users list, then do one of the following:
    Select a user from Users & Groups, which includes all the users of your Mac.
    Select a user from Network Users or Network Groups, which includes everyone on your network.
    To let others share your screen without having a user account on your Mac, click Computer Settings, then select one or both of the following:
    Option
    Description
    Anyone may request permission to control screen:
    When other computer users begin screen sharing your Mac, they can ask for permission instead of entering a user name and password.
    VNC viewers may control screen with password:
    Other users can share your screen using a VNC viewer app—on iPad or a Windows PC, for example—by entering the password you specify here.
    If this computer’s screen is shared only by other OS X users, turn off these options and add accounts for the other users.
    Thank you for contributing to Apple Support Communities.
    Take care,
    Bobby_D

  • Can we use both INSERT and UPDATE at the same time in JDBC Receiver

    Hi All,
    I would like to know is it possible to use both INSERT and UPDATE at the same time in one interface because I have a requirement in which I have to perform both the task.
    user send the file which contains both new and old record and I need to save those in MS SQL database.
    If the record exist then use UPDATE otherwise use INSERT.
    I looked on sdn but didn't find any blog which perform both the things at the same time.
    Interface Requirement
    FILE -
    > PI -
    > JDBC(INSERT & UPDATE)
    I am thinking to use JDBC Lookup but not sure if it good to use for bulk record.
    Can somebody please suggest me something or send me the link of any blog or anything to solve this problem.
    Thanks,

    Hi ,
              If I have understood properly the scenario properly,you are not performing insert and update together. As you posted
    "If the record exist then use UPDATE otherwise use INSERT."
    Thus you are performing either an insert or an update which depends on outcome of a search if the records already exist in database or not. Obviously to search the tables you need " select * from ...  where ...." query. If your query returns some results you proceed with update since this means there are some old records already in database. If your query returns no rows  you proceed with "insert into tablename....." since there are no old records present in database.
      Now perhaps the best method to do the searching, taking a decision to insert or update, and finally insert or update operation is to be done by a stored procedure in MS SQL database.  A stored procedure is a subroutine available to applications accessing a relational database system. Here the application is PI server.   If you need further help on how to write and call stored procedure in MS SQL you can look into these links
    http://www.daniweb.com/web-development/databases/ms-sql/threads/146829
    http://www.sqlteam.com/article/stored-procedures-parameters-inserts-and-updates
    [ This part you can ignore, Since its not sure that you will face this situation
        Still you might face some problems while your scenario runs. Lets consider this scenario, after the stored procedure searches the database it found no rows. Thus you proceed with an insert operation. If your database table is being accessed by multiple applications (or users) other than yours then it is very well possible that after the search operation completed with a null result, an insert/update operation has been performed by some other application with the same primary key. Now when you are trying to insert another row with same primary key you get an error message like "duplicate entry not possible for same primary key value". Thus you need to be careful in this respect. MS SQL has a feature called "exclusive locks ". Look into these links for more details on the subject
    http://msdn.microsoft.com/en-us/library/aa213039(v=sql.80).aspx
    http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm
    http://www.faqs.org/docs/ppbook/r27479.htm
    http://msdn.microsoft.com/en-US/library/ms187373.aspx
    http://msdn.microsoft.com/en-US/library/ms173763.aspx
    http://msdn.microsoft.com/en-us/library/e7z8d5hf(v=vs.80).aspx
    http://mssqlserver.wordpress.com/2006/11/08/locks-in-sql/
    http://www.mollerus.net/tom/blog/2008/03/using_mssqls_nolock_for_faster_queries.html
        There must be other methods to avoid this problem. But the point is you need to be sure that all access to database for insert/update operations are isolated.
    regards
    Anupam

  • How to use "where" clause in modify statement

    Hi
    can any1 telll me is it possible to use a where clause in a modify statemetn. I want to use modify statemetn  to insert a new recoed in a database table.
    Regards
    Sabahuddin Ahmed

    MODIFY itab - itab_lines
    Syntax :
    ... itab FROM wa TRANSPORTING comp1 comp2 ... WHERE log_exp.
    With these additions the MODIFY statement assigns the content of the comp1 comp2 ... components of the wa work area specified after TRANSPORTING to all lines in the itab table that meet the logical condition log_exp. The wa work area must be compatible with the line type of the internal table.
    The TRANSPORTING addition has the same effect as changing individual lines. The WHERE addition can only be specified together with the TRANSPORTING addition. After WHERE, any logical expression can be specified in which the first operand of each individual comparison is a component of the internal table. All logical expressions are therefore possible, with the exception of IS ASSIGNED, , and IS SUPPLIED. It is not possible to dynamically specify a component using bracketed character-type data objects.
    While for standard tables and hashed tables all lines in the internal table are checked for the logical expression of the WHERE statement, for sorted tables, optimized access can be achieved by checking at least one opening part of the table key for parity using AND linked queries in the logical expression.
    Example
    Change the contents of the planetype component for all lines in the sflight_tab internal table in which this component contains the value p_plane1 to the value p_plane2.
    PARAMETERS: p_carrid TYPE sflight-carrid,
                p_connid TYPE sflight-connid,
                p_plane1 TYPE sflight-planetype,
                p_plane2 TYPE sflight-planetype.
    DATA sflight_tab TYPE SORTED TABLE OF sflight
                     WITH UNIQUE KEY carrid connid fldate.
    DATA sflight_wa TYPE sflight.
    SELECT *
           FROM sflight
           INTO TABLE sflight_tab
           WHERE carrid = p_carrid AND
                 connid = p_connid.
    sflight_wa-planetype = p_plane2.
    MODIFY sflight_tab FROM sflight_wa
           TRANSPORTING planetype WHERE planetype = p_plane1.
    reward if useful

Maybe you are looking for