如何通过 Oracle 18c 中的用户定义过程访问 HR 模式对象?
How to access the HR schema objects through a user defined procedure in Oracle 18c?
我已经给出了代码和我在尝试创建过程 user1 时收到的错误消息。我尝试在 Oracle XE 18c 的示例 hr 模式中访问员工 table。我能知道如何通过用户定义的过程访问 hr 模式对象吗
CREATE OR REPLACE PROCEDURE proc_1 IS
v_name hr.employees.first_name%TYPE;
v_num NUMBER;
BEGIN
SELECT first_name INTO v_name FROM hr.employees
WHERE employee_id=100;
v_num:=5;
DBMS_OUTPUT.PUT_LINE('test'||v_name);
DBMS_OUTPUT.PUT_LINE(v_num);
END;
/
警告:创建的过程存在编译错误。
SQL> show errors
Errors for PROCEDURE PROC_1:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/8 PL/SQL: Item ignored
2/8 PLS-00201: identifier 'HR.EMPLOYEES' must be declared
5/1 PL/SQL: SQL Statement ignored
5/39 PL/SQL: ORA-00942: table or view does not exist
7/1 PL/SQL: Statement ignored
7/38 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
您需要向用户 user1 授予对 HR 对象的访问权限。
作为用户 HR 连接:
grant select on employees to user1;
你需要直接给hr.employees
table的select grant
。
从HR用户,你需要执行:
grant select on employees to user1;
当 PL/SQL
程序 (procedure/function/etc..
) 使用 定义者的权利.
The use of roles in a subprogram depends on whether it executes with
definer rights or invoker rights. Within a definer-rights subprogram,
all roles are disabled.
在 Oracle 文档中找到它 here。
干杯!!
我已经给出了代码和我在尝试创建过程 user1 时收到的错误消息。我尝试在 Oracle XE 18c 的示例 hr 模式中访问员工 table。我能知道如何通过用户定义的过程访问 hr 模式对象吗
CREATE OR REPLACE PROCEDURE proc_1 IS
v_name hr.employees.first_name%TYPE;
v_num NUMBER;
BEGIN
SELECT first_name INTO v_name FROM hr.employees
WHERE employee_id=100;
v_num:=5;
DBMS_OUTPUT.PUT_LINE('test'||v_name);
DBMS_OUTPUT.PUT_LINE(v_num);
END;
/
警告:创建的过程存在编译错误。
SQL> show errors
Errors for PROCEDURE PROC_1:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/8 PL/SQL: Item ignored
2/8 PLS-00201: identifier 'HR.EMPLOYEES' must be declared
5/1 PL/SQL: SQL Statement ignored
5/39 PL/SQL: ORA-00942: table or view does not exist
7/1 PL/SQL: Statement ignored
7/38 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
您需要向用户 user1 授予对 HR 对象的访问权限。
作为用户 HR 连接:
grant select on employees to user1;
你需要直接给hr.employees
table的select grant
。
从HR用户,你需要执行:
grant select on employees to user1;
当 PL/SQL
程序 (procedure/function/etc..
) 使用 定义者的权利.
The use of roles in a subprogram depends on whether it executes with definer rights or invoker rights. Within a definer-rights subprogram, all roles are disabled.
在 Oracle 文档中找到它 here。
干杯!!