CREATE PROCEDURE PAMS.ORGMERCANT_TEST()
LANGUAGE SQL
------------------------------
--NAME pams.organ
--description 是否营销部门认定
--author: levma
--date 2007-6-18
-----------------------------
BEGIN
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQL_CODE INTEGER DEFAULT 0;
DECLARE sqlMsg VARCHAR(255) ;
--声明异常处理
DECLARE CONTINUE HANDLER FOR NOT FOUND ,SQLEXCEPTION
BEGIN
SET SQL_CODE=SQLCODE;
END;
=======================SQL语句开始=====================================
MERGE INTO PAMS.ORG_MERCANT AS A
USING ( select instno,mercant,contain from pams.organ where insttype='1')AS B
ON A.INSTNO = B.INSTNO
WHEN NOT MATCHED THEN
INSERT (A.INSTNO ,A.MERCANT,A.CONTAIN ) VALUES(B.INSTNO,B.MERCANT,B.CONTAIN);
========================SQL语句结束====================================
IF sql_code<> 0 AND sql_code <> 100 THEN
SET sqlMsg = '失败';
GOTO ERROR_RETURN;
END IF;
COMMIT;
set sqlMsg = '成功!';
set sql_code = 0;
return 1;
ERROR_RETURN:
ROLLBACK;
return -1;
END ;