Referencing other schema table in procedure

Hello All,
I am writing a stored procedure and within this i have an update statement which updates a table in my own schema based on
certain condition based on different schema table.
CREATE OR REPLACE PROCEDURE PROC_UPD(P_TBL_NAME VARCHAR2)
IS
V_TBL_NAME VARCHAR2(20) := P_TBL_NAME;
V_SQL_STMT1 VARCHAR2(9999);
BEGIN
V_SQL_STMT1 :=    'UPDATE '||  V_TBL_NAME ||' A '
                           ||'   SET CP   =   (SELECT   CP_I
                                                 FROM  SAM.PROD_TBL
                                                WHERE  A.PROD_I = PROD_I)
                          WHERE A.PROD_I IN ( SELECT PROD_I
                                                FROM SAM.PROD_TBL) ';
EXECUTE IMMEDIATE V_SQL_STMT1 ;
END; When i execute this by passing a table name as a parameter, it gives me an error that "Table or View does not exists".
I can access SAM.PROD_TBL in my schema when i query using SELECT statement.
Also, I can use the same update statement outside the procedure and it works fine without giving me any error.
Is there something i am missing here and hence the error.
Kindly suggest how to overcome this error.
Regards,
Shane

Your privilege on this table needs to have been granted directly to the user not via a role.
In addition, debugging may be made easier by logging or outputting this sql so that you can verify that it's correct and runs correctly via a sql session.

Similar Messages

  • Change schema runtime in procedure

    Hello friends,
    I have one query in procedure. I have same table with same structure and name in more than 10 schema. I want to access these table records dynamically using procedure.
    I want to change schema name in procedure.
    Please check below PL/SQL code i have wrote.
    declare
         cursor c1 IS
         select deptno,dname,loc from &schema..dept;
    begin
         for rec in c1
         loop
              dbms_output.put_line(rec.deptno || ' ' || rec.dname || ' ' || rec.loc);
         end loop;
    end;
    I want same functionality using procedure. Please check procedure code below:
    create or replace procedure diff_schema (schema_name IN varchar2)
    Declare
         cursor c1 IS
         select deptno,dname,loc from schema_name.dept;
    AS
    begin
         for rec in c1
         loop
              dbms_output.put_line(rec.deptno || ' ' || rec.dname || ' ' || rec.loc);
         end loop;
    end;
    but it returns error.
    Please help me to solve this issue.
    Pradip Patel

    BluShadow wrote:
    Venkadesh wrote:
    Agree..
    Hope this work.
    create or replace procedure r_test (p_schema in varchar2)
    is
    v_rc sys_refcursor;
    v_all emp%rowtype;
    begin
    open v_rc for 'select * from '||p_schema||'.emp';
    loop
    fetch v_rc into v_all;
    exit when v_rc%notfound;
    dbms_output.put_line(v_all.ename);
    end loop;
    close v_rc;
    end;
    That still assumes that the emp table exists in the schema in which the procedure is compiled because you have:
    v_all emp%rowtype;Essentially what the OP is asking for indicates that whereve the procedure is defined is going to need to know the structure of the tables it's going to use otherwise everything about it would need to be dynamic.
    We have a process on one of our databases that has a similar setup, where there are several schema's all containing the same table structure, but different data, and we need a central setup of code that can process each of those as required.
    For us we looked at it from a different perspective. Rather than having the central procedure try and access all the other schemas, for which it would need to know which schemas it has to access etc. and because sometimes some of those schemas should be excluded from the process if they have had an issue with their data being populated (it's a regular job to repopulate them and determine changes on them etc. - a bit of an ETL task really), we leave it up to the individual schemas to determine when the processing is necessary (i.e. when they each know their own data is ready to be processed). The advantage of that is that the central procedure's those schemas use all use the AUTHID CURRENT_USER, so the central schema just has a blank copy of the tables so the code can compile, but when the other schemas call the procedure, they are running the code against their own tables because of the AUTHID setting. It avoids any dynamic coding, or any (mis/ab)use of ref cursors, and it gives the flexibility that each schema is in control of it's own destiny, and other schemas can be added or removed as necessary without having to have some central control mechanism to know which schemas need processing.Thank you Blu,i'm learning lot of things from you...you are a champion

  • Schema dependencies on other schema

    Hi all,
    i am refreshing some tables in the schema so before truncating the tables i need check
    any objects dependent from other schema to these truncating tables and is these truncating tables depends on other objects schema
    Inputs appreciated
    Thanks

    Hi
    Thanks for the reply
    i am using the below query to find foreign key constraints on HUSER schema
    select owner, table_name from dba_constraints where constraint_type='R' and owner='HUSER';
    similarly i want to know is any other schema tables depends on HUSER schema how i can query ?
    Thanks

  • Can a procedure select data from tables on other schemas?

    Can a procedure select data from tables on other schemas?
    If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?

    Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
    Now , as regards the syntax....
    1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
    2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
    3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
    Regards,
    Simon

  • How to get the own schema data while calling the other schema's Procedure

    Hello Experts,
    I'm Sanjit, new to OTN forum.
    I'm using Oracle 10g 10.1.0.2.0 database. Another user Sush has created one procedure proc_1 like
    create or replace procedure proc_1
    as
    v_total number;
    begin
    select sum(amt) into v_total from trans_master where dot
    between add_months(sysdate,-3) and sysdate;
    dbms_output.put_line('last three months total transactions is: '||v_total);
    end proc_1;
    He has the Trans_master table and having 280 records and I have the same Trans_master table with 430 records
    inserted in last 3 months. He has granted execute privileges on the procedure Proc_1 to me. When I call the procedure
    I cannot call it directly like my own schema procedures: Exec Proc1;
    I am calling like : Exec Sush.Proc1 to get the result. My issue is: when the procedure is called,
    it is accessing the data from the Sush schema Trans_master table with 280 records total, but I want
    the procedure to get the total amount of transaction of 430 records from my own Trans_master table.
    Please resolve my issue which would be a great help. And is there any way to call the procedure of other schema
    by not attaching the owner name of the object with it?
    Thanks
    Sanjit

    Pleast take a look at "Definer's rights and invoker's rights" in the following article:
    http://docs.oracle.com/cd/E11882_01/timesten.112/e21639/accesscntl.htm#BABDDCHC
    I guess you need to define a stored procedure with "invoker's rights".
    If this is what you are looking for will have to define it in the stored procedure that you are going to call.
    The syntax is as follows:
    create or replace procedure <yourprocedure> authid current_user ...
    ...or (the following is the default, you don't have to use the "authid definer" keywords):
    create or replace procedure <yourprocedure> authid definer ...
    ...hm

  • Privilege for truncating a table of other schema

    Hi friends
    I need to truncate a table of other schema. What privilege the other user has to give to carry out it.
    Thanks
    Edited by: user12892846 on 01-abr-2010 15:59

    DROP ANY TABLEWhile technically correct, above is somewhat dangerous because every schema could be impacted; even SYS.
    Assume SCHEMA_A owns TABLE_A & procedure below.
    CREATE & REPLACE PROCEDURE TRUNCATE_TABLE_A
    AS
    BEGIN
    EXECUTE IMMEDIATE 'TRUNCATE TABLE TABLE_A';
    END TRUNCATE_TABLE_A;
    GRANT EXECUTE ON TRUNCATE_TABLE_A TO SCHEMA_B;
    By doing as above SCHEMA_A can control who & which table(s) can be impacted (in is own schema only).
    Edited by: sb92075 on Apr 1, 2010 7:06 PM

  • Export schema table structure only- no procedures

    Hi Friends,
    I try to export a schema structure with rows=n option in exp command. As log records show the procedures had exported too.
    Do we have any way to export a schema tables only?
    Thanks for help!
    Jin

    user589812 wrote:
    Database is 10.2.04 I are not able to use data pump based on system configuration.Please elaborate on what you mean by "I are not able to use data pump based on system configuration"
    We have more one hundred tables. that needs to be include tables option.
    Do you have any simple way to export a schema tables structure without list 120 table's name in exp command?
    Edited by: user589812 on Jan 4, 2012 10:19 AMI do not believe you have a choice. One method could be to get a list of all needed tables (SELECT TABLE_NAME FROM USER_TABLES) and create a par file with this list.
    HTH
    Srini

  • EXPORT SCHEMA 'S ALL TABLES AND PROCEDURES BY EXPDP

    how i can export schema's all tables and procedures using expdp.
    when i am giving expdp usr/pass schemas=scott directory=export_dir dumpfile=280606.DMP logfile=280606.log tables=*
    but it is giving error.
    pls help
    regards
    Prabhaker

    You only need to specify parameter USER or TABLES , no need of both
    specify USER=SCOTT then it will export all objects in SCOTT

  • How can we copy table from one schema to other schema

    Hi,
    I have create one table in one schema and i want to copy it to other schema.How we can copy table from one schema to other schema

    Hi,
    You can try something like this :-
    SQL> CONNECT SYS/SYS123@SERVER AS SYSDBA
    Connected.
    SQL> CREATE USER TEST_1 IDENTIFIED BY TEST_1;
    User created.
    SQL> CREATE USER TEST_2 IDENTIFIED BY TEST_2;
    User created.
    SQL> GRANT CONNECT,RESOURCE,DBA TO TEST_1;
    Grant succeeded.
    SQL> GRANT CONNECT,RESOURCE,DBA TO TEST_2;
    Grant succeeded.
    SQL> CONNECT TEST_1/TEST_1@SERVER
    Connected.
    SQL> CREATE TABLE TEST_COPY ( TEST_COL NUMBER );
    Table created.
    SQL> INSERT INTO TEST_COPY VALUES ( 1 );
    1 row created.
    SQL> INSERT INTO TEST_COPY VALUES ( 2 );
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> GRANT ALL ON TEST_COPY TO TEST_2;
    Grant succeeded.
    SQL>  CONNECT TEST_2/TEST_2@SERVER
    Connected.
    SQL> CREATE TABLE TEST_COPY AS SELECT * FROM TEST_1.TEST_COPY;
    Table created.
    SQL>  SELECT * FROM TEST_COPY;
      TEST_COL
             1
             2Regards,
    Sandeep

  • How to move one table to other schema

    Hi;
    imagine i have one schema A and i create table in this schema as test. Now i have one other schema,name is B. I wanna move my A.test table to B.test2
    How i can do it?
    thanks

    Following discussion might help How to move the table to the another schema?

  • Select from a table from other schema

    Hi,
    I want to make a select from a table how is into other Schema and into other instance.
    form example, if I have _2 schemas (in diferent instances)_:
    SCHEMA1 =
    *(DESCRIPTION =*
    *(ADDRESS =*
    *(PROTOCOL = TCP)*
    *(HOST = XXX.XXX.XXX.XX1)*
    *(PORT = 1560)*
    *(CONNECT_DATA =*
    *(SERVER = DEDICATED)*
    *(SERVICE_NAME = SCHEMA1)*
    SCHEMA2 =
    *(DESCRIPTION =*
    *(ADDRESS =*
    *(PROTOCOL = TCP)*
    *(HOST = XXX.XXX.XXX.XX2)*
    *(PORT = 1560)*
    *(CONNECT_DATA =*
    *(SERVER = DEDICATED)*
    *(SERVICE_NAME = SCHEMA2)*
    and into SCHEMA2 there is a table TABLE_A.
    If I`m connected into SCHEMA1:
    how can I do to make a select from the TABLE_A?
    thanks very much.

    1) Referring to an entry in the tnsnames.ora file as a "schema" as you have here with schema1 and schema2 is likely to be confusing. You have multiple schemas in the same database-- in this case, you appear to be trying to query tables in a different database. If we try to answer using your TNS aliases "schema1" and "schema2", there is likely to be a great deal of confusion between schemas/ databases/ and TNS aliases. So I will assume that your tnsnames.ora file actually reads
    TNS_ALIAS1 =
      (DESCRIPTION =
        (ADDRESS =
          (PROTOCOL = TCP)
          (HOST = HOST1)
          (PORT = 1560)
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = DB1)
    TNS_ALIAS2 =
      (DESCRIPTION =
        (ADDRESS =
          (PROTOCOL = TCP)
          (HOST = HOST2)
          (PORT = 1560)
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = DB2)
    )2) Given the TNS aliases above, assuming that we are talking about the tnsnames.ora file on HOST1, you would need to create a database link from DB1 to DB2. You can either specify a fixed username and password for the database link or you can specify that the connection happens as the current user (which assumes that the passwords are synchronized between the databases).
    CREATE DATABASE LINK to_db2
      CONNECT TO username_on_db2
      IDENTIFIED BY password_on_db2
      USING 'TNS_ALIAS2'3) Assuming the database link is in place
    SELECT *
      FROM schema2.table_name@to_db2Justin

  • Import a schema (tables, Views, Stored Procedures) on logical standby

    Hi,
    We have a logical standby for reporting purpose. The logical standby build through data guard
    we need to import a new user in logical standby using import utility. The user dump contain tables, views, procedures, packages, roles).
    The new user import has to go in users tablespace.
    Is is possbile to import a new user in logical standby and what are the steps.
    Thanks in advance

    Hi,
    Can you give me more details about your envirnoment configuration, O/S, DB version.
    But generally i don't think that is this possible becuase as you know standby only for cloning the primary database, so you can import it on the production then it will be transfered to the logical standby database.
    Regards;

  • Access other schema's table without specify the schema name

    Hi, need ur help again,
    I would like to access other schema's table without specify the schema name. for example,
    select * from hr.jobs;
    What priviledges i need if i want to select the data in this way:
    select * from jobs;
    Thanks!

    Public synonyms have their place, but are not generally a good idea as they will cause conflicts with other schemas and applications. Another think that you can do is issue the
    ALTER SESSION set CURRENT_SCHEMA = schema;
    The CURRENT_SCHEMA (8i and above) parameter changes the current schema of the session to the specified schema. Subsequent nqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement. CURRENT_SCHEMA is a session parameter only, not an initialization parameter.
    This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.

  • Restricting SYS user to View other schema's Tables

    Hi All,
    Oracle DB Version - 10R2
    O/S - UNIX
    Could anyone share docs or steps to prevent SYS user to view other schema's tables;
    Thanks,
    Deepak

    Dear Deepak_DBA,
    If you revoke every privilege and role from the SYS user i presume the SYS will continue to select any table from the relevant schema. SYS is a special user and not like the others.
    For instance if you want to revoke the SYSDBA and the SYSOPER from the SYS user;
    SQL> revoke sysdba, sysoper from sys;
    revoke sysdba, sysoper from sys
    ERROR at line 1:
    ORA-01998: REVOKE failed: user SYS always has SYSOPER and SYSDBAI have never seen such documentation that describes how to revoke everything or at least the SELECT ANY TABLE privilege from the SYS user.
    Please see more about the SYS and the SYSTEM users;
    SYS and SYSTEM Users;
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10897/users_secure.htm#ADMQS12003
    Regards.
    Ogan

  • How can I to rename Table in Other Scheme ?

    I some tables area backup, but all are in other scheme , How can I to rename all ?
    SQL> rename SYSADM.PS_LOC_CNTRCT_SN   to SYSADM.PS_LOC_CNTRCT_SN_999;
    rename SYSADM.PS_LOC_CNTRCT_SN   to SYSADM.PS_LOC_CNTRCT_SN_999
    ORA-01765: specifying table's owner name is not allowed

    @pmcda Look up prerequisites for RENAME
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9019.htm#i2064929
    SQL> show user
    USER is "SYSTEM"
    SQL> alter table scott.dept rename to department;
    Table altered.
    SQL> select * from scott.department;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> alter table scott.department rename to dept;Best regards
    Maxim

Maybe you are looking for

  • IChat fails to connect in a user's profile

    Someone in my office uses iChat to connect with AIM. We have verified the password and server settings as correct, but the program stalls with the message connecting. I am able to connect to her AIM account using iChat under a different user's login

  • JComboBox makes for nice security vulnerability under X11?

    I noticed a couple years ago that when I set a breakpoint inside a JComboBox state change event handler on a Java application or applet running under X11, the entire desktop would hang. Back then, I checked the Swing bug database and found an issue r

  • Using the invoke node VI Strings.Im​port

    I'm achieving a program to translate the captions which are on the front panels of existing programs.  I use the invoke node VI String.Export to create a file containing the differents properties of the front panel objects of the target VI.  I modify

  • Microsoft Windows Services for UNIX 3.5  - unable to sqlplus

    Hi, I have installed - Microsoft Windows Services for UNIX 3.5 on my pc running XP 2002 Service Pack2 Unable to run sqlplus : Error 6 initializing SQL*Plus Message file sp1<lang>.msb not found SP2-0750: You may need to set ORACLE_HOME to your Oracle

  • Formatting every second rows in Reports??

    Hi!Would like to add a shadow to every second row in Hyperion Reports. Cannot find a good solution to this since I'm using dynamic rows i.e. Children of xxxx.Does anybody have a good tip och trick on how to solve this.Thank you in advance,Erik