Home > Ask the Oracle Database / Applications Experts > Oracle PL/SQL Questions & Answers > Execute SQL statement from table in other schema
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Execute SQL statement from table in other schema

Advice from previous expert, Greg Williams EXPERT RESPONSE FROM: Advice from previous expert, Greg Williams

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 02 April 2007
I want to execute SQL statements that use other schema tables from my stored procedure. The stored procedure is in one schema and the table is in the other schema. I am getting "ORA-01031: insufficient privileges" error. Please suggest how to execute statement from a table from a stored procedure of another user. Both the two users are in the same Oracle instance. The database is Oracle 10g.

>

You have two schemas on the same Oracle instance: schemaA and schemaB. You have a procedure called proc1 in schemaA and you have a table emp on schemaB that you want to read from schemaA. Perform the following two steps:

Step 1: Log onto schemaB. Grant references and select on emp to schemaA as follows:

 grant references, select on emp to schemaA;

Step 2: While logged in as schemaB, create a public synonym as follows:

 create PUBLIC synonym emp for emp;

Now log onto schemaA and create proc1, using emp from schemaB as:

create or replace procedure proc1
as

v_emp_no number;

begin

     select emp_no
     into v_emp_no
     from emp
     where emp_no = 1;

end; 


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Oracle PL/SQL
How to concatenate rows into a single CLOB in PL/SQL
Working with substitution variables and using EXECUTE IMMEDIATE in PL/SQL
How to open a ref cursor in a PL/SQL procedure
Converting Long Raw to Blob
Parsing in Oracle
ORA-01422 error when procedure returns more than one row
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers
Script to revoke access from user
PL/SQL procedure to load CSV file into database table

Oracle and SQL
Oracle tutorial library: SearchOracle.com's learning guides
Can I specify Oracle column order in my database table?
Review: Oracle's 11g R2 database has some good and bad
SELECT statement syntax and examples
Oracle PL/SQL tutorial
PL/SQL datatypes in Oracle
Stored procedures in PL/SQL
PL/SQL functions and triggers in Oracle
Do I need a license for SQL Developer Data Modeler in Oracle?
Using the SQL GROUP BY clause for counting combinations
Oracle and SQL Research

Oracle stored procedures
Stored procedure to autotransfer data between Oracle servers
Insufficient privileges error when creating stored procedure
ORA-01422 error when procedure returns more than one row
Calling procedure inside another procedure in anonymous block
Can I make a second connection to Oracle without losing the first?
How to create an index using a procedure in Oracle
Oracle updates Microsoft developer tools
Procedure compiles but does not execute
Tool in Oracle 10g to keep track of execution of queries
ORA-04082: NEW or OLD references not allowed in table level triggers

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
autonomous transaction  (SearchOracle.com)
CFML  (SearchOracle.com)
dynamic SQL  (SearchOracle.com)
foreign key  (SearchOracle.com)
Java Database Connectivity  (SearchOracle.com)
Open Database Connectivity  (SearchOracle.com)
Oracle  (SearchOracle.com)
stored procedure  (SearchOracle.com)
The Open Group  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts