2
FUNCTION authenticate(p_username IN VARCHAR2,p_password IN VARCHAR2) RETURN 
BOOLEAN 
is
l_count integer;
begin
select count(*)
into   l_count
from   STUDENT, ADMIN, ORGANISATION
WHERE upper(Student.STUDENT_ID, ADMIN.ADMIN_ID, ORGANISATION.ORG_ID) = 
upper(p_username)
AND upper(Student.STUDENT_PASSWORD, ADMIN.ADMIN_PASSWORD, 
ORGANISATION.ORG_PASSWORD) = upper(p_password);
return (l_count > 0);
end;

以上是我为从多个表中获取信息并使用它们来验证登录名而制作的身份验证代码。如果我只是为学生做它工作正常,但我需要多种类型的用户才能访问该软件,我不能同时运行多个身份验证方案所有表名和列名都是正确的下面是我得到的错误ORA-06550:第 9 行,第 7 列:PL/SQL:ORA-00909:参数数量无效 ORA-06550:第 6 行,第 1 列:PL/SQL:忽略 SQL 语句

4

3 回答 3

6

我想尝试将其分解,并解决问题。有很多事情需要解决。

逻辑

您将如何控制表之间的唯一性?学生和行政部门都可能有 ALBERT 。它甚至可能是同一个人、学生和设施的员工。我就是这样的人。

建议的 SQL

你的表之间没有连接,这会将结果变成一个 cartesion 产品,我很确定你可以返回 true 让 ALBERT 使用 NIKOLA 的密码登录。

我认为您可能打算使用集合运算符

select ...
from student 
where ...
union all
select ...
from admin
where ...

UNION ALL意味着不需要检查唯一性,不需要额外的 sort

密码保护

能够 UPPER 密码意味着您将其存储为明文。今天的人们应该继承足够的数字流畅性,密码应该以明文形式存储。曾经。

有关如何通过散列密码在 APEX 中设置自定义身份验证的示例,请参阅本文。在没有散列密码的令人失望的数字中很少见。这个还用用户名和一些盐进行哈希处理,这样更好。 http://barrybrierley.blogspot.com.au/2015/05/custom-authentication-in-apex.html

它还开始满足您对用户类型的需求。

我确定 APEX 文档中有一个示例,但我找不到它。

用户类型 - 授权

一旦你确定你有一个有效的用户,你可以确定他们是什么类型的用户,然后使用授权方案控制他们对各种组件的访问。

对于更灵活的系统,我会进一步抽象,并使用授权方案来控制某些组件的权限,并将这些权限分配给业务角色,然后授予用户

这为您的“多种类型的人”服务。

“记录存在”检查

从一开始,我就在 AskTom 学到了一些关于检查行是否存在的东西,这似乎在所有版本中都适用

declare
  ln_exists pls_integer;
begin
  select count(*)
  into ln_exists
  from dual
  where exists (
     select null 
     from your_table -- whatever you're looking for
     where id = p_id
  );
  return ln_exists = 1; -- true if exists
 end;

Oracle 知道如何花费最少的精力来解决这个问题。

许多其他变体只是从数据库中选择了太多行。

共享应用程序

您实际上可以使用对同一应用程序的不同身份验证定义多个入口点。 http://www.grassroots-oracle.com/2014/04/shared-authentication-across-multiple-apex-apps.html

于 2018-05-28T14:24:45.183 回答
0
With valid_student as (
select count(*) as student_result 
from student 
where upper (p_username) = upper(student_id)
And upper(p_password) = upper(student_password)
),
valid_Admin as (
select count(*) as admin_result 
from admin
where upper (p_username) = upper(admin_id)
And upper(p_password) = upper(admin_password)
),
valid_org as (
select count(*) as org_result 
from organisation 
where upper (p_username) = upper(org_id)
And upper(p_password) = upper(org_password)
)
Select “Valid” as access_allowed
From valid_student s, valid_admin a, valid_org o
 Where s.student_result = 1 or a.admin_result = 1 or o.org_result = 1
于 2018-05-28T14:31:02.783 回答
-1

语法错误。尝试

select count(*) 
into l_count
from student,
     admin,
     organisation
where upper(p_username) in (upper(student.student_id),
                            upper(admin.admin_id),
                            upper(organisation.org_id)
                           )
  and upper(p_password) in (upper(student.student_password),
                            upper(admin.admin_password),
                            upper(organisation.org_password)
                           );
于 2018-05-26T21:25:02.020 回答