Schema name as Parameter

Hi,
I have a requirement where i need to pass the schema names during run time for a cursor.
Is there any way I can do it for an existing cursor?
For example, the idea is to pass the schema name as a parameter as mentioned below.we have set of programs which are written already and the current requreiments is to change the schema name alone as a parameter.
Please advice.
Example:
CREATE OR REPLACE PROCEDURE proc_TEST (SRC_SCH VARCHAR2)
IS
CURSOR c_Account(SRC_SCH VARCHAR2) IS
SELECT *
FROM &SRC_SCH.T2ACCOUNTS;
fl_Success Boolean;
BEGIN
END proc_TEST;

You need to use dynamic SQL.
SQL> conn thomas2/thomas@ora9204
Connected.
SQL> create table test(id number);
&nbsp
Table created.
&nbsp
SQL> insert into test values(2);
&nbsp
1 row created.
&nbsp
SQL> grant select on test to scott;
&nbsp
Grant succeeded.
&nbsp
SQL> conn thomas1/thomas@ora9204
Connected.
SQL> create table test(id number);
&nbsp
Table created.
&nbsp
SQL> insert into test values(1);
&nbsp
1 row created.
&nbsp
SQL> grant select on test to scott;
&nbsp
Grant succeeded.
&nbsp
SQL> conn scott/tiger@ora9204
Connected.
SQL> create or replace procedure get_id(sch varchar2)
  2  is
  3   id number;
  4   cur sys_refcursor;
  5  begin
  6   open cur for 'select id from ' || sch || '.test';
  7   loop
  8    fetch cur into id;
  9    exit when cur%notfound;
10    dbms_output.put_line(id);
11   end loop;
12   close cur;
13  end;
14  /
&nbsp
Procedure created.
&nbsp
SQL> set serveroutput on
SQL> exec get_id('thomas1');
1
&nbsp
PL/SQL procedure successfully completed.
&nbsp
SQL> exec get_id('thomas2');
2
&nbsp
PL/SQL procedure successfully completed.
&nbspRgds.

Similar Messages

  • How to get the current schema name

    Hi,
    Can anybody please tell me how to get the current schema name, there is some inbuilt function for this,but i am not getting that. Please help me.
    Thanks
    Jogesh

    ok folks, I found the answer at Tom's as usual.
    http://asktom.oracle.com/tkyte/who_called_me/index.html
    I rewrote it into a function for kicks. just pass the results of DBMS_UTILITY.FORMAT_CALL_STACK to this function and you will get back the owner of the code making the call as well some extra goodies like the name of the code and the type of code depending on the parameter. This ignores the AUTHID CURRENT_USER issues which muddles the schemaid. Quick question, does the average user always have access to DBMS_UTILITY.FORMAT_CALL_STACK or does this get locked down on some systems?
    cheers,
    paul
    create or replace
    FUNCTION SELF_EXAM (
       p_call_stack VARCHAR2,
       p_type VARCHAR2 DEFAULT 'SCHEMA'
    ) RETURN VARCHAR2
    AS
       str_stack   VARCHAR2(4000);
       int_n       PLS_INTEGER;
       str_line    VARCHAR2(255);
       found_stack BOOLEAN DEFAULT FALSE;
       int_cnt     PLS_INTEGER := 0;
       str_caller  VARCHAR2(30);
       str_name    VARCHAR2(30);
       str_owner   VARCHAR2(30);
       str_type    VARCHAR2(30);
    BEGIN
       str_stack := p_call_stack;
       -- Loop through each line of the call stack
       LOOP
         int_n := INSTR( str_stack, chr(10) );
         EXIT WHEN int_cnt = 3 OR int_n IS NULL OR int_n = 0;
         -- get the line
         str_line := SUBSTR( str_stack, 1, int_n - 1 );
         -- remove the line from the stack str
         str_stack := substr( str_stack, int_n + 1 );
         IF NOT found_stack
         THEN
            IF str_line like '%handle%number%name%'
            THEN
               found_stack := TRUE;
            END IF;
         ELSE
            int_cnt := int_cnt + 1;
             -- cnt = 1 is ME
             -- cnt = 2 is MY Caller
             -- cnt = 3 is Their Caller
             IF int_cnt = 1
             THEN
                str_line := SUBSTR( str_line, 22 );
                dbms_output.put_line('->' || str_line);
                IF str_line LIKE 'pr%'
                THEN
                   int_n := LENGTH('procedure ');
                ELSIF str_line LIKE 'fun%'
                THEN
                   int_n := LENGTH('function ');
                ELSIF str_line LIKE 'package body%'
                THEN
                   int_n := LENGTH('package body ');
                ELSIF str_line LIKE 'pack%'
                THEN
                   int_n := LENGTH('package ');
                ELSIF str_line LIKE 'anonymous%'
                THEN
                   int_n := LENGTH('anonymous block ');
                ELSE
                   int_n := null;
                END IF;
                IF int_n IS NOT NULL
                THEN
                   str_type := LTRIM(RTRIM(UPPER(SUBSTR( str_line, 1, int_n - 1 ))));
                 ELSE
                   str_type := 'TRIGGER';
                 END IF;
                 str_line  := SUBSTR( str_line, NVL(int_n,1) );
                 int_n     := INSTR( str_line, '.' );
                 str_owner := LTRIM(RTRIM(SUBSTR( str_line, 1, int_n - 1 )));
                 str_name  := LTRIM(RTRIM(SUBSTR( str_line, int_n + 1 )));
              END IF;
           END IF;
       END LOOP;
       IF UPPER(p_type) = 'NAME'
       THEN
          RETURN str_name;
       ELSIF UPPER(p_type) = 'SCHEMA.NAME'
       OR    UPPER(p_type) = 'OWNER.NAME'
       THEN
          RETURN str_owner || '.' || str_name;
       ELSIF UPPER(p_type) = 'TYPE'
       THEN
          RETURN str_type;
       ELSE
          RETURN str_owner;
       END IF;
    END SELF_EXAM;

  • Using dbms_datapump package to export the schema with the schema name as pa

    Hi,
    I am using the pl/sql block to export schema using dbms_datapump package,Now I want to pass the scheme name as the parameter to the procedure and get the .dmp and .log files with the schema name included.
    CREATE OR REPLACE PROCEDURE export
    IS
    h1 number;
    begin
    h1 := dbms_datapump.open (operation => 'EXPORT', job_mode => 'SCHEMA', job_name => 'export1', version => 'COMPATIBLE');
    dbms_datapump.set_parallel(handle => h1, degree => 1);
    dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG', directory => 'DATA_PUMP_DIR', filetype => 3);
    dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
    dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''CHECKOUT'')');
    dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value => 'BLOCKS');
    dbms_datapump.add_file(handle => h1, filename => 'EXPDAT%U' || to_char(sysdate,'dd-mm-yyyy') || '.DMP', directory => 'DATA_PUMP_DIR', filetype => 1);
    dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
    dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
    dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
    dbms_datapump.detach (handle => h1);
    exception
    when others then
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    end;
    Thank you in advanced
    Sri

    user12062360 wrote:
    Hi,
    I am using the pl/sql block to export schema using dbms_datapump package,Now I want to pass the scheme name as the parameter to the procedure and get the .dmp and .log files with the schema name included.
    OK, please proceed to do so
    >
    CREATE OR REPLACE PROCEDURE export
    IS
    h1 number;
    begin
    h1 := dbms_datapump.open (operation => 'EXPORT', job_mode => 'SCHEMA', job_name => 'export1', version => 'COMPATIBLE');
    dbms_datapump.set_parallel(handle => h1, degree => 1);
    dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG', directory => 'DATA_PUMP_DIR', filetype => 3);
    dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
    dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''CHECKOUT'')');
    dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value => 'BLOCKS');
    dbms_datapump.add_file(handle => h1, filename => 'EXPDAT%U' || to_char(sysdate,'dd-mm-yyyy') || '.DMP', directory => 'DATA_PUMP_DIR', filetype => 1);
    dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
    dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
    dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
    dbms_datapump.detach (handle => h1);
    exception
    when others then
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    end;
    EXCEPTION handler is a bug waiting to happen.
    eliminate it entirely

  • What is table schema name?

    Hi,
    I was looking at DatabaseMetaData::getColumns() while searching for a way to get a table's column names and I run into these ugly params catalog and schemaPattern. Of course nowhere on the sun's site could I find a definition of these terms although they're used quite often in the API documentation. So I turned to a specific DBMS provider and found out that catalog is a fancy term for the system metadata. But what about the String schema param? I usually see a table's schema referred to as the "structure" of the table, what columns it contains of which types. But I've never known this "schema" can have a string name. Anyone so kind to explain it to me or better point me to a text that has definitions and explanations of the concepts used in the JDBC API documentation? And more generally for JDK where do you folks usually go when you want a simple explanation of how things work, not the dry listing of function and parameter names? Look at MSDN for example, it is both a good reference and a reasonable self-contained tutorial. Not that I praise Microsoft but...
    BTW I found that probably ResultSetMetaData is more suitable for my initial purposes, but still the questions bother me. So if you have any suggestion please let me know.
    Thank you in advance

    To answer your question, what is a table schema name?, it is the name of the schema that the table belongs to. If you have an Oracle database, MYDB, it will have at the very least two users which are SYS and SYSTEM, these are schema names, there are objects that exists in their schema. If you create a new user, JAKE, and then create a bunch of objects as JAKE, these objects are said to belong to the JAKE schema. All objects are like this, not just tables (indexes, sequence tables, triggers, etc.).

  • Default schema names in multi-tier landscape

    Hi folks,
    We have an interesting problem due to having different named default schemas in each of our 3 hana systems.  For example lets say these are our default schemas in our development, staging, and production HANA systems;
    DEV_SCHEMA
    QA_SCHEMA
    PROD_SCHEMA
    Each of these replicating data from their corresponding SAP source systems.
    Now, we have a view that is developed on DEV hana box and uses DEV_SCHEMA.  When this view content is imported to QA or PROD we handle easily with schema mapping.  All is well and good although we are not really a fan of this different naming and us developers did not choose this naming (self defense plea here for us brilliant developers whom never make such mistakes... PS: HI LARS! - Go Germany!)
    Now we are setting up a connection from BW into HANA using system connection and inside this is a parameter called 'db user'.  Although it's called db user it's actually looking for a SCHEMA name.  If BW DEV is querying from HANA DEV this schema name would be DEV_SCHEMA.  However if BW_QA is querying from HANA_QA then the name would need to be QA_SCHEMA but in our BW landscape we are locked in QA and PROD and normally can not and/or do not want to edit objects in non-native systems.  Ideally what we need is our default schemas in HANA to have the same exact name throughout the HANA landscape.
    All this said, I can see that it would be great to re-name our entire HANA landscape however that would be a HUGE monumental undertaking as all systems would need to be re-replicated again (at least I think).
    Just curious if anybody else has named their schemas differently on each tier?  What are most people doing?  Naming the default schemas the same consistently or are you using schema mapping?
    Thanks,
    -Patrick

    Hi Luke,
    I am new to the project and there seems to be no original version.  At some point a bunch of the destination field names were changed on the admin console and errors resulted from it both due to mismatched joins and the use of two word field names.  I have documentation of the names for the set of tables in the function area but am having trouble with how everything matches up in the bottom half..  I'll keep working on it
    Z

  • Schema name in DB Adapter

    Hi,
    Schema name is hardcoded in the DB adpater even if I am not selecting the schema name while creation.
    <jca:operation
    SchemaName="APPS"
    PackageName="XX_PKG"
    ProcedureName="POPULATE_DATA"
    InteractionSpec="oracle.tip.adapter.db.DBStoredProcedureInteractionSpec" >
    How do I make it generic? Can I remove SchemaName parameter?
    My JNDI Url may change dynamically and the target database may have different schemas.
    Thanks,
    Rishi

    The adapter uses the schema name to qualify the stored procedure invocation (e.g. "APPS.XX_PKG.POPULATE_DATA"). Having the schema name means that you can invoke a stored procedure in a schema other than the one associated with your connection. If you remove the schema name then the qualified execution will be "XX_PKG.POPULATE_DATA" and the schema will be your connection schema. So be careful about removing the schema name because the stored procedure qualified by package name alone may not be enough to resolve it for execution. In other words, the package containing your stored procedure may not exist in the schema associated with your connection.

  • How to programatically change schema name for an application ? JDev10g

    I am using JDeveloper 10g 10.1.3.4
    What I am trying to do is: while connecting to the database instace with login/passwd credentials for a specific schema, being able to take in
    schema as a separate paramter and connect to that schema.
    Connecting to a database instace ORCL to the hr schema say with hr/hr
    supply a paramter schema_name: scott. and connect to the scott schema as the hr schema user.
    In SQL Plus* all you do is
    connect as hr/hr
    and then
    alter session set current_schema = scott.
    While developing an application that autheticates against database username/pwd credentials I was using the methodology
    as described on http://www.oracle.com/technology/products/jdev/howtos/10g/dynamicjdbchowto.html
    and http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.htmlexample 14.*[Dynamic JDBC Credentials for Model 1 and Model 2|http://otn.oracle.com/products/jdev/tips/muench/dynamiccredentials/DynamicCredentials1013.zip]* [10.1.3.3] 2006, Upd: 17-MAY-2007 by Steve Muench
    In the DynamicJDBCBindingFilter that in the doFilter() method, I was trying to find a way to be able to specify the schema name
    as in sessoion.setAttribute(Configuration.&lt;SomeProperty&gt;, schema);
    is there any property/parameter that can be set to change the schema within the context of the application?
    because in all the code that i see there are attributes of 'Configuration' that are being set.
    So I don't think there is way for me to just write straight up jdbc code to
    create a connection and run the statement "alter session set current_schema = scott"
    and be able to pass the login credentials
    and connect to the schema I want to.
    Any help would be appreciated.

    Hi,
    I am not sure if JDBC really supports this. I found
    JDBC alter session set ...
    but this never got a success/failure statement.
    If you want to use a singe connection but different schema for users then you may want to have a look at proxy user authentication, which is exatly doing what you want - use a single user to get into the database and then have him mapped to his own schema to work in
    Frank

  • How to call a schema name using substitution name?

    Hi All,
    How to call a schema name using substitution menthod in odi?
    I was trying but I got the following error..
    ODI-1227: Task XXX(Procedure) fails on the source ORACLE connection YYY.
    Caused By: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
    Here xxx procedurename.
    yyy-schemaname
    Please do the needful..
    Thanking you in Advance.
    Regards,
    PP

      1  declare
      2  sql_string varchar2(2000);
      3  begin
      4  sql_string := 'select ' || func_name || ' into a from dual ';
      5  execute immediate sql_string;
      6* end;
    SQL> /
    sql_string := 'select ' || func_name || ' into a from dual ';
    ERROR at line 4:
    ORA-06550: line 4, column 28:
    PLS-00201: identifier 'FUNC_NAME' must be declared
    ORA-06550: line 4, column 1:
    PL/SQL: Statement ignored
      1  declare
      2  sql_string varchar2(2000);
      3  func_name varchar2(30);
      4  begin
      5  func_name := 'some_func';
      6  sql_string := 'select ' || func_name || ' into a from dual ';
      7  execute immediate sql_string;
      8* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-00904: "SOME_FUNC": invalid identifier
    ORA-06512: at line 7
    SQL> desc some_func;
    ERROR:
    ORA-04043: object some_func does not exist
      1  create or replace function test_func
      2       return number
      3       is
      4       begin
      5          return 0;
      6*      end;
    SQL> /
    Function created.
      1  declare
      2  sql_string varchar2(2000);
      3  func_name varchar2(30);
      4  begin
      5  func_name := 'test_func';
      6  sql_string := 'select ' || func_name || ' into a from dual ';
      7  execute immediate sql_string;
      8* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-00905: missing keyword
    ORA-06512: at line 7
    SQL> Set serveroutput on
      1   declare
      2   sql_string varchar2(2000);
      3   func_name varchar2(30);
      4   return_value number;
      5   begin
      6   func_name := 'test_func';
      7   sql_string := 'select ' || func_name || ' from dual ';
      8   execute immediate sql_string into return_value;
      9   dbms_output.put_line(return_value);
    10* end;
    SQL> /
    0
    PL/SQL procedure successfully completed.Hope that helps.
    Regards
    Raj

  • Dynamic prefix of schema name in PL/SQL objects

    I have a requirement where schema name would be passed as a parameter to the procedure and I am supposed to write some DML statements on some of the fixed tables. The table names are common among any schemas, but then only the schema names change.
    This weird requirment is because, here they do not maintain same names for schemas on DEV,QA,UAT and PROD databases, and I can not change that. My thoughts are that it can be acheived only using Dynamic SQL. I want to know whether any alternate ways exist since this is going to be the case on various packages and procedures. For example I have a package with around 80 procedures in it which have couple of DML statements in it. Now they want to pass the schema name to main procedure and want the 80 procedures to perform the DML on the schema name passed :)
    So, should I change all the 80 procedures and make all the DML in it to Dynamic SQL (I am afraid I might end up doing that)? Please not that I can not change all the environments to same schema names (Not in my hands)
    Please suggest.

    You can make use of this inside you programs. We do this.
    You can prefix the value before the object names.
    When the procedure can run from same user who has privs on other schemas.
    Just set the current_schema to HR , SCOTT or others.
    You will not need to Pass Parameters for each procedure.
    Current User can be same as the procedure run from or owner of the procedure.
    SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
    SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
    SCOTT
    SQL> alter session set current_schema=hr;
    Session altered.
    SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
    SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
    HR
    SQL> alter session set current_schema=scott
    Session altered.
    SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
    SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
    SCOTTSS

  • 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.

  • DatabaseProcedure with return type prefixed with schema name

    Hi (Paco)
    I have a question about the DatabaseProcedure class. We are using Oracle proxy users for our database connections.
    Everything is accessed via a database role that are granted to the logged on user. All our database objects, tables etc are protected with this database role.
    When I want to call a database function/procedure I need to add the schema name as a prefix to the custom database object that we uses for parameters/return types.
    So far so good. I can also define a parameter prefixed with schema name via the DatabaseProcedure.registerArrayType ...
    But when I try to define a function call that uses this parameter I get an error saying "Declaration is not valid".
    The problem is located to the PROCEDURE_DEFINITION regular pattern:
    private static final Pattern PROCEDURE_DEFINITION = Pattern.compile("\\s* (FUNCTION|PROCEDURE) \\s+ ([\\w.$]+) \\s* (?:\\((.*?)\\))? \\s* (?:RETURN\\s+(\\w+))? \\s* ;? \\s*", CASE_INSENSITIVE | COMMENTS | DOTALL); The return type cannot be prefixed with the schema name.
    Any good suggestions or workarounds?!
    I actually did change the pattern runtime via reflection to make it work - but I really don't like this solution in the long run!
    /Torben
    Edited by: Zonic on 2013-05-07 10:52

    Hi Torben,
    I think I have a workaround for the issue that might work for you. If you look at the source of <font face="courier">DatabaseProcedure.registerArrayType</font> you find that it actually calls <font face="courier">DatabaseProcedure.registerCustomParamType</font>.
    public static void registerArrayType(String name)
      registerCustomParamType(name, Types.ARRAY, Array.getORADataFactory(), name);
    }As a workaround you could replace your calls to <font face="courier">DatabaseProcedure.registerArrayType</font> with calls to <font face="courier">DatabaseProcedure.registerCustomParamType</font> as follows.
    // Instead of DatabaseProcedure.registerArrayType("NAME.WITH.DOTS") call:
    DatabaseProcedure.registerCustomParamType("anyNameWithoutDots", Types.ARRAY, Array.getORADataFactory(), "NAME.WITH.DOTS"); // Don't forget to use uppercase here.
    DatabaseProcedure dp = DatabaseProcedure.define("procedure my.procedure(param1 in out anyNameWithoutDots)");
    DatabaseProcedure.ParamType type = dp.getParamDef(0).getType();
    System.out.println(type.getName() + " is " + type.getTypeName()); // ANYNAMEWITHOUTDOTS is NAME.WITH.DOTSThis way you don't have to use the "illegal" name in the DatabaseProcedure definition.
    Regards,
    Paco van der Linden

  • Passing a Schema Name to a Procedure

    Hi,
    I'm hoping there's a really simple answer to this...
    We have an Oracle database containing many schemata, all customer schemata are identical but hold different data pertaining to each customer.
    We also have a 'reporting' schema which has select privileges on all the other schemata.
    In this reporting schema we have various ref cursor returning procedures, and we use dot notation to reference the required schema - E.g. 'select * from SCHEMA1.Customers'.
    What I'd like to do is pass a schema name as a parameter to a procedure so the one procedure could cover all schemata. - E.g. call p_GetCustomers('SchemaNameParameter'). The procedure would then return the customer data for a given schema.
    All I've come up with (thus far) is using EXECUTE IMMEDIATE.
    E.g. (very simplified)
    create or replace procedure p_GetCustomers(pSchema in varchar2) as
    vExecuteString varchar2(100);
    begin
    vExecuteString := 'select * from '|| pSchema ||'.ICustomers';
    execute immediate vExecuteString ;
    end;
    This does the job in extremely simple procedures/functions, but we have some heavy-duty procedures that would make it extremely hard to do the concatenation as they mention the schema all over the place.
    What I'd ideally like is something like...
    create or replace procedure p_GetCustomers(pSchema in varchar2) as
    begin
    select * from pSchema.Customers;
    end;
    But the above won't compile (table or view does not exist...).
    I'd be extremely grateful if somebody could advise on this...
    Thanking you in advance (and hope!)...
    Mike
    Oracle 10.g - Windows - Oracle SQL Developer 1.1.2

    The owner of the procedure needs to have the ALTER SESSION system privilege granted directly to them, but that is all. The SET CURRENT_SCHEMA <name> just defines the namespace to look in, it does not make you that user. The reporting user (presumably the procedure owner) still needs to have SELECT privileges on all of the tables.
    SQL> show user
    USER is "OPS$ORACLE"
    SQL> CREATE USER a IDENTIFIED BY a;
    User created.
    SQL> GRANT CREATE SESSION, ALTER SESSION to a;
    Grant succeeded.
    SQL> CREATE TABLE t (id NUMBER, descr VARCHAR2(10));
    Table created.
    SQL> INSERT INTO t VALUES (1, 'OP$ORACLE');
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> GRANT SELECT ON t TO a;
    Grant succeeded.
    SQL> connect mpprod/********
    Connected.
    SQL> CREATE TABLE t (id NUMBER, descr VARCHAR2(10));
    Table created.
    SQL> INSERT INTO t VALUES (1, 'MPPROD');
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> GRANT SELECT ON t TO a;
    Grant succeeded.
    SQL> connect a/a
    Connected.
    SQL> ALTER SESSION SET CURRENT_SCHEMA = ops$oracle;
    Session altered.
    SQL> SELECT * FROM t;
            ID DESCR
             1 OP$ORACLE
    SQL> ALTER SESSION SET CURRENT_SCHEMA = mpprod;
    Session altered.
    SQL> SELECT * FROM t;
            ID DESCR
             1 MPPRODJohn

  • How to prefix schema name to a called procedure?

    Hi,
    I have five different schemas and each and every schema has the same procedures and same set of tables.
    In calling procedure, there is one IN parameter which is schema name. In this procedure I am calling another procedure. In this scenario how to prefix schema name parameter to the called procedure?
    Urgent please.
    Thank you.

    Make use of Package constants:
    [list]
    [*]Create a package specification in each schema called REGION.
    [*]Create a Package specification constant CURRENT_SCHEMA string literal equal the owner of the REGION package.
    [*]This very very simple package (with no body) will be different in each of your five schemas. You must not transport this package between schemas.
    [*]For the procedures you are calling, redefine the argument of schema_name with a DEFAULT REGION.CURRENT_SCHEMA value. This should give you what you are looking to do - making all the procedure code (except for the REGION package spec) portable between the schema.
    [list]

  • Passing schema name at runtime in batch file

    I am having a batch file where i am prompting users to tell the schema name to which they wish to connect at runtime. I am calling one .sql fil within that batch file to execute where i need user to connect to the specific schema at runtime
    My batch file looks like as
    set serveroutput on;
    set linesize 500;
    set scan on;
    spool test_bat.log
    Accept a PROMPT 'Enter the schema name you wish to connect: '
    Accept a_pw PROMPT 'Enter the password?: ' HIDE
    Accept a_connstr PROMPT 'Enter the connect string : '
    conn &a/&a_pw@&a_connstr
    Now after getting connected to the specified schema i would like to call some .sql file within the batch file which seems to be as
    select count(*) from <schema entered above>.table_name
    I want to use the above schema name (a) to get data from the tables.
    Please let me know how to get this.
    Thanks

    user11200661 wrote:
    That's fine but still i want to prefix the schema name within the .sql file. My .sql should contain the name of that parameter only as i want to get that parameter replaced by the schema name at runtime. Some other users are using the same .sql file and they have access to that specific schema only. i want to make the .sql file more general so that it can be used by everyone without altering it every time.Sorry, your requirement no longer makes sense.
    If people have to access a specific schema because they need the script for general use, then you will have to hard code the schema name into it.
    If the script is to prompt for the schema name and connect to that schema and then use that schema name inside the called sql script, then people would not be able to use it generically, as it would be reliant upon the schema name being passed in.
    It sounds as if you're trying to write one generic thing that needs to do two different tasks.
    Just have two scripts and make life simple.

  • Can we use Column Names in Parameter Cursor

    Hi
    can we use Column Names in Parameter Cursor??
    DECLARE
    CURSOR Emp_Cur (P_Deptno NUMBER)
    IS
    SELECT Empno, Ename
    FROM Emp
    WHERE Deptno = P_Deptno;
    BEGIN
    FOR Emp IN Emp_Cur(10)
    LOOP
    DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
    DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
    END LOOP;
    FOR Emp IN Emp_Cur(20)
    LOOP
    DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
    DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
    END LOOP;
    END;
    In the above Program, I send Deptnumber. If i send Column names like Empno, Ename. What can i do??
    If Declare Samething Through Parameter Cursor, it doesn't accept VARCHAR2(Size)

    For parameters you don't use size, just the type (DATE, NUMBER, VARCHAR2, CLOB, ...)
    DECLARE
      CURSOR Emp_Cur (P_Ename VARCHAR2)
      IS
        SELECT Empno, Ename
        FROM Emp
        WHERE Ename = P_Ename;
    BEGIN
      FOR Emp IN Emp_Cur('SCOTT')
      LOOP
        DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
        DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
      END LOOP;
    END;

Maybe you are looking for