例: MERGEでのDEFAULT関数の使用上のルール - Teradata Database - Teradata Vantage NewSQL Engine - 例: MERGEでのDEFAULT関数の使用上のルール

Teradata Vantage™ SQLデータ操作言語

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
2019年3月
Language
日本語
Last Update
2019-10-29
dita:mapPath
ja-JP/fbo1512081269404.ditamap
dita:ditavalPath
ja-JP/fbo1512081269404.ditaval
dita:id
B035-1146
Product Category
Software
Teradata Vantage

次の例では、MERGE文内で正しくDEFAUL関数が使用されています。

     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);