Work with a table in different schema depending on the user group

I have 2 groups of users user_group1, user_group2 and also two different schemas schema_group1,schema_group2 containing the same table names with a different content.
Now, i have to write a stored procedure which takes user name as input and depending on which group the user belongs to, i want to work with table in that user_group schema.  i.e.(if user_group1 then "schema_group1"."table". if user_group2 then "schema_group2"."table" )
i tried to set schema using dynamic sql but it seems that the schema is changing only after the end of the stored procedure.

yes, i do maintain a table to map user groups with schema name.
i have two tables:
table-1: USERS(user_name, group_name)
table-2: GET_SCHEMA(group_name, schema_name)
// Just to make it simple(for testing purpose), i am directly assigning the schema_name inside the stored procedure.
CREATE PROCEDURE "TEJA"."RETURN_SCHEMA_OF_USER" (IN IN_USER_NAME VARCHAR(30))
LANGUAGE SQLSCRIPT
AS
BEGIN
     DECLARE VAR_USER_GROUP VARCHAR(20);
     --DECLARE VAR_SCHEMA_NAME VARCHAR(20);
     DECLARE SCHEMA_NAME VARCHAR(20);
     DECLARE SQL_STATEMENT VARCHAR(200);
     DECLARE VAR_TEMP VARCHAR(200);
     SELECT USER_GROUP INTO VAR_USER_GROUP FROM "TEJA"."USERS" WHERE USER_NAME =      IN_USER_NAME;
     --SELECT VAR_USER_GROUP AS USER_GRP FROM DUMMY;
     -- SELECT GROUP_NAME INTO VAR_SCHEMA_NAME FROM GET_SCHEMA WHERE GROUP_NAME =      VAR_USER_GROUP;
     -- Instead of above statement, i am directly assigning the schema_name below
     IF VAR_USER_GROUP = 'UNION' THEN
            SCHEMA_NAME := 'USER_UNION';
     ELSE
            SCHEMA_NAME := 'USER_CORPORATE';
     END IF;
     SQL_STATEMENT := 'SELECT * FROM "'||:SCHEMA_NAME||'"."USER_DETAILS"';
     --I have USER_DETAILS table in both the schemas.
     --SQL_STATEMENT := 'SET SCHEMA ' || :SCHEMA_NAME || ' ';
     --sets the schema after the stored procedure is executed.
     EXECUTE IMMEDIATE SQL_STATEMENT;
END;
This dynamic sql statement does the job for me, but i don't want to use dynamic sql in all my stored procedures. I need this kind of functionality in almost all of my stored procedures. So, i am looking for a better approach.  I really appreciate your valuable inputs.
Thank you

Similar Messages

  • Performance with having tables in different schema's

    Hi all,
    We have a requirement to segregate tables into different schema's based on the sources. But everything is going to be on the same instance and database.
    Is there a performance hit (querying between tables) by having tables in different schema as apposed to having them in the same schema?
    Thanks
    Narasimha

    Most likely there is bit of performance impact if your application refers the tables from different schemas. You need to use database link to access the other schemas. Even you schemas may in instance but when you use database link the network also comes into picture. even queries on same instance will routed through network connect and get the data. Distributed transaction also have issues some time. So as far as possible the distribution of objects should be avoided into diffrent schemas.

  • Accessing tables from different schema in CDS and AMDP

    Hi All,
    We are working on a HANA system which has several schema replicated from SAP R/3/Non SAP systems. We have BW 7.4 SP9 deployed on the same system and accessing the HANA views using latest BW virtual objects such as Open ODS , Composite providers etc.
    We are also using the BW system for few ABAP based data processing developments. We are currently accessing HANA views in ABAP programs by creating dictionary views based on external HANA views.
    We would like to however use recent possibilities of CDS and AMDP for better life cycle management of ABAP based solutions. The open SAP course on this subject was of very good help. Thanks a lot "open SAP team" for that. I would however have few open questions,
    As I understand AMDP gives us full flexibility of writing sql procedures within ABAP development environment, but can we access tables from different schema into AMDP code. If yes, then sample code would help.
    If the answer of first question is yes, then how do we manage transports between development and production systems where the schema names would be different. Currently in open HANA developments, such transport is manged using Schema mapping.
    Can I also use different schema tables in CDS views.
    We are updating few tables in ABAP dictionary after applying processing logic in ABAP program as detailed in step 1. With the new approach using AMDP, can we directly update database schema tables which will give us an optimization advantage.
    New ABAP HANA program interfaces are quite promising and we would like to use them to optimize many data intensive applications.
    Thanks & Regards,
    Anil

    Hi Anil,
    I can only answer 1. and 2. (and would be interested into 3. as well):
    1.
    Yes you can access tables from a different schema and also HANA views. In this case no 'using' is needed.
    Examples:
        RESULT = SELECT
        FROM
              "SAP_ECC"."T441V" AS t,
              "_SYS_BIC"."tmp.package/AFPO" AS a.
        WHERE ...
    2. In this case, if you need schema mapping: You could use HANA (projection) views which just forward to a different schema, also see example.
    Best regards,
    Christoph

  • Code and core tables in different schemas

    Hi,
    My db version : Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    I would like to understand, the pros and cons of the following situation:
    We have a single application.
    The db design for this application has 44 tables out of which 28 are core tables related by PK and FK relationships. The remaining 16 are look up and reference tables which are not related to any.
    The team decided to place the 28 core tables in one schema A and the remaining 16 in another schema B within same database. (The reason for this is..since it is done in other projects lets do it here too).
    Now comming to the code (stored procs, functions, packages etc). The teams wants to place most of the code in the schema B that has the 16 ref tables. (the reason again being the same).
    What are the pros and cons doing this???
    Please advice.
    PS:
    I have googled and found sth on these lines:
    cons: 
    o harder to manage
    o harder to upgrade
    o harder to patch
    o harder to maintain
    o causes your shared pool size to increase 1,000 times (shared sql goes down the tubes)
    o takes more space
    o queries against the dictionary will be impacted
    o latching on the shared pool goes WAY up (latching = locks = serialization device =
    slows you down)
    pros:
    o none that I can think of.

    >
    I would like to understand, the pros and cons of the following situation:
    Yes I am straining to find more points (was not good at it though).
    >
    You just want to understand? Are you sure? Your thread reads more like you just want to do things your way and are looking for support.
    >
    The team decided to place the 28 core tables in one schema A and the remaining 16 in another schema B within same database. (The reason for this is..since it is done in other projects lets do it here too).
    Now comming to the code (stored procs, functions, packages etc). The teams wants to place most of the code in the schema B that has the 16 ref tables. (the reason again being the same).
    >
    My question to you is: what PROBLEM are you trying to solve? If the 'team' already uses this approach and there haven't been any substantive problems then why try to change things now? Why have you chosen to fight this battle?
    Your 'team' has already decided and now, after that decision, you want to argue about it with them? The time to present arguments for/against a given plan is BEFORE the decisions are made, not after. Once a decision is made you need to be a team player and implement that decision to the best of your ability.
    One thing I'm certain of. If you try to support your argument using things like that 'AskTom' link you posted any credibility you had will go out the window. That link, as you already hinted yourself, is not your use case at all. All it takes is for one of your 'team' members to point that out and everyone will pretty much stop listening to any other arguments you make.
    People are generally not going to 'change their ways' unless you can show them:
    a) there is something seriously wrong with the way they are now doing things or
    b) a new way of doing things provides some substantial benefits
    Choice 'a' above is where you need to start but you haven't provided ANY information in this post that you have identified any serious issues with the status quo.
    The main task for Oracle is to be able to FIND the objects being referenced. So, in my opinion, that is what you should focus on when looking for PRO/CON arguments.
    That is: What issues are there if an object being referenced is in a different schema than the session that needs to use the object?
    1. objects may need to be prefixed with the schema name
    2. public or private synonyms may need to be created/maintained to avoid having to deal with item #1 above
    3. new grants may be needed to implement/maintain the proper security
    4. new roles may need to be created to maintain proper security (see item #3 above)
    5. additional work will be needed to maintain the new roles in item #4 above
    6. PL/SQL code may not be able to reference the object or may reference the wrong object
    7. Roles are disabled in PL/SQL (see item #6 above) - this means that the new grants (see item #3) may need to be granted directly to the schema users that need access instead of to roles. That can make it harder to create and maintain a role-base security schema.
    If I were you I would spend my time on other more important thingsd. But if I chose to fight this particular battle then I would make a list of problems that occured in the past with the current method of doing things and also problems related to the above list of items and then show how many of those problems will 'disappear' if the new method is used.

  • No Easy Way to Join on Tables from Different Schemas

    Hi,
    The company policy does not allow to join on tables from different schemas or use db links...
    I'm tasked to come up with a Perl script that does exactly that - allows for the SELECT statement to do several joins on 3 different schemas. In addition 1 of the schemas is on the different host altogether.
    Upping the privileges for my user and allowing db links is not an option...Can someone, please help me to understand on a conceptual level how would I use Perl and what logic would it have and what would it (perl) do?
    Thank you,

    Court in the wrong job... ;)
    It's like a librarian who is a hard rock artist maintaining the silence in the premises. ;)
    My dear friend, i don't think this is the right place for your requirement. This is the PL/SQL forum. If you have any problem related PL/SQL or SQL you can place that here.
    Regards.
    Satyaki De.

  • Read tables from different schemas in oracle

    Hi, I'm trying to write a code to run a query to get data from an Oracle server, the problem is that the query refers to multiple tables in multiple schemas... the regular way to do it in oracle (SCHEMANAME.TABLENAME) does not work in excel vba query and
    I cant find a way to so, any help will be really appreciated, below a sample code with one table from WWPP schema.....
    Const DB As String = "Driver={Microsoft ODBC for Oracle};" & _
                         "CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=1526))(CONNECT_DATA=(SERVICE_NAME=MyName)));" & _
                         "Uid=MyID;Pwd=MyPwd*;"
    Sub test()
        Dim cnt As ADODB.Connection, rst As ADODB.Recordset
        Set cnt = New ADODB.Connection
        Set rst = New ADODB.Recordset
        cnt.Open DB
        (I also tried this but didn't work) -> cnt.Execute "ALTER SESSION SET CURRENT_SCHEMA=WWPP"
        rst.Open "SELECT * FROM WWPP.SO_LIFE_CYCLE_BACKLOG_RP", cnt, adOpenDynamic, 2
        If rst.EOF = False Then
            Sheet1.Cells(2, 2).Select
            Selection.CopyFromRecordset rst
        End If
        rst.Close
    End Sub
    Oscar Marquez

    1) Posting the error number (i.e. ORA-00942) in addition to the error message is often quite helpful since that's generally far easier to look up and far less likely to get confused in translation.
    2) Are you using an invoker's rights stored procedure? Or a definer's rights stored procedure? If you're not sure, the default is definer's rights.
    3) How has YFS been granted access to the Y_PS table? My hunch is that it was granted access via a role, not via a direct grant. Privileges granted through a role would be available for ad hoc SQL queries, but those privileges are not available to a definer's rights stored procedure. A definer's rights stored procedure only has access to the privileges granted directly to the owner.
    If my hunch is correct, you'd either have to directly grant YFS access to the table(s) it needs to access in other schemas or you'd need to make the stored procedure use invoker's rights, which may have ripple effects down the line if users other than YFS are going to be running the procedure.
    Justin

  • Package Error!  join to tables in different schemas

    Hi
    I get an error whwn I want to put my query into package
    I have two tables in different schemas and I joined them and it works when I compile it
    but in the SP it doesn't works
    Is anbody help me? please
    Table1 in Schema1
    Table2 in Schema2
    TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
    User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
    Package1 in Schema1

    query is working
    but when I put that query in to package, Package is giving error like "table or view does not exist"
    Table1 in Schema1
    Table2 in Schema2
    TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
    User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
    Package1 in Schema1
    Select * from Schema1.Table1
    Inner join Schema2.Table2 on Table1.TableID=Table2.TableID
    is working in editor but
    CREATE OR REPLACE PACKAGE Schema1.PCKG_packagename AS
    PROCEDURE SP_procedurename
    Select * from Schema1.Table1
    Inner join Schema2.Table2 on Table1.TableID=Table2.TableID;
    END SP_procedurename;
    END PCKG_packagename ;
    is not working
    Must I give grant to Package?
    Edited by: 874779 on 25.Tem.2011 03:37
    Edited by: 874779 on 25.Tem.2011 03:51

  • InDesign CC 2014 is very very slow when working with a table.

    InDesign CC 2014 is very very slow when working with a table. Every 1/2 - 1 hour it nearly falls back, impossible to work with. While this project must be finshed quite soon..
    What the hell is the matter with this Creative Cloud. I havea very fast iMac form 2014. I closed all other programmes, even cannot listen to music now. More people with this problem??
    Martien

    @Martien – How complex is your table?
    How many cells? Merged ones as well?
    Complex formatting of texts inside the cells?
    Complex formatting rules of table rows and/or columns?
    Many images inserted?
    If yes, and the table is running through many text frames of many pages, I fear, you can do nothing against slowness.
    Nothing but: Greek text, not showing the page contents in the Pages Panel, in short: anything you can do to get better performance in redrawing of the screen.
    If you have the chance to break up one big table in several parts, do that and edit its parts one after another isolated. Pehaps in different documents.
    Then merge the parts in one table, if you want to flow it from page to page.
    Uwe

  • Java API for working with Pivot Tables...?

    Hi,
    I want to create/modify an existing pivot table in an excel sheet. Is there any open source available to work on pivot tables.
    I have seen few articles mentioning that POI supports updation of data, though the apache site says that it does not support working with pivot tables. I am able to copy an existing excel template with pivot table to a new excel using poi but am stuck with updating....
    Thanx,
    Praveen.

    Hi,
    The JExcelAPI does not support working with pivot tables... I am still in search of an open source to work with pivot tables....
    btw, we are able to update an existing pivot table using apache poi. But we need to change the data range of the pivot table during run time... Am stuck with this... Has anyone come across any open source to work with pivots???
    Regards...

  • How to create directories with same name in different schemas

    I have two schemas on the same database.
    I am trying to create directories with same name, but different paths in both the schemas.
    When i created the directories in second schema, the directory paths of the first schema are automatically changed to the second path.
    Is there any solution to create directories with same name, but different path in two different schemas on the same database.
    Thanks,
    Sridhar.

    Hi,
    >>When i created the directories in second schema, the directory paths of the first schema are automatically changed to the second path.
    If you have removed the REPLACE clause of your create statement, then you would see that is not possible.
    SYSTEM> connect scott/tiger
    Connected.
    SCOTT> create directory mydir as '/tmp';
    Directory created.
    SCOTT> connect legatti/pwd
    Connected.
    LEGATTI> create directory mydir as '/tmp';
    create directory mydir as '/tmp'
    ERROR at line 1:
    ORA-00955: name is already used by an existing object
    LEGATTI> select owner,object_name,object_type,created
      2  from dba_objects where object_name='MYDIR';
    OWNER     OBJECT_NAME    OBJECT_TYPE         CREATED
    SYS       MYDIR          DIRECTORY           19/12/2007Cheers
    Legatti

  • Create a View from tables of different schemas

    hi all,
    can u pls give solution to create a View from tables of different schemas.
    i have to bring data from one DB Server A,
    which contains different schemas and tables in the schemas...
    i need to insert that data in another DBServer B.
    i made a procedure for this...
    but when the connection fails from A, then i could not get data...
    please suggest some solution..
    thanks,
    neelima

    I don't know what database system you use, but in the most I know it is done that way:
    SELECT
    A.COL1,A.COL2.....
    FROM
    SCHEMA_NAME.TABLENAME A,
    SCHEMA_NAME.TABLE_NAME B
    WHERE
    A.COL1 = B.COL2
    ...

  • Working with RW_SERVER_JOB_QUEUE Table and RW_SERVER Package

    Hi,
    I have one form that is based on RW_SERVER_JOB_QUEUE Table which shows reports details.
    This table contains all reports regardless of the user who run the report.
    Is there any way to add column (User_Id) to the RW_SERVER_JOB_QUEUE table so that I can filter the results depending on the user? If it is possible, Where and how I can fill this column?
    Thanks & Regards.

    Here is the solution I found and I would like to share if anybody is interested :
    Check the following Oracle Support Notes:
    ALERT - After Applying Patchset 11.1.1.4, Fusion Middleware Control Inserts "demo:" Tags in Conf Files of Reports Server- ENVID Section Stops Working [ID 1298701.1]
         After applying patchset 11.1.1.4 to Reports Server, any configuration changes through Fusion Middleware Control inserts "demo:" tags in the beginning of each line in conf file of Report Server.
         The behaviour is described in the following bug :
         Bug:11784251 MBEAN BROWSER ADDS A DEMO TAG IN RWSERVER.CONF AT EACH LINE
    So you I removed all demo tags in rwserver.conf
    <jobStatusRepository class="oracle.reports.server.JobRepositoryDB">
    <property value="csf:reports:jobrepo" name="dbpassword"/>
    <property value="repteam.us.oracle.com" name="dbconn"/>
    <property value="jobrep11g" name="dbuser"/>
    </jobStatusRepository>
    Regarding : PKI-02002 error:
    Error PKI-02002: Unable to open the wallet. Check password When Starting a Reports Server [ID 1316651.1]
    Temporary file cannot be created in temporary directory.
    After checking the wallet I simply changed the following lines
         <variable id="TEMP" value="C:\Users\oracle\AppData\Local\Temp\2"/>
         <variable id="TMP" value="C:\Users\oracle\AppData\Local\Temp\2"/>
    to
         <variable id="TEMP" value="C:\TEMP"/>
         <variable id="TMP" value="C:\TEMP"/>
    because the folder C:\Users\oracle\AppData\Local\Temp\2 was not created.
    Regards,
    Alex
    Edited by: user12019587 on 11-Apr-2012 2:50 PM

  • HELP PLEASE!  I am working with GH4 4k footage in adobe preimere and the computer keeps freezing... any ideas?

    HELP PLEASE!  I am working with GH4 4k footage in adobe preimere and the computer keeps freezing... any ideas?

    Thanks for your response.  I'm sorry for the lack of details, but posting a question on this forum is completly new to me, so I guess I am learning how it works.
    I have to be honest, I am a novice to video editing, but I am here to learn so I will provide all the info I know and please let me know if it is enough...
    I filmed my first feature film on a Panasonic GH4. We filmed in 4k (compressed files).  I am about 900 GB of total files for all the footage.  I am currently editing on a 17' Toshiba Satellite i7 with 750 GB of space and I believe 8 gb of ram.  All of the footage for the film is not on the computer, but stored on a 1 TB external hardrive (Rugged Lacie is the name of the hard drive).  I am using a usb 3.0 from the hard drive to the computer.
    I actually was able to get through about 17 mins of edits for the film before I started to experiencing the computer completely freezing up on me.  I tried using a different hard drive, and same issue.  A friend mentioned it might just be the computer is not powerful enough to edit all the footage, but he wasn't for sure considering the computer is less than a year old and is on the higher end for a toshiba.
    I am requesting advice on how to continue editing the film without the computer crashing if that is even possible with using the same computer.  If not what would be my options?
    Thank you!

  • I have Firefox 5.0.1, and a theme I want to download says that it works with Firefox 4.0b9pre - 7.0a1, but at the top it says that it is not available for my platform. What do I do?

    I just downloaded Firefox 5.0.1, and one of the themes I want to download and try out says that it works with Firefox 4.0b9pre - 7.0a1. At the top, though, it says that the theme is not available for my platform. It has happened with some other themes as well, but I didn't check what versions they work with. I don't know what this means or what to do about it. The theme is at this link: https://addons.mozilla.org/z/en-US/firefox/addon/bloomind-ft-deepdark-2/

    It says:
    <blockquote>"Bloomind FT DeepDark 2" is a theme that has been created to transform the look of Firefox 4 for <b>Windows</b> users. It has been specially designed for Seven, but rendering is relatively accurate on XP and Linux (<b>I can t test it on MAC</b>, but for those who would like to try it anyway on that platform, <u>you can force download and install it</u>).</blockquote>
    So try to save that file via the right-click context menu.
    *http://kb.mozillazine.org/Themes

  • HT201210 hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    Try the suggestions here to see if they resolve your problem:
    http://support.apple.com/kb/ts1559
    If these don't work you may have a hardware problem. Visit an Apple store for an evaluation or contact Apple Support.

Maybe you are looking for