比較字符串有了這張表:的Oracle PL/SQL的過程
CREATE TABLE HR.MSG_USER (
ID number(38) NOT NULL,
NAME varchar2(100) NOT NULL,
PASS varchar2(10) NOT NULL,
LOGIN varchar2(20) NOT NULL,
CONSTRAINT IDX_USER_LOGIN_UNIQUE UNIQUE (LOGIN) ,
CONSTRAINT PK_USER PRIMARY KEY (ID) ,
CONSTRAINT IDX_USER_NAME_UNIQUE UNIQUE (NAME)
);
我創造了這個過程:
create or replace procedure new_user (login IN VARCHAR, name IN VARCHAR, pass IN VARCHAR) is
rowsFound number;
ERR_NULL exception;
ERR_NAME_TOO_LONG exception;
ERR_NAME_DUPLICATED exception;
ERR_UNIQUE exception;
PRAGMA EXCEPTION_INIT(ERR_NULL, -20001);
PRAGMA EXCEPTION_INIT(ERR_NAME_TOO_LONG, -20002);
PRAGMA EXCEPTION_INIT(ERR_NAME_DUPLICATED, -20003);
PRAGMA EXCEPTION_INIT(ERR_UNIQUE, -20013);
begin
if (login is null) or (name is null) or (pass is null) then
raise_application_error(-20001, 'Datos de Usuario Nulos');
end if;
if (LENGTH(name) > 100) then
raise_application_error(-20002, 'Nombre Usuario Demasiado Largo');
end if;
select count(*) into rowsFound from MSG_USER where NAME = name;
if rowsFound >= 1 then
raise_application_error(-20013, 'Usuario Ya Existe: Name');
end if;
select count(*) into rowsFound from MSG_USER where LOGIN = login;
if rowsFound >= 1 then
raise_application_error(-20013, 'Usuario Ya Existe: Login');
end if;
INSERT INTO MSG_USER ("ID", "NAME", "PASS", "LOGIN") VALUES (seq_MSG_USER_id.nextval, name, pass,login);
dbms_output.put_line('Usuario Creado: '||name);
commit;
end;
/
當我插入與EXEC用戶:
exec new_user('testL1','testN1','testP1');
exec new_user('testL2','testN2','testP2');
第二個失敗,用ORA-20013;這意味着(testL1 = testL2)= True。但使用:
select count(*) from MSG_USER where NAME = 'testN2';
計算它是等於0。我不知道爲什麼;有人可以幫我糾正我的程序嗎?