473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

MERGE INTO omitting WHEN NOT MATCHED

Can you write a MERGE statement omitting one of the WHEN MATCHED and WHE NOT MACTHED statements. In my program I have to update when macthed and not do any thing when not matched.

EX:

Expand|Select|Wrap|Line Numbers
  1.  MERGE INTO table1 tb1 USING table2 tb2 
  2. WHEN MACTHED THEN
  3. UPDATE SET
  4. tb1.col1 = tb2.col1
  5. WHEN NOT MACTHED
  6.  
then do nothing

I tried completely omitting WHEN NOT MACTHED and putting NULL; under WHEN NOT MACTHED section which always gave me sysntax error. I need a solution urgently. Any help is greatly appreciated.

-Sree
Aug 19 '05 #1
1 19520
rebeaj
2
I can't even get my merge statement to work. I see that you have been successful at it. I don't think that you can leave out the when not matched. Here is my merge statement. I cannot get it to compile without errors:
Expand|Select|Wrap|Line Numbers
  1.  CREATE OR REPLACE PROCEDURE P_PVT_MERGE 
  2. AS
  3. BEGIN 
  4. MERGE INTO EMPLOYEES2 B
  5. USING (
  6. SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, DEPT_NO, SALARY
  7. FROM EMPLOYEES
  8. WHERE DEPT_NO = 20) E
  9. ON (B.EMPLOYEE_ID = E.EMPLOYEE_ID)
  10. WHEN MATCHED THEN
  11. UPDATE SET B.EMPLOYEE_ID = E.EMPLOYEE_ID,
  12. B.FIRST_NAME = E.FIRST_NAME,
  13. B.LAST_NAME = E.LAST_NAME,
  14. B.DEPT_NO = E.DEPT_NO,
  15. B.SALARY = E.SALARY
  16. WHEN NOT MATCHED THEN
  17. INSERT (B.EMPLOYEE_ID, B.FIRST_NAME, B.LAST_NAME, B.DEPT_NO, B.SALARY)
  18. VALUES (E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.DEPT_NO, E.SALARY)
  19. COMMIT;
  20. END;
  21.  
/
Jan 4 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Newbie | last post by:
Hi, I am trying to merge data from two tables (over two servers, using dblink). Approx 40,000 records in each. Server1(source) and Server2(dest) On Server1, db-link "dblink1" points to...
1
by: Shan R Shanmuganathan | last post by:
Try this: create table xyz ( c1 number ); insert into xyz values ( 5 ); 1 row created. select * from xyz; C1
4
by: Bob Stearns | last post by:
The statement: merge into nullid.animals_et_in t1 using is3.animals t2 on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and t1.sire_regnum=t2.regnum when matched then update set...
5
by: Janick Bernet | last post by:
I'm going crazy trying to write a working merge-statement. Why doesn't the following work: MERGE INTO utSystem.t_Filter_Results AS Res USING (SELECT 9 as clubid, 50 as filterid, ID as MemberID...
16
by: Sam Durai | last post by:
Hello, I need to merge a small table (of rows less than 100,sometimes even 0 rows) to a big table (of rows around 4 billion). I used the PK of the big table as merge key but merge does a table scan...
5
by: melentina | last post by:
Hello, I'm trying to use MERGE statement in a procedure, please see the code below: procedure gen_nou (p_data date) is v_atribut_id number; begin v_atribut_id=100;
1
by: sumanroyc | last post by:
Hi All, We are encountering a strange problem with the merge command. The following statement works :- merge into ATTRIBUTE_GROUP@US_PRODUCT_UAT a using ( select
7
by: Michel Esber | last post by:
Question About Merge DB2 V8 LUW FP 15. Hello, Consider table A (ID integer not null PK, Field2 varchar(50)). I have the existing following set of rows in the table:
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.