可以用merge语句。给你举个例子
CREATE OR REPLACE PROCEDURE test (in_deptno IN NUMBER, in_dname IN VARCHAR2, in_loc IN VARCHAR2)AS t_record scott.dept%ROWTYPE;BEGIN SELECT in_deptno, in_dname, in_loc INTO t_record FROM DUAL;---用merge语句 MERGE INTO scott.dept dept USING (SELECT t_record.deptno, t_record.dname, t_record.loc FROM DUAL) ON (dept.deptno = t_record.deptno) WHEN MATCHED THEN UPDATE SET dept.dname = t_record.dname, dept.loc = t_record.loc WHEN NOT MATCHED THEN INSERT (deptno, dname, loc) VALUES (t_record.deptno, t_record.dname, t_record.loc);END;
取消
评论