Questions tagged [sql-merge]

`SQL MERGE` statement allows us to insert new rows into table and update existing rows depending on given condition. Use this tag in addition to [tag:sql] to make question better categorized.

SQL MERGE statement allows us to insert new rows into table and update existing rows depending on given condition.

Examples of using MERGE statement:

Use this tag in addition to to make question better categorized.

324 questions
3
votes
1 answer

Massive UPDATE vs. MERGE performance on Oracle

I am trying to update a destination table from a source table using a single, massive UPDATE statement, but the execution time is way longer than it should. Query UPDATE MY_DEST SET (DEST_B, DEST_C) = ( SELECT SRC_A + SRC_B, SRC_B FROM MY_SRC …
3
votes
1 answer

Merge with select with multiple rows

I have a query which every time runs, selects the rows of user_triggers which are related to a table(p_table_name_in). I want to run this procedure every day and I want to just insert new rows, not all rows again. but when I install this oackage , I…
mona shiri
  • 57
  • 8
3
votes
2 answers

BigQuery: Concatenate two arrays and keep distinct values within MERGE statement

I am working on a MERGE process and update an array field with new data but only if the value isn't already found in the array. target table +-----+----------+ | id | arr_col | +-----+----------+ | a | [1,2,3] | | b | [0] …
3
votes
1 answer

SQL MERGE statement not case sensitive

I have the following MERGE statement: MERGE TargetTable t USING SourceTable s ON (t.ID = s.ID) WHEN MATCHED AND EXISTS (SELECT s.Day, s.Date, s.Name EXCEPT SELECT t.Day, t.Date, t.Name) THEN UPDATE …
Pearl
  • 392
  • 2
  • 12
3
votes
1 answer

ORA-38104: Columns referenced in the ON Clause cannot be updated c.emp_id

i have 2 simple table CREATE TABLE employee ( emp_id INT PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40), birth_day DATE, sex VARCHAR(1), salary INT, super_id INT, branch_id INT ); CREATE TABLE biodata ( emp_id INT…
3
votes
1 answer

Merging without source table Oracle SQL Developer

Im trying to merge data to a database and i cannot without a table and i would like not to create a temporary table just to be deleted afterwards MERGE INTO target_table target USING ('0101-2019' as date, 1515 as random_data, 9595 as…
3
votes
3 answers

If the record exists in target but doesn't exist in source, i need to delete it

So, i have two tables, the target table and the source one. I need to delete the rows that exists in the target table, but doesn't exists in the source table. And the code: MERGE INTO (SELECT id_car_bk, car_brand_bk, car_type_bk, new_car …
Andrei GH
  • 53
  • 1
  • 5
3
votes
1 answer

How to correct migrate MERGE statement with " NOT MATCHED BY TARGET " from MS SQL to PostgreSQL?

I have such sql statement: MERGE pvl.testTable AS T USING temp.testTable AS S ON (T.Id = S.ID) WHEN NOT MATCHED BY TARGET THEN INSERT (first, second, third, fourth) VALUES (s.first, …
Roman Martyshchuk
  • 195
  • 1
  • 2
  • 7
3
votes
1 answer

Best way to handle insert/update process for application with high transaction of data?

I have been working on my single page application for the past few months and while trying to improve some things on the back end I started digging more into my process of Insert/Update and database in general. I use SQL Server 2008 and database is…
3
votes
0 answers

Oracle merge statement and by source/target condition

I need to do a MERGE in Oracle, but I'm stuck. In SQL Server, I always use the BY SOURCE and BY TARGET condition to check where record exists, and then take an action. I'm a little confused because I don't know how to achieve the same in PL/SQL. I…
tylkonachwile
  • 2,025
  • 4
  • 16
  • 28
3
votes
1 answer

Merge: when not matched by source - update rows

I'm trying to figure out the merge function where I have to update rows that exist in target table but those rows doesn't match with rows in source table. Those that didn't match in source table I would like to update in line where it say's WHEN…
Dragon.M
  • 249
  • 1
  • 4
  • 11
3
votes
2 answers

JdbcTemplate - Insert or update Oracle BLOB using SQL MERGE

Using JdbcTemplate I would like to call MERGE SQL statement which will insert a new record to the table or update if row with specific key already exists. The key part is that one of the column is of the Oracle BLOB type. Here is what I tried till…
kpater87
  • 1,190
  • 12
  • 31
3
votes
2 answers

Primary key violation while merging data from another table

I have two tables, TBTC03 and TBTC03Y, with TBTC03Y having two extra columns as EFFDTE and EXPDTE. I have to merge the data from TBTC03 to TBTC03Y with the following logic: If no matching TC03 entry is found in TC03Y a new TC03Y record is build…
CHS
  • 173
  • 1
  • 1
  • 8
3
votes
2 answers

Merge statement issue in oracle

I came from Microsoft SQL environment.I have two tables tak_ne and tak_beb and my requirement was to insert values from tak_beb to tak_ne if value is not present,if it is present just update.So i made a merge statement as shown below.But the problem…
peter
  • 8,158
  • 21
  • 66
  • 119
3
votes
2 answers

How to update SQL table from other table when they are on different servers

I've already run the following command to include another server instance. EXEC sp_addlinkedserver @server='Server' Now I'm trying to synchronize these databases using this: UPDATE [Server].[ServerDB].[dbo].[tableName] SET …
Charles Clayton
  • 17,005
  • 11
  • 87
  • 120
1 2
3
21 22