Replicate Table DDL Changes to other schema..!!

Hello All,
I have two schemas SCH1 and SCH2
SCH1 : TBL1
SCH2 : A_TBL1
Our requirement is whenever we create a table in SCH1 for Eg TBL2 there should be some code which will create A_TBL2 table automatically in SCH2.. Both TBL2 and A_TBL2 should have same structure.. This functionality i can manage using "ON CREATE OR ALTER" Trigger..
But now if in SCH1 we do ALTER TABLE... on TBL2.. same changes has to be applied to A_TBL2 in SCH2.. I have no idea how i could manage this ALTER TABLE change..
Please any help would be greatly appreciated..
Here's the trigger i did for create table..
create or replace
TRIGGER DDL_APPLY_TO_SCH2
AFTER ALTER OR CREATE ON SCH1.SCHEMA
DECLARE
VSTR  VARCHAR2(255);
VJOB NUMBER;
BEGIN
        IF  ORA_DICT_OBJ_TYPE = 'TABLE' THEN
        VSTR := 'EXECUTE IMMEDIATE ''CREATE TABLE SCH2.A_'||ORA_DICT_OBJ_NAME||' AS SELECT * FROM '||ORA_DICT_OBJ_NAME||''';';
        DBMS_OUTPUT.PUT_LINE(VSTR);
        DBMS_JOB.SUBMIT( VJOB, VSTR );       
        END IF;
END;Thanks - HP

Ora_User_2 wrote:
Hello All,
I have two schemas SCH1 and SCH2
SCH1 : TBL1
SCH2 : A_TBL1
Our requirement is whenever we create a table in SCH1 for Eg TBL2 there should be some code which will create A_TBL2 table automatically in SCH2.. Both TBL2 and A_TBL2 should have same structure.. This functionality i can manage using "ON CREATE OR ALTER" Trigger..
But now if in SCH1 we do ALTER TABLE... on TBL2.. same changes has to be applied to A_TBL2 in SCH2.. I have no idea how i could manage this ALTER TABLE change..
Please any help would be greatly appreciated..
Here's the trigger i did for create table..
create or replace
TRIGGER DDL_APPLY_TO_SCH2
AFTER ALTER OR CREATE ON SCH1.SCHEMA
DECLARE
VSTR  VARCHAR2(255);
VJOB NUMBER;
BEGIN
IF  ORA_DICT_OBJ_TYPE = 'TABLE' THEN
VSTR := 'EXECUTE IMMEDIATE ''CREATE TABLE SCH2.A_'||ORA_DICT_OBJ_NAME||' AS SELECT * FROM '||ORA_DICT_OBJ_NAME||''';';
DBMS_OUTPUT.PUT_LINE(VSTR);
DBMS_JOB.SUBMIT( VJOB, VSTR );       
END IF;
END;Thanks - HPThis is not a good idea but you can use that,first you can check if object(table) exits then you can drop this table and can create again using VSTR := 'EXECUTE IMMEDIATE ''CREATE TABLE SCH2.A_'||ORA_DICT_OBJ_NAME||' AS SELECT FROM '||ORA_DICT_OBJ_NAME||''';'* it means trigger will fire after alter event du to there will not any problem,so first check if this table exits then drop and create again ,so you will get changed table.

Similar Messages

  • How to restrict one user making DDL changes in another schema

    can anyone please let me know the way to restrict a user making the DDL changes Through Procedure (This user have the execute privilege on procedure owner by another schema) on another schema.
    Let say we have schema A and B. our requirement is, The User A should grant execute privilege on all the procedure that are created on A to user B, but if at all there is a situation a procedure is created with DDL changes(with execute immediate option) and gave the execute privilege to the user B, Then user B can make DDL changes through this procedure. i wanted to restrict user B making DDL changes any way to user A .
    Appreciate your help.
    Thanks,
    Karthik

    Your requirement doesn't sound terribly sensible.  If you want B to be able to execute the procedure, grant B access to the procedure.  If you don't want B to be able to execute the procedure, don't grant B access.  If you are concerned that someone is going to change the code in the procedure after it is created to transform it from something that you want B to have access to into something that you don't want B to have access to, you should be reviewing changes before they are promoted.
    If you're really determined to do things "uniquely", I suppose you could create a DDL trigger that looks to see who the user is and throws an exception if it is B.  But that seems like a poor second choice to dealing with the problem sensibly from the outset.
    If you aren't reviewing the changes and building code that tries to check whether something bad got slipped in, you're going to be fighting a losing battle.  If you write a DDL trigger that checks the user, for example, and I'm a developer that's intent on creating holes, I could simply add code to a procedure that submits a dbms_job that executes DDL.  That job would run as A so your DDL trigger would let it pass.  Of course, you could then turn around and disable DBMS_JOB in which case I could use DBMS_SCHEDULER instead.  You could disable that as well but then you're disabling the scheduler jobs that Oracle runs by default for things like gathering statistics.  And then the rogue developer simply moves on to the next hole to exploit.
    Justin

  • 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

  • Error using views from other schema

    Hello,
    i recently had problems using the execute immediate statement in Object Types.
    The SQL statement tried to select from some views which were owned by an other schema.
    Although we had public synonyms on these views and the same dynamic sql could be used out of a stored procedure the usage in the object type raised a "table or view does not exist exception".
    using the same views in the same schema where the object types belonged to, was ok.
    example:
    schema: scott
    view: my_view
    schema: dave
    sql: "select from scott.my.view ....."
    works well from a stored procedure, but nor if used in an object type
    create the view in schema "dave" an then
    sql: "select from my.view ....."
    works fine.
    So is someone aware of this behaviour?
    Is this a bug or a feature?
    regards
    peter

    Hello Geoff,
    here is the sample code.
    If the table my_table belongs to the same
    schema runningthe code the code runs with
    no exception.
    But if the table belongs to an other schema
    (lets say SCOTT),
    only having global synonyms and the rigths to
    select on it, the code will raise an exception "table or view does not exist"
    even if we use SCOTT.my_table in the
    select.
    create type query_o as object(
    dummy integer,
    static function get_query return
    varchar2;
    create or replace type body query_o as
    static function get_query return varchar2
    as
    query varchar2(4000) :=
    'select ' | |
    ' f.amount_month ' | |
    'into :r1 ' | |
    'from ' | |
    ' my_table f ' | |
    'where id=:p1 ';
    begin
    return query;
    end;
    end;
    create type consumer_o as object(
    amount_month number,
    member function find(p_id in integer)
    return consumer_o
    create type body consumer_o as
    member function find(p_id in integer)
    return consumer_o
    as
    l_amount number;
    begin
    execute immediate query_o.get_query()
    using out l_amount,
    in p_id;
    return consumer_o( l_amount );
    end;
    end;
    kind regards
    peetr

  • Import from other schemas other than default

    Hi,
    I defined a source metadata location to an Oracle database. The user used to connect to the DB itself has no objects. I need to import tables and views from other schemas in the source Oracle database. It that possible using the same user that was used in creating the metadata source location? Or, does one need specific one-to-one connection established as separate source metadata locations in order to import tables and views from other schemas?
    In other words, is one user/password to a database sufficient to import tables and views from other schemas?
    Thanks!

    I'm not sure you can import directly into the Android version of Firefox due to security limitation on the device. If you can get your Opera bookmarks into Firefox on the desktop, you can use Firefox Sync to move them to your mobile.
    Does this thread help? [https://support.mozilla.org/en-US/questions/923976 how can I sync bookmarks between my opera mobile browser and my new Firefox for android browser ? | Firefox Support Forum | Firefox Help]

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

  • After i bought mac os x lion from web then download , after that to install but when they ask me to choose disk to install i can not choose, it say this disk does not use the GUID partiton table scheme. use disk utility to change the partition scheme. but

    after i bought mac os x lion from web then download , after that to install but when they ask me to choose disk to install i can not choose, it say this disk does not use the GUID partiton table scheme. use disk utility to change the partition scheme. but

    after i bought mac os x lion from web then download , after that to install but when they ask me to choose disk to install i can not choose, it say this disk does not use the GUID partiton table scheme. use disk utility to change the partition scheme. but

  • How do I change the partition scheme to use GUID partition Table.

    How do I change the partition scheme to use GUID partition Table so I can get Snow Leopard to download on my 10.5 disk.
    When I insert the disk it asks me to select  the disk where you want to install MAC OS X.It only give me one option the 10.5.
    when I click on it it says...
    "10.5" can't be used because it doesn't use the GUID Partition Table scheme.
    Use Disk Utility to change the partition scheme.  Select the disk, choose the Partition tab, select the Volume Scheme and then click Options. 
    I tried to do what it says and I can not find what it is saying.  This is the info about my MacBook.
    Model Name: MacBook
      Model Identifier: MacBook4,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.4 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 3 MB
      Memory: 4 GB
      Bus Speed: 800 MHz
      Boot ROM Version: MB41.00C1.B00
      SMC Version (system): 1.31f0
    Thank you for your help!

    The GUID partition option is one of three possible choices (click the "Options" button in the Partition") menu - be careful to have a full backup as changing the partition scheme will force an erasure on the disk. Take a look at this Apple support article for more complete information:
    Firmware updates for Intel-based Macs require a GUID partition scheme - Apple Support
    Ignore the stuff about firmware updates and just look at the changing GUID partition scheme.
    Good luck - and don't forget about the full backup BEFORE making this sort of change.

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

  • Can't see DDL of views from other schemas in Developer?

    Hi,
    I've seen elements of this problem in other threads but this problem of course has it's own twist.
    I can see other schema's objects EXCEPT VIEW DDL.
    I have given a user every role and priv that I can and they still can't see the view ddl of another schema. They can see procedures, functions etc. just not the view. I've found that if I use the user that created the users I can see the DDL of all subordinate users. Users created under that schema can not see each others views no matter what rights are given. Interestingly enough sometimes when I look to display view DDL it will flash the DDL briefly before blanking the screen. very frustrating. All the Toad fanboys are crowing about how they couldn't possibly use a tool that doesn't allow them to see other view source.
    I have also looked for settings in the preferences but could find none.
    Is this a bug? It seems like one to me.
    Any help is greatly appreciated.
    Thanks
    Mark

    We have a bug logged for this.
    Sue

  • 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

  • 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

  • Readonly user can access other schema and change them

    Hello everybody,
    I created a readonly user like this in oracle 11g r2
    SQL> CREATE USER readonly IDENTIFIED BY readonly;
    SQL> GRANT CREATE SESSION ,CREATE SYNONYM TO readonly;
    SQL> GRANT SELECT ON SA.vCustomerService TO readonly;
    But when I connect to the database and do a select like:
    SQL> SELECT * FROM ACC;
    I get the data from that table, even if I do an update on that table it works.
    What am I doing wrong that my readonly user still has full acces on the other schema?
    Thanks in advance for your help!
    Best regards,
    GIL GOMES Dany

    Dan_lu wrote:
    Hello everybody,
    I created a readonly user like this in oracle 11g r2
    SQL> CREATE USER readonly IDENTIFIED BY readonly;
    SQL> GRANT CREATE SESSION ,CREATE SYNONYM TO readonly;
    SQL> GRANT SELECT ON SA.vCustomerService TO readonly;
    But when I connect to the database and do a select like:
    SQL> SELECT * FROM ACC;
    I get the data from that table, even if I do an update on that table it works.Check the permissions for that table -- maybe some operations on this table are granted to publc?

  • 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

Maybe you are looking for

  • Instrument I/O Assistant not installed correctly

    I've been troubleshooting this problem for over 2 weeks now and every response to this question that has found success I have tried, but was unable to fix the problem. in labView, double selecting the I/O Assistant it reads the infamous text "I I/O A

  • How to identify migrated rows on a table

    Hi, folks, I'm wondering how to identify migrated rows on a table. I understand that ANALYZE generates data into CHAINED_ROWS. The Oracle document implies that this table has both CHAINED ROWS and MIGRATED ROWS. FYI: http://download-west.oracle.com/d

  • Sending empty files using SFTP Adapter

    I am trying to send empty files using SFTP adapter. The interface has to send the file whether its empty file or containing data using SFTP adapter. I am using BizTalk Server 2013 R2. Is it a bug or the hotfix is already there for this issue.

  • Problem with my Thread

    MainProgram Thread1->named th does some process Thread2->ProgressBar where i have this code while(th.isAlive()) Thread.sleep(4000); My program is stuck up in the above loop. Eventhough thread1 and thread2 are independent,thread one is never dead. Onc

  • How to implement Security Domains with Delegated Management

    Hello, I have read the GlobalPlatform docs and 'scoured' the Internet for some useful advice on how to implement DM with Java Card. The GlobalPlatform docs say that "The interface between a SD and the Card Manager is not defined by Open Platform" and