2016-10-19 24 views
-4

在我眼中,一切都是完美的。为什么它不断说警告:程序创建编译错误?任何人都可以知道有什么问题吗? enter image description here我的程序错误

+3

把你的代码作为文本,而不是图像 –

+0

做基本的调试。在时间添加一行以找到哪条线给你的问题。但是我告诉你,如果你期望有一个用户拥有多个帐户'SELECT INTO'将会失败 –

+0

''用户。密码'与'.'和'密码'之间的空格看起来可疑。同上'用户。 user_id%type'。要了解更多关于错误的信息,你可以尝试'SELECT * FROM ALL_ERRORS WHERE NAME ='LOGIN_USE''。祝你好运。 –

回答

0

“set serveroutput on”不适用于存储过程。

不要使用“select into”,除非您确定知道结果是1条记录。 在你的例子中,结果也可以是2(或更多)记录。

首先让游标对记录进行计数。 如果计数结果为0(零)显示消息。如果计数结果为1,则使用“select into”。更好的开放,获取,关闭建设。如果计数结果超过1,则显示消息超过1(!!!)个帐户。

这是一个工作还是学校相关的问题?

0

带着几分OCR和手动摆弄,我让你的程序是:

create or replace procedure LOGIN_USE(USER_EMAIL IN VARCHAR, USER_PASSWORD IN 
VARCHAR) IS 

acttype users.account_type%type; 
psword users. password%type; 
acctuser users. user_id %type; 
message varchar(100) := 'User name or password are incorrect'; 

Begin 
SELECT account_type, password, user_id INTO acttype, psword, acctuser 
FROM users 
WHERE email = USER_EMAIL; 

IF(psword = USER_PASSWORD) THEN 
dbms_output.put_line('Hello, and Welcome ' || USER_EMAIL); 
dbms_output.put_line('Account Type ' || acttype); 
ELSIF (acctuser >= 2) THEN 
dbms_output.put_line('Warning, You have more than two accounts'); 
ELSE 
dbms_output.put_line(message); 
END IF; 
END; 

当收拾的可读性(你应该养成这样做你自己的习惯),我得到这个:

create or replace procedure login_use 
    (user_email in varchar 
    , user_password in varchar) 
as 
    acttype users.account_type%type; 
    psword users.password%type; 
    acctuser users.user_id%type; 
    message varchar(100) := 'User name or password are incorrect'; 

begin 
    select account_type, password, user_id 
    into acttype,  psword, acctuser 
    from users 
    where email = user_email; 

    if psword = user_password then 
     dbms_output.put_line('Hello, and Welcome ' || user_email); 
     dbms_output.put_line('Account Type ' || acttype); 
    elsif acctuser >= 2 then 
     dbms_output.put_line('Warning, You have more than two accounts'); 
    else 
     dbms_output.put_line(message); 
    end if; 
end; 

这编译为我好,我创建了USERS表作为

create table users 
(account_type varchar2(10) 
, password  varchar2(20) 
, user_id  integer 
, email   varchar2(50)); 
后210

不过:

  1. 您应该使用varchar2没有varchar
  2. 我看不到在选择users.user_idacctuser(混淆命名系统btw)的意义,然后检查该用户ID是否大于1,如果是这样,警告用户有两个以上的帐户。 users表中user_id的典型值是多少?拥有1以上的ID与账户数量有什么关系?你是不是要计算行数?如果users.email不是唯一的,那么你需要重新考虑这个方法。
  3. 我非常希望这不适用于任何真正的系统,因为它以纯文本形式存储密码。至少,如果你将它们与电子邮件地址一起散列,那将是至关重要的。