Accessing a different schema in Oracle

Hi,
I currently have a great deal of code that assumed it would have access to the same database schema as the logged on user e.g.
"Select * from TABLE_NAME" (no need to specify schema name).
I have found out that we will now be using a system where the user that logs on, will be granted select, update and delete priviledges on another schema. So now after setting up the connection, my code would have to read: "Select * from ANOTHER_SCHEMA.TABLE_NAME" where ANOTHER_SCHEMA is the schema that contains the tables.
My question is, since I would have to modify a great deal of code at this point, is there any way to change the user on an existing connection so that I would not have to manually affix the new schema name to all table references? I would have to be able to do this without logging on as this alternate user since we will not have the password for that user (for security reasons).
I have considered creating views in the initial schema that access the alternate schema (e.g CREATE VIEW TABLE_NAME AS SELECT * FROM ANOTHER_SCHEMA.TABLE_NAME), however I was wondering if there might be a better way to do this?

Yes he would have to change his code. I am just used to using "S_" and it is the standard Oracle naming convention for synonyms. (Also it makes it clear that you are referencing the table via a synonym rather than hitting the table directly.
Why not encode all table names in an abstract class.
Eg
package utils;
public class TableNames
public static final String TABLE_NAME1 = "S_TABLE_NAME1";
public static final String TABLE_NAME2 = "S_TABLE_NAME2";
//etc etc
This class can then be used in the building of sql statements. If the table name happens to change at any time then a change is only required in TableNames class.

Similar Messages

  • Transfer a binary file stored in a table field in oracle to another table different schema in oracle

    I would like to know if it is possible to use ssis to transfer a binary file of a datatype of long raw in a field in one table in oracle to a new table in a different schema of a datatype blob in oracle? The binary file is a Crystal reports executable
    which is used in a application that I support. I are trying to consolidate data fields over many schemas into one main schema to simplify the support issues.

    Hi r_peterser,
    SQL Server Integration Services maps DT_IMAGE data type to LONG RAW and BLOB in Oracle. So, you can directly use an OLE DB Source or Oracle Source adapter to extract the LONG RAW column from the Oracle database, and then load the data to the BLOB column
    of the Oracle table through an OLE DB Destination or Oracle Destination adapter.
    Reference:
    http://technet.microsoft.com/en-us/library/ms141036.aspx 
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Stored Procedure executes on two different schemas in Oracle 8i

    Can I Create a Stored Procedure that access table from two different schemas?
    For Example I have created this Stored Procedure on SCHEMA_ONE
    CREATE OR REPLACE PROCEDURE SP_DEMO IS
    BEGIN
    INSERT INTO SCHEMA_ONE.COUNTRY_ONE(COUNTRY_NAME)
    SELECT COUNTRY_NAME
    FROM SCHEMA_TWO.COUNTRY_TWO
    END SP_DEMO;
    and when I execute it I am getting error message as :
    Error: PLS-00201: identifier 'SCHEMA_TWO.COUNTRY_TWO' must be declared
    is that possible? If yes then what I need to do for that?
    Please assist me.

    hi john
    How are you?
    please have a view there and correct me if m wrong.
    insufficient privileges
    Khurram Siddiqui
    [email protected]                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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

  • Securing Data Access In Same Schema

    Dear All Experts,
    Please guide us to Securing the Data Access In Same Schema in Oracle Forms & Reports.
    Currently our application (Based on Oracle Forms , DB & AS 10g) is running for 6 COMPANIES in same schema. All the 6 COMPANY's employee can access the other COMPANY's Data.
    Please give us any idea to Secure the Data Access as we want that if any Employee have the Rights of one or two COMPANIES then he can only access the data of those companies instead of all the companies.
    How can we got it using same Oracle Form & Reports...?
    Please guide....
    Thanks
    Eidy

    Hello,
    <p>Did you check out the Virtual Private Database feature ? </p>
    Francois

  • Can Oracle reports access different schemas?

    I have a query that accesses 2 schemas: It gives me an error ORA-00904 when I try to run the report.
    Any ideas?

    Yes it helps. I had 3 queries... and the first was accessing the other schema but not the second or third query when they should have. However, when I ran the report, it kept giving me an error as if the first one was the problem.
    Misleading error diagnostics made doubt it.

  • Different schemas in the same Oracle database

    Both my source and target tables are in the same physical Oracle database (different schemas).
    I can use the LKM Oracle to Oracle (DBLINK) knowledge module to load data but this requires setting up a dblink between the two schemas. Given that I can set this up so that the target schema has select etc permissions on the source schema, I can't help feeling that there is a simpler (more efficient?) way of doing this.
    One of the steps in the LKM is 'Create Synonym on Target' which does the following
    create synonym     <%=snpRef.getTable("L", "COLL_NAME", "W")%>
    for           <%=snpRef.getTable("R", "COLL_NAME", "W")%>
    This creates an Oracle synonym that includes a dblink (e.g create synonym s1 for s2@dblink). I can't help feeling that if I could change this so that it doesn't include the '@dblink' part then I could solve the problem and just create a synonym in the target schema that points directly to the source (e.g create synonymn s1 for source.s2). This should then mean that all the rest of the load etc process could run just the same.
    I'm sure that there must be a way of doing this, but I can't figure out how to do it using the substitution methods API.
    Any ideas how I do this?
    Thanks,
    Chris

    Chris,
    for sure when you define a Data Server you have to specify user which have appropriate access to both source and target schemas.
    Then you can create 2 schemas in one Data Server and ODI will use queries like
    insert into target_schema.tab_name
    select ... from source_schema.tab1 ...
    Loading KM will not be used in that case at all therefore data flow will work MUCH faster.
    Oleg

  • Accessing a Cube under different schema

    Guys,
    Is it possible for a user to access OLAP cube residing in a different schema under same oracle database and SID ? If yes, how it can be done (permissions etc.)
    Thanks,
    Mav

    Hi,
    Yes this is possible. The other user needs to have the olap_user role, and if you are going to use discoverer it also needs the d4opub role.
    In addition to that you also need to grant rights on the AW$ table to the user you want to give access to.
    The AW$ table is where actually the AW is stored and should be in the schema where you have created the AW. The name of it s AW$<AW_NAME> so in order for you to grant select on it to other users, all you need to do is the following:
    grant select on aw$<aw_name> to <user>
    Ragnar

  • 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

  • MapViewer metadata problem - accessing spatial data in a different schema.

    I have a MapViewer application that uses data from three different schemas.
    1. Dynamic Themes come from schema A.
    2. Static Themes come from schema B.
    3. A newly added static theme in B whose data comes from schema C.
    The mapviewer datasource points to schema B where the static themes, data and metadata are defined while the dynamic themes have their own datasource specified as part of addJDBCTheme(...).
    To get the newly added map to work I've had to add a view in schema B that points to C instead of referencing directly the table and I've had to add the metadata twice, once for schema B and once for schema C.
    If I put the metadata in just one of the two schemas I get the following errors.
    08/11/21 13:58:57 ERROR [oracle.sdovis.ThemeTable] cannot find entry in ALL_SDO_GEOM_METADATA table for theme: AMBITOS_REST
    08/11/21 13:58:57 ERROR [oracle.sdovis.ThemeTable] java.sql.SQLException: Invalid column index
    OR
    08/11/21 13:53:39 ERROR [oracle.sdovis.theme.pgtp] java.sql.SQLException: ORA-29902: error in executing ODCIIndexStart() routine
    ORA-13203: failed to read USER_SDO_GEOM_METADATA view
    It's not a big deal but I'd like to know if anyone else has has similar problems.
    Saludos,
    Lew.
    Edited by: Lew2 on Nov 21, 2008 6:42 AM

    Hi Lew,
    if you are using a recent version (10.1.3.1 or later) there is no need to use a view and to create the metadata in both schemas.
    You need to grant selection on tables between the schemas.
    You can try the following. Assume you have the MVDEMO schema (from MapViewer kit) and SCOTT schema.
    1) grant select on MVDEMO Counties table to SCOTT
    SQL> grant select on counties to scott;
    2) Now you are ready to create a predefined theme in schema SCOTT using the MVDEMO Counties table.
    - Open MapBuilder and loads the SCOTT schema.
    - On the Data navigator (bottom left tree), go to Geometry tables and you should see the MVDEMO node and the COUNTIES node inside it.
    - Start a wizard to create a geometry theme based on this Counties table.
    - At the end you should see that the base table name is MVDEMO.COUNTIES. Therefore MapViewer will use the metadata in MVDEMO schema and there is no need to replicate it in SCOTT schema.
    Joao

  • Any time tested tool to sync 2 oracle databases having different schemas?

    Hi,
    I have 2 databases (one with old table schemas and the other one with refined table schemas) that are catering to 2 applications - a new app and the old app.
    Gradually the old app will fade away, but till then we need to run these 2 apps together.
    The requirement is to have a bidirectional sync between these 2 databases so that the 2 apps can reflect real-time data at any point in time used by different set of users.
    Initially we thought of using Golden Gate but it seems that it is not meant for databases having different schemas.
    Any recommendations what tool can be used in such a scenerio?
    Thanks.

    This forum is assiting with foreign database to Oracle migrations. For your replication issue there's a dedicated forum:
    Replication
    Better post our issue there.

  • DB2 to Oracle conversion using SQL Developer Migration Wizard - different schemas

    I am performing a conversion between DB2  to Oracle 11 XE, using the SQL Developer Migration Wizard. Specifically I am trying to migrate the DB2User schema over to Oracle.
    Using the migration wizard, when I pick the Oracle target connection to be the same schema ( DB2User schema ) the migration is successful and all data is converted.
    However if I pick a different Oracle target connection ( say OracleUser ) , I run into issues.
    Firstly , the table schema is not created. When I check the project output directory, the .out file has the following errors:
       CREATE USER DB2User IDENTIFIED BY DB2User DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP
            SQL Error: ORA-01031: insufficient privileges
            01031. 00000 -  "insufficient privileges"
        connect DB2User/DB2User
        Error report:
        Connection Failed
        Commit
        Connection created by CONNECT script command disconnected
    I worked around this by manually executing the .sql in the project output directory using the OracleUser id  in the new DB.
    Then I continue with the migration wizard and perform the Move Data step.
    Now - the message appears as succuessful, however, when I review the Migrationlog.xml file, i see errors as follows:
    <level>SEVERE</level>
      <class>oracle.dbtools.migration.workbench.core.logging.MigrationLogUtil</class>
      <message>Failed to disable constraints: Data Move</message>
      <key>DataMove.DISABLE_CONSTRAINTS_FAILED</key>
      <catalog>&lt;null&gt;</catalog>
      <param>Data Move</param>
      <param>oracle.dbtools.migration.workbench.core.logging.LogInfo@753f827a</param>
      <exception>
        <message>java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist</message>
      <level>WARNING</level>
      <class>oracle.dbtools.migration.datamove.online.TriggerHandler</class>
      <message>ORA-01031: insufficient privileges
    </message>
    I think what is happening is that the wizard is attempting to perform the 'move data' process using the DB2User id.
    How do I tell the wizard that the target schema is different than my source schema.
    My requirement is that I need to be able to migrate the DB2User schema to different schemas in the same Oracle database
    ( since we will have multiple test environments under the same database ) .
    Thanks in advance .
    K.

    Perhaps the following from the SQL Developer documentation is helpful for you:
    Command-Line Interface for Migration
    As an alternative to using the SQL Developer graphical interface for migration operations, you can use the migration batch file (Windows) or shell script (Linux) on the operating system command line. These files are located in the sqldeveloper\sqldeveloper\bin folder or sqldeveloper/sqldeveloper/bin directory under the location where you installed SQL Developer.
    migration.bat or migration.sh accepts these commands: capture, convert, datamove, delcaptured, delconn, delconverted, driver, generate, guide, help, idmap, info, init, lscaptured, lsconn, lsconverted, mkconn, qm, runsql, and scan. For information about the syntax and options, start by running migration without any parameters at the system command prompt. For example:
    C:\Program Files\sqldeveloper\sqldeveloper\bin>migration
    You can use the -help option for information about one or more actions. For the most detailed information, including some examples, use the -help=guide option. For example:
    C:\Program Files\sqldeveloper\sqldeveloper\bin>migration -help=guide
    Regards
    Wolfgang

  • Combine multiple oracle 10g db as one 11g database with different schemas

    We have 3 10g databases on a solaris machine
    We are planning to migrate them and upgrade to 11g rel2 on linux machine
    and finally merge those into one database as different schemas
    has anyone got good ideas of the best strategy to do that
    thanks

    has anyone got good ideas of the best strategy to do thatexpdp/impdp

  • Import of BaseView to a different schema in database

    Hi All,
    We have developed some bam reports. Now the base view, meta view are referring to a schema name (say SchemaName1) in database.
    In the plans we are using "SQL query" to get data from database. So we have queries like "Select SchemaName1.table1.column1 ... from ......".
    Now we have taken a export of the base view, meta view ,plans and all other components of BAM.
    All is fine till now... But now i need to import all these stuff in a different database. My problem is that in the new database instance i cannot use the same schema name (i.e. SchemaName1 ). I have a different schema name(say SchemaName2) there and i need to use that......There is no way i can use SchemaName1.
    Will the import of Base view/Meta view/plans work or we need to do some configuration changes during import??
    Do we have to create Base view for the new schema names from scratch or the imported code can be used??
    The plans have sql queries referring to SchemaName1 but we need it to refer to the Other schema(SchemaName2 )...What is the possible way of referring to the new schema without developing the plan again??
    Waiting for your valuable feedback...

    ***Backup your repository database***
    ***Please review all steps before attempting***
    Sarputil Export
    1.     Start | Run, type “sarputil”
    2.     Do a partial export. (Note down directory that will contain files to be exported.).
    3.     Select your Baseview, Metaview, Security:Login Profile, and Plan. (Note, the check boxes are in front of each object name and might appear very light on some clients.)
    4.     On the XML dialog and with the question on what you would like to do – select Execute Now.
    5.     Finish the wizard and from the directory noted above, verify .csv files were created. (Typically C:\OracleBAM\EnterpriseLink\Data\rp\export).
    6.     Copy all .csv files and paste to different temporary folder on 2nd server.
    Sarputil Import
    1.     Start | Run, type “sarputil” on the 2nd server where you’ll import into.
    2.     Partial import
    3.     Under Repository Information dialog, set the Data Source information on the right and remember to change the directory now containing your .csv files.
    4.     Like before, select “Execute now” and Finish the wizard.
    Oracle BAM Admin
    Modify connect string (host string or tns name) if you need to:
    1.     Connect in Oracle BAM Admin
    2.     Expand Baseviews and select the imported Baseview
    3.     Check under “Server” on the left if the connect string is correct.
    4.     If not, click Modify button and change.
    Modify Baseview Login if you need to:
    1.     With your Baseview still selected on the left side, click on “Baseview Logins” tab
    2.     Logins on the left correspond to actual database user id’s and password. Add a new Login with a database User ID and Password to access the new schema.
    3.     Associate or Set the new Login (right) to the BAM User on the left.
    Sarpbv Modification
    Use sarpbv utility to change references of the old schema name to a new schema name.
    General syntax for Oracle:
    sarpbv /R"username:pwd:Oracle:TNS Name::DB UserID:DBUser pwd” /B"BaseView name" /O"NewSchema"
    **Use Capital letters for New Schema name!
    **Notice 2 colons (::) after TNS Name (because you do not have a database name in Oracle).
    1.     Open DOS
    2.     Type your sarpbv command. Below is an example where I changed a Baseview called “scott” to use a new schema name called Jack.
    sarpbv /R"sa::ORACLE:baminst::sagent:sagent" /B"scott" /O"JACK"
    3.     Open Design Studio, locate the plan and check the SQL Query now reflects the new schema.
    4.     Test the plan to ensure it’s pulling data correctly from the new schema.

  • SQL Query Template to a different schema

    Hi all
    I am on MII 12.2, connecting to Oracle through a data source which references user/schema "Foo"
    I would like to perform queries involving tables from schema "Bar" .
    As a consequence, when I need to access Bar tables I must reference them like "Foo.<TableName>"
    If I use an SQL query with mode Command I can freely write the prefix but no return is allowed
    If I use mode = FixedQuery(With Output) I can't prefix "Foo." because the editor prevents me from freely entering SQL code
    How can I do this? Thanks regards
    Vincenzo

    Thanks for your reply!
    Actually there is a primary key, but Streams seems to ignore it. I've also tried the SET_KEY_COLUMNS way plus supplementary logging on the source DB, but this didn't help at all. I think this is happenening because the tables are not in the TEST_HQ schema, there are only synonyms to the real tables contained in TEST_CO.
    Is there any other easy way to get Streams working between two different schemas?
    Thanks again for your help!!
    Max

Maybe you are looking for