17.05 - Example: Using the DEFAULT Function With MERGE - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

The following examples show the correct use of the DEFAULT function within the MERGE statement.

     MERGE INTO emp
     USING VALUES (100, 'cc', 200, 3333) AS emp1 (empnum, name,
                                                  deptno, sal)
       ON emp1.empnum=emp.s_no
     WHEN MATCHED THEN
       UPDATE SET sal=DEFAULT
     WHEN NOT MATCHED THEN
       INSERT VALUES (emp1.empnum, emp1.name, emp1.deptno, emp1.sal);
     MERGE INTO emp
     USING VALUES (100, 'cc', 200, 3333) AS emp1 (empnum, name,
                                                  deptno, sal)
       ON emp1.empnum=emp.s_no
     WHEN MATCHED THEN
       UPDATE SET sal=DEFAULT(emp.sal)
     WHEN NOT MATCHED THEN
       INSERT VALUES (emp1.empnum, emp1.name, emp1.deptno, emp1.sal);     
       USING (empno INTEGER,
             name   VARCHAR(50),
             salary INTEGER)
     MERGE INTO employee AS t
     USING VALUES (:empno, :name, :salary) AS s(empno, name, salary)
       ON t.empno=s.empno
     WHEN MATCHED THEN UPDATE
       SET salary=s.salary
     WHEN NOT MATCHED THEN INSERT (empno, name, salary)
       VALUES (s.empno, s.name, s.salary);