Apex包中的编译错误
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个有根据的猜测。编译错误最可能的来源是
VALID_USER()
过程中对VALID_USER2()
的调用。正如我怀疑的那样,如果VALID_USER2()
未在包规范中声明,这将引发 PLS-00313 异常,“未在此范围内声明”。私有函数必须在调用之前声明。另一种方法是前向声明,但是我一直认为这是不必要的重复。
有很多事情对您的实施造成困扰。按严重性升序排列:
UPPER()
和TRIM()
的调用对
GET_HASH()
的调用是放错地方了。只需在
GET_HASH()
本身的主体。GET_HASH()
有一个的签名(P_PASSWORD IN
VARCHAR2,P_USERNAME IN VARCHAR2)
但你总是将其调用为
get_hash(p_用户名,p_密码)
。当然,始终错误
意味着你会得到“正确的”
结果,但仍然是一个错误。
似乎是手卷
身份验证方案而不是
使用内置 Oracle
申请快捷帐户
凭据。你为什么在做
那?
An educated guess. The most likely source of a compilation error is the call to
VALID_USER2()
in theVALID_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:
UPPER()
andTRIM()
inthe calls to
GET_HASH()
aremisplaced. Just use them in the
body of
GET_HASH()
itself.GET_HASH()
has asignature 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.
appear to be hand-rolling an
authentication scheme instead of
using the built-in Oracle
Application Express Account
Credentials. Why are you doing
that?