Apex包中的编译错误

发布于 2024-10-09 20:11:37 字数 1633 浏览 5 评论 0原文

我在 oracle apex 中创建了一个包。编译时我收到这样的错误消息..

请帮助我。

create or replace package body "PKG_APP_SECURITY" is
procedure ADD_USER(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
as
begin
 INSERT INTO P_USERS(username, password)
    VALUES (UPPER (p_username),get_hash(TRIM(p_username), p_password));

COMMIT; 
EXCEPTION
   WHEN OTHERS THEN ROLLBACK; RAISE;
end ADD_USER;

function VALID_USER(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
) return BOOLEAN

as
begin
 VALID_USER2(UPPER(p_username),p_password);
 RETURN TRUE;
EXCEPTION 
 WHEN OTHERS THEN RETURN FALSE;
end VALID_USER;

function GET_HASH(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
) RETURN VARCHAR2 AS 
    BEGIN 
    RETURN 
       DBMS_OBFUSCATION_TOOLKIT.md5(input_string => UPPER (p_username) || '/' || UPPER (p_password));
end GET_HASH;

procedure LOGIN(P_FLOW_PAGE IN VARCHAR2
      ,P_PASSWORD IN VARCHAR2
      ,P_SESSION_ID IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
is
begin
-- THIS PROVIDES AUTHENTICATION
     wwv_flow_custom_auth_std.login 
       (p_uname => p_uname
          ,p_password => p_password
            ,p_session_id => p_session_id
           ,p_flow_page => p_flow_page || ':' || 1);
end LOGIN;

procedure VALID_USER2(       P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
as
begin
 SELECT '1'
 INTO v_dummy 
 FROM P_USERS
 WHERE UPPER(username) = UPPER (p_username)
 AND password= get_hash (p_username, p_password);

EXCEPTION 
   WHEN NO_DATA_FOUND THEN 
   raise_application_error(-20000, 'Invalid username / password.');
end VALID_USER2;

end "PKG_APP_SECURITY";​

I have created one package in oracle apex. While compiling i got an error msg like this..

please help me.

create or replace package body "PKG_APP_SECURITY" is
procedure ADD_USER(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
as
begin
 INSERT INTO P_USERS(username, password)
    VALUES (UPPER (p_username),get_hash(TRIM(p_username), p_password));

COMMIT; 
EXCEPTION
   WHEN OTHERS THEN ROLLBACK; RAISE;
end ADD_USER;

function VALID_USER(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
) return BOOLEAN

as
begin
 VALID_USER2(UPPER(p_username),p_password);
 RETURN TRUE;
EXCEPTION 
 WHEN OTHERS THEN RETURN FALSE;
end VALID_USER;

function GET_HASH(P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
) RETURN VARCHAR2 AS 
    BEGIN 
    RETURN 
       DBMS_OBFUSCATION_TOOLKIT.md5(input_string => UPPER (p_username) || '/' || UPPER (p_password));
end GET_HASH;

procedure LOGIN(P_FLOW_PAGE IN VARCHAR2
      ,P_PASSWORD IN VARCHAR2
      ,P_SESSION_ID IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
is
begin
-- THIS PROVIDES AUTHENTICATION
     wwv_flow_custom_auth_std.login 
       (p_uname => p_uname
          ,p_password => p_password
            ,p_session_id => p_session_id
           ,p_flow_page => p_flow_page || ':' || 1);
end LOGIN;

procedure VALID_USER2(       P_PASSWORD IN VARCHAR2
      ,P_USERNAME IN VARCHAR2
)
as
begin
 SELECT '1'
 INTO v_dummy 
 FROM P_USERS
 WHERE UPPER(username) = UPPER (p_username)
 AND password= get_hash (p_username, p_password);

EXCEPTION 
   WHEN NO_DATA_FOUND THEN 
   raise_application_error(-20000, 'Invalid username / password.');
end VALID_USER2;

end "PKG_APP_SECURITY";​

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2024-10-16 20:11:37

一个有根据的猜测。编译错误最可能的来源是 VALID_USER() 过程中对 VALID_USER2() 的调用。正如我怀疑的那样,如果 VALID_USER2() 未在包规范中声明,这将引发 PLS-00313 异常,“未在此范围内声明”。

私有函数必须在调用之前声明。另一种方法是前向声明,但是我一直认为这是不必要的重复。


有很多事情对您的实施造成困扰。按严重性升序排列:

  1. UPPER()TRIM() 的调用
    GET_HASH() 的调用是
    放错地方了。只需在
    GET_HASH() 本身的主体。
  2. 过程 GET_HASH() 有一个
    的签名(P_PASSWORD IN
    VARCHAR2,P_USERNAME IN VARCHAR2)

    但你总是将其调用为
    get_hash(p_用户名,p_密码)
    当然,始终错误
    意味着你会得到“正确的”
    结果,但仍然是一个错误。
  3. 最担心的是你
    似乎是手卷
    身份验证方案而不是
    使用内置 Oracle
    申请快捷帐户
    凭据
    。你为什么在做
    那?

An educated guess. The most likely source of a compilation error is the call to VALID_USER2() in the VALID_USER() procedure. If, as I suspect, VALID_USER2() is not declared in the package spec this will hurl a PLS-00313 exception, "not declared in this scope".

Private functions must be declared before they are invoked. The alternate is forward declaration, but that has always struck me as unnecessary duplication.


There are a number of things which are troubling about your implementation. In ascending order of severity:

  1. Those calls to UPPER() and TRIM() in
    the calls to GET_HASH() are
    misplaced. Just use them in the
    body of GET_HASH() itself.
  2. The procedure GET_HASH() has a
    signature of (P_PASSWORD IN
    VARCHAR2,P_USERNAME IN VARCHAR2)

    but you always invoke it as
    get_hash (p_username, p_password).
    Of course, being consistently wrong
    means you will get the "right"
    result but it's still an error.
  3. The most worrisome thing is that you
    appear to be hand-rolling an
    authentication scheme instead of
    using the built-in Oracle
    Application Express Account
    Credentials
    . Why are you doing
    that?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文