该怎么办?我的用户定义输入不允许我输入值

时间:2014-04-28 02:28:02

标签: plsql ampersand defined

我编写了一个程序,该程序应该允许输入用户名和密码,如果成功,它应该处理登录的时间戳。问题是代码似乎完全跳过&用户名并转到下一个用户定义的条目,即条目中的& pass。这是我的代码: ECHO已开启,因此服务器BTW

create or replace procedure LOGIN_CK_PF
as
fname   bb_shopper.firstname%type;
lname   bb_shopper.lastname%type;
uname   bb_shopper.username%type;
pass    bb_shopper.password%type;


begin

    select firstname, lastname, username, password 
    into fname, lname, uname, pass from bbshop 
    where username=&username;

    if pass = &pass then
    dbms_output.put_line(Sysdate);
    else
    dbms_output.put_line('Invalid Login');
    end if;

exception
    when no_data_found then
    dbms_output.put_line('Invalid Login');

end;
/

这是输入值时代码输出的样子:

Enter value for username: 
old  11:  select firstname, lastname, username, 
                 password into fname, lname, uname, pass 
          from bbshop 
new  11:  select firstname, lastname, username, 
                  password into fname, lname, uname, pass 
          from bbshop 

它看起来像将整个select语句作为条目??? 特定行的错误如下:

11/2     PL/SQL: SQL Statement ignored
11/107   PL/SQL: ORA-00936: missing expression

1 个答案:

答案 0 :(得分:1)

您需要使用正确的PL / SQL参数传入您的过程。

CREATE OR REPLACE PROCEDURE LOGIN_CK_PF (P_User   IN VARCHAR2,
                                         P_Pass   IN VARCHAR2)
AS
   fname   bb_shopper.firstname%TYPE;
   lname   bb_shopper.lastname%TYPE;
   uname   bb_shopper.username%TYPE;
   pass    bb_shopper.password%TYPE;
BEGIN
   SELECT firstname, lastname, username, password
     INTO fname, lname, uname, pass
     FROM bbshop
    WHERE username = P_User;

   IF pass = P_Pass THEN
      DBMS_OUTPUT.put_line (SYSDATE);
   ELSE
      DBMS_OUTPUT.put_line ('Invalid Login');
   END IF;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
      DBMS_OUTPUT.put_line ('Invalid Login');
END;

/