我正在尝试在oracle 11g中执行以下函数
CREATE OR REPLACE PROCEDURE EMAT_PROC_AD_USER_LOGIN
(USER_ID_IN IN VARCHAR2, PASSWORD_IN IN VARCHAR2,USER_ID_OUT OUT VARCHAR2)
IS
chk boolean;
TESTING VARCHAR2(200);
BEGIN
SELECT USER_ID into TESTING FROM AD_USERMASTER WHERE USER_ID=USER_ID_IN and password=password_in;
if(testing=user_id_in)then
testing:=user_id_out;
DBMS_OUTPUT.PUT_LINE('hi');
DBMS_OUTPUT.PUT_LINE(user_id_out);
chk:=true;
end if;
IF (USER_ID_IN is NULL AND PASSWORD_IN IS NULL) THEN
TESTING:='Username AND Password Cannot Be Blank';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSIF (USER_ID_IN is NULL OR PASSWORD_IN IS NULL) THEN
TESTING:='USER ID OR PASSWORD Cannot Be Blank';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSIF chk THEN
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSE
TESTING:='USER ID AND PASSWORD INCORRECT';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
END IF;
Exception
When NO_DATA_FOUND Then
DBMS_OUTPUT.PUT_LINE('ERROR: '||sqlerrm);
Raise; -- To ensure if this is the error, you will set get no_data_found raised...
END;
在oracle 11g中执行此过程时显示错误 连接到数据库emat。
ORA-01403:未找到数据ORA-06512:at" EMAT.EMAT_PROC_AD_USER_LOGIN", 第39行ORA-06512:第9行错误:ORA-01403:未找到数据
答案 0 :(得分:3)
说你有这张桌子:
create table AD_USERMASTER(USER_ID, password) as ( select 'userName', 'password' from dual)
并且您希望您的过程的行为如下:
USER_ID_IN PASSWORD_IN USER_ID_OUT
null null 'Username AND Password Cannot Be Blank'
null 'xx' 'USER ID OR PASSWORD Cannot Be Blank'
'aa' null 'USER ID OR PASSWORD Cannot Be Blank'
'aa' 'xx' 'USER ID AND PASSWORD INCORRECT'
'userName' 'xx' 'USER ID AND PASSWORD INCORRECT'
'aa' 'password' 'USER ID AND PASSWORD INCORRECT'
'userName' 'password' 'userName'
这可能是一种方式:
CREATE OR REPLACE PROCEDURE EMAT_PROC_AD_USER_LOGIN
(USER_ID_IN IN VARCHAR2, PASSWORD_IN IN VARCHAR2,USER_ID_OUT OUT VARCHAR2)
IS
BEGIN
case
when USER_ID_IN is null AND PASSWORD_IN is null then
USER_ID_OUT := 'Username AND Password Cannot Be Blank';
when USER_ID_IN is null OR PASSWORD_IN is null then
USER_ID_OUT := 'USER ID OR PASSWORD Cannot Be Blank';
else
begin
SELECT USER_ID
into USER_ID_OUT
FROM AD_USERMASTER
WHERE USER_ID=USER_ID_IN
and password=password_in;
exception
when NO_DATA_FOUND then
USER_ID_OUT := 'USER ID AND PASSWORD INCORRECT';
end;
end case;
end;
<强>试验:强>
SQL> declare
2 vUserCheck varchar2(100);
3 begin
4 EMAT_PROC_AD_USER_LOGIN(null ,null , vUserCheck);
5 dbms_output.put_line(null || ' - ' || null || ' - ' || vUserCheck);
6 EMAT_PROC_AD_USER_LOGIN(null ,'xx' , vUserCheck);
7 dbms_output.put_line(null || ' - ' || 'xx' || ' - ' || vUserCheck);
8 EMAT_PROC_AD_USER_LOGIN('aa' ,null , vUserCheck);
9 dbms_output.put_line('aa' || ' - ' || null || ' - ' || vUserCheck);
10 EMAT_PROC_AD_USER_LOGIN('aa' ,'xx' , vUserCheck);
11 dbms_output.put_line('aa' || ' - ' || 'xx' || ' - ' || vUserCheck);
12 EMAT_PROC_AD_USER_LOGIN('userName' ,'xx' , vUserCheck);
13 dbms_output.put_line('userName' || ' - ' || 'xx' || ' - ' || vUserCheck);
14 EMAT_PROC_AD_USER_LOGIN('aa' ,'password', vUserCheck);
15 dbms_output.put_line('aa' || ' - ' || 'password' || ' - ' || vUserCheck);
16 EMAT_PROC_AD_USER_LOGIN('userName' ,'password', vUserCheck);
17 dbms_output.put_line('userName' || ' - ' || 'password' || ' - ' || vUserCheck);
18 end;
19 /
- - Username AND Password Cannot Be Blank
- xx - USER ID OR PASSWORD Cannot Be Blank
aa - - USER ID OR PASSWORD Cannot Be Blank
aa - xx - USER ID AND PASSWORD INCORRECT
userName - xx - USER ID AND PASSWORD INCORRECT
aa - password - USER ID AND PASSWORD INCORRECT
userName - password - userName
PL/SQL procedure successfully completed.
答案 1 :(得分:-1)
你想要什么,请描述一下。很简单,在执行过程SELECT USER_ID into TESTING FROM AD_USERMASTER WHERE USER_ID=USER_ID_IN and password=password_
时,此Query不会从表中获取任何数据。所以使用像
BEGIN
SELECT USER_ID into TESTING FROM AD_USERMASTER WHERE USER_ID=USER_ID_IN and password=password_
Exception
When NO_DATA_FOUND Then
Do you task;
它应该是你的程序
CREATE OR REPLACE PROCEDURE EMAT_PROC_AD_USER_LOGIN (USER_ID_IN IN VARCHAR2, PASSWORD_IN IN VARCHAR2,USER_ID_OUT OUT VARCHAR2) IS
chk boolean;
TESTING VARCHAR2(200);
BEGIN
BEGIN
SELECT USER_ID into TESTING FROM AD_USERMASTER WHERE USER_ID=USER_ID_IN
and password=password_in;
EXCEPTION
When no_data_found then
TESTING:= 'No data to print';
END;
if(testing=user_id_in)then
testing:=user_id_out;
DBMS_OUTPUT.PUT_LINE('hi');
DBMS_OUTPUT.PUT_LINE(user_id_out);
chk:=true;
end if;
IF (USER_ID_IN is NULL AND PASSWORD_IN IS NULL) THEN
TESTING:='Username AND Password Cannot Be Blank';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSIF (USER_ID_IN is NULL OR PASSWORD_IN IS NULL) THEN
TESTING:='USER ID OR PASSWORD Cannot Be Blank';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSIF chk THEN
DBMS_OUTPUT.PUT_LINE(TESTING);
ELSE
TESTING:='USER ID AND PASSWORD INCORRECT';
USER_ID_OUT:=TESTING;
DBMS_OUTPUT.PUT_LINE(TESTING);
END IF;
Exception
When NO_DATA_FOUND Then
DBMS_OUTPUT.PUT_LINE('ERROR: '||sqlerrm);
Raise; -- To ensure if this is the error, you will set get no_data_found raised...
END;