How to find schema name in Oracle ? when you are connected in sql session using read only user

前端 未结 3 1192
猫巷女王i
猫巷女王i 2021-02-18 15:29

I am connected to a oracle database with a read only user and i used service name while Setting up connection in sql developer hence i dont know SID ( schema ).

How can

3条回答
  •  青春惊慌失措
    2021-02-18 15:52

    To create a read-only user, you have to setup a different user than the one owning the tables you want to access.

    If you just create the user and grant SELECT permission to the read-only user, you'll need to prepend the schema name to each table name. To avoid this, you have basically two options:

    1. Set the current schema in your session:
    ALTER SESSION SET CURRENT_SCHEMA=XYZ
    
    1. Create synonyms for all tables:
    CREATE SYNONYM READER_USER.TABLE1 FOR XYZ.TABLE1
    

    So if you haven't been told the name of the owner schema, you basically have three options. The last one should always work:

    1. Query the current schema setting:
    SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') FROM DUAL
    
    1. List your synonyms:
    SELECT * FROM ALL_SYNONYMS WHERE OWNER = USER
    
    1. Investigate all tables (with the exception of the some well-known standard schemas):
    SELECT * FROM ALL_TABLES WHERE OWNER NOT IN ('SYS', 'SYSTEM', 'CTXSYS', 'MDSYS');
    

提交回复
热议问题