如何使用来自另一个模式的表编写存储过程? [英] How to write stored procedures using tables from another schema?

查看:47
本文介绍了如何使用来自另一个模式的表编写存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用Oracle的函数和过程是否需要HR用户中的表?当我从另一个用户运行函数时,它给了我一个编译错误.

Is it necessary that table should be in HR user to call function and procedure of Oracle? When I run function from another user, it gives me a compilation error.

对于我的项目,我想从另一个用户运行函数和过程.我该如何实施?

For my project,I want to run the function and procedure from another user. How can I implement it?

推荐答案

要使用另一个模式中的表编写函数或过程,表所有者需要授予我们所需的权限.例如:

To write a function or procedure using a table in another schema the table owner needs to grant us the required privilege. For example:

SQL>  conn hr/hr
SQL>  grant select on employees to mousumi;

或请超级用户为您执行此操作:

or ask a super user to do it for you:

SQL>  conn dba_user/password
SQL>  grant select on hr.employees to mousumi;

权限可以授予角色,但我们不能使用这些权限来创建过程或视图.为此,必须直接授予我们特权.了解详情.

Privileges can be granted to roles but we cannot use those privileges to create procedures or views. For that purpose the privileges must be granted directly to us. Find out more.

当我们引用时,我们需要包含架构名称:

When we reference that we need to include the schema name:

SQL>  select * from hr.employees;

或者,我们可以为它创建一个同义词.

Alternatively we can create a synonym for it.

SQL>  create synonym employee_table for hr.employees;
SQL>  select * from employee_table;

同义词只是一个标签:它可以是我们喜欢的任何东西,只要它在我们的模式中是唯一的(并且符合 Oracle 命名约定).了解详情.

The synonym is just a label: it can be anything we like providing it is unique within our schema (and conforms to Oracle naming conventions). Find out more.

这篇关于如何使用来自另一个模式的表编写存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆