APEX - 将值与当前用户 ID 进行比较
APEX - Compare value against current user ID
我正在尝试创建一个报告,该报告将根据用户 ID 显示过滤后的信息。讲师将能够登录系统并看到他们领导的所有模块,登录 ID 与用于在模块中定义讲师代码的讲师代码相同 table。
这是我的 SQL 查询。
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator FROM module m, lecturer l
WHERE m.lecturer_code = [Select l.lecturer_code from lecturer l where
l.lecturer_code = UserInfo.getUserId()];
我在尝试将其用作报告来源时收到以下错误 "Query cannot be parsed, please check the syntax of your query. (ORA-00936: missing expression)"。
我是 APEX 的新手。知道为什么此代码无效吗?
如果我理解你的意图,正确的 SQL 应该是:
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator
FROM module m JOIN
lecturer l
ON m.lecturer_code = l.lecturer_code
WHERE l.lecturer_code = UserInfo.getUserId();
UserInfo.getUserId()
不是 Oracle 的标准部分(据我所知)。您可以使用 USER
或类似的函数来获取数据库中的用户 ID。获取系统信息的一般函数是 SYS_CONTEXT()
,它在 here 中有记载。你可能想要 "SYSTEM_USER": SYS_CONTEXT('USERENV', 'SESSION_USER')
.
在你的情况下,你可能只需要 EXISTS
:
SELECT m.*
FROM module m
WHERE EXISTS (SELECT 1
FROM lecture l
WHERE m.lecturer_code = l.lecturer_code AND
l.lecturer_code = UserInfo.getUserId()
);
这些都没有解决 Oracle 不理解 UserInfo.getUserId()
的问题。
据我所知,apex
中没有任何类似于 UserInfo.getUserId() 的代码
在我的代码中,我使用 apex cookie 来获取登录用户的用户名,然后为了查找 ID,我在括号中使用了类似于下面的代码
为了适应你可以使用如下
l.lecturer_code = (select USER_ID from USERS_TABLE where USER_USERNAME=apex_authentication.get_login_username_cookie)
创建一个页面进程包为:
declare
v varchar2(255) := null;
c owa_cookie.cookie;
begin
c := owa_cookie.get('LOGIN_USERNAME_COOKIE');
:P1_USERNAME := c.vals(1);
exception when others then null;
end;
根据上述获取用户名的过程,您可以编写如下查询:
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator FROM module m, lecturer l
WHERE m.lecturer_code = (Select l.lecturer_code from lecturer l where
l.lecturer_code = :P1_USERNAME);
Make appropriate change in your database table for lecture code to be
comparable with username
在 Apex 中,您使用 :APP_USER
检索用户。此绑定变量包含用户用于登录应用程序的值(因此,登录页面上的 :P101_USERNAME
中的值)。
如果您需要与用户有关的实际 ID 或任何其他相关信息,您应该创建一些应用程序项来存储该信息。在身份验证方案的 post- 身份验证过程中,您可以根据使用的登录名将值检索到应用程序项中。
我正在尝试创建一个报告,该报告将根据用户 ID 显示过滤后的信息。讲师将能够登录系统并看到他们领导的所有模块,登录 ID 与用于在模块中定义讲师代码的讲师代码相同 table。
这是我的 SQL 查询。
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator FROM module m, lecturer l
WHERE m.lecturer_code = [Select l.lecturer_code from lecturer l where
l.lecturer_code = UserInfo.getUserId()];
我在尝试将其用作报告来源时收到以下错误 "Query cannot be parsed, please check the syntax of your query. (ORA-00936: missing expression)"。
我是 APEX 的新手。知道为什么此代码无效吗?
如果我理解你的意图,正确的 SQL 应该是:
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator
FROM module m JOIN
lecturer l
ON m.lecturer_code = l.lecturer_code
WHERE l.lecturer_code = UserInfo.getUserId();
UserInfo.getUserId()
不是 Oracle 的标准部分(据我所知)。您可以使用 USER
或类似的函数来获取数据库中的用户 ID。获取系统信息的一般函数是 SYS_CONTEXT()
,它在 here 中有记载。你可能想要 "SYSTEM_USER": SYS_CONTEXT('USERENV', 'SESSION_USER')
.
在你的情况下,你可能只需要 EXISTS
:
SELECT m.*
FROM module m
WHERE EXISTS (SELECT 1
FROM lecture l
WHERE m.lecturer_code = l.lecturer_code AND
l.lecturer_code = UserInfo.getUserId()
);
这些都没有解决 Oracle 不理解 UserInfo.getUserId()
的问题。
据我所知,apex
中没有任何类似于 UserInfo.getUserId() 的代码在我的代码中,我使用 apex cookie 来获取登录用户的用户名,然后为了查找 ID,我在括号中使用了类似于下面的代码 为了适应你可以使用如下
l.lecturer_code = (select USER_ID from USERS_TABLE where USER_USERNAME=apex_authentication.get_login_username_cookie)
创建一个页面进程包为:
declare
v varchar2(255) := null;
c owa_cookie.cookie;
begin
c := owa_cookie.get('LOGIN_USERNAME_COOKIE');
:P1_USERNAME := c.vals(1);
exception when others then null;
end;
根据上述获取用户名的过程,您可以编写如下查询:
SELECT m.module_code, m.module_name, m.lecturer_code,
m.module_number_assessments, m.module_moderator FROM module m, lecturer l
WHERE m.lecturer_code = (Select l.lecturer_code from lecturer l where
l.lecturer_code = :P1_USERNAME);
Make appropriate change in your database table for lecture code to be comparable with username
在 Apex 中,您使用 :APP_USER
检索用户。此绑定变量包含用户用于登录应用程序的值(因此,登录页面上的 :P101_USERNAME
中的值)。
如果您需要与用户有关的实际 ID 或任何其他相关信息,您应该创建一些应用程序项来存储该信息。在身份验证方案的 post- 身份验证过程中,您可以根据使用的登录名将值检索到应用程序项中。