1. 程式人生 > >oracleinsert的時候返回插入的ID

oracleinsert的時候返回插入的ID

return line 默認 exception The 年齡 ack others com

//----------------  聲明部分  ----------------

create or replace package Pro_Test_User is
PROCEDURE Ins_Test_User(I_ID IN VARCHAR2,I_NAME IN VARCHAR2,I_AGE IN VARCHAR2,O_RET_CODE OUT NUMBER,O_RET_MSG OUT VARCHAR2);
end Pro_Test_User;

//----------------  BODY部分  ----------------

create or replace package body Pro_Test_User is
PROCEDURE Ins_Test_User(I_ID IN VARCHAR2,
I_NAME IN VARCHAR2,
I_AGE IN VARCHAR2,
O_RET_CODE OUT NUMBER,
O_RET_MSG OUT VARCHAR2)IS
v_id Test_User.ID%type;
BEGIN
O_RET_CODE:=0;
O_RET_MSG:=‘初始化默認成功‘;

IF I_ID IS NOT NULL AND I_NAME IS NOT NULL AND I_AGE IS NOT NULL THEN
INSERT INTO Test_User(ID,NAME,AGE) VALUES (I_ID,I_NAME,I_AGE) returning ID into v_id;
dbms_output.put_line(v_id);
COMMIT;
O_RET_CODE:=0;
O_RET_MSG:=‘操作成功‘;
ELSE
O_RET_CODE:=1;
O_RET_MSG:=‘沒有ID|姓名|年齡‘;
END IF;
EXCEPTION
WHEN OTHERS THEN
O_RET_CODE:=-1;
O_RET_MSG:=‘sql執行過程出錯啦!‘;
END Ins_Test_User;


end Pro_Test_User;

oracleinsert的時候返回插入的ID