DDL to execute ?

Hi
oracle 10.2.0.1.0
I have created a view on table as
create table try_table ( sno number);
create or replace view try_table_vw as select * from try_table;When I alter the table and select/ desc the view then new coluymn is nt reflected until I recreate the view .
select * from try_table_vw;
desc try_table_vw;
alter table try_table add ( name varchar2(20));Is it that when ever DDL changes I need to create or replace the view definition ???

SQL> DESC emp_test
Name                                      Null?    Type
EMPNO                                              NUMBER(4)
ENAME                                              VARCHAR2(10)
JOB                                                VARCHAR2(9)
MGR                                                NUMBER(4)
HIREDATE                                           DATE
SAL                                                NUMBER(7,2)
COMM                                               NUMBER(7,2)
DEPTNO                                             NUMBER(2)
SQL> CREATE OR REPLACE VIEW emp_test_view AS SELECT * FROM emp_test;
View created.
SQL> /* Now checking My view status */
SQL> SELECT object_name,status FROM user_objects
  2  WHERE object_name='EMP_TEST_VIEW';
OBJECT_NAME
STATUS
EMP_TEST_VIEW
VALID
SQL> /* Although, I have created it as SELECT * FROM ...., I want to see
DOC>    How Oracle has stored the definition */
SQL> set line 1000
SQL> set long 1000000
SQL> SELECT view_name,text FROM user_views
  2  WHERE view_name='EMP_TEST_VIEW';
VIEW_NAME                      TEXT
EMP_TEST_VIEW                  SELECT "EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO" FROM emp_tes
                               t
SQL> /* So, it has stored it as all the column names, not as SELECT *..... */
SQL> /* So, If I add a column to this table, this definition will not be updated autometicaly
DOC>    and SELECT * FROM view_name will show all the old columns */
SQL> ALTER TABLE emp_test ADD dummy VARCHAR2(1);
Table altered.
SQL> desc emp_test
Name                                                                                                                  
EMPNO                                                                                                                 
ENAME                                                                                                                 
JOB                                                                                                                   
MGR                                                                                                                   
HIREDATE                                                                                                              
SAL                                                                                                                   
COMM                                                                                                                  
DEPTNO                                                                                                                
DUMMY                                                                                                                 
SQL> SELECT view_name,text FROM user_views
  2  WHERE view_name='EMP_TEST_VIEW';
VIEW_NAME                      TEXT
EMP_TEST_VIEW                  SELECT "EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO" FROM emp_tes
                               t
SQL> SELECT * FROM emp_test_view WHERE rownum<3;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
SQL> /* Now, again We are re-creating the view */
SQL>  CREATE OR REPLACE VIEW emp_test_view AS SELECT * FROM emp_test;
View created.
SQL> SELECT view_name,text FROM user_views
  2  WHERE view_name='EMP_TEST_VIEW';
VIEW_NAME                      TEXT
EMP_TEST_VIEW                  SELECT "EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO","DUMMY" FROM
                                emp_test
SQL> /* Now, you can see the definition got updated and successive SELECETs can retrive the new column value */
SQL>

Similar Messages

  • See the detalis of DDL commands executing on oracle 10g

    Hi,
    how can i see the detail of DDL command executed on oracle 10g on ECC 6.0
    ECC 6.0
    HPUX
    Regards,

    Did you activated the auditing mechanish on the Oracle? If it is active, you can query the audit table;
    select * from sys.aud$;
    Another way is using Oracle Log Miner. You can find the related information, on the link below;
    http://docs.oracle.com/cd/B10501_01/server.920/a96521/logminer.htm
    Best regards,
    Orkun Gedik

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • EXECUTE IMMEDIATE - DDL

    Can someone explain the reason for why oracle doesnt allow DDL statements to be executed directly in a PL/SQL block?

    DDL statements execute an implicit commit before the statement is executed, and the statement itself is also automatically committed.
    A pl/sql procedure typically should comprise one logical unit of work.
    Both executing DDL and committing every individual record must be considered extreemly poor practice, resulting from brainwashing by the Evil Empire, aka Microsoft, where this is required because the concurrency model is completely different (and unelegant).
    So, if you want to stop being a Ringwraith of Sauron, aka William H Gates III, or his amanuensis Saruman, aka Stephen Ballmer, please never ever issue DDL through a stored procedure.
    Sybrand Bakker
    Senior Oracle DBA

  • Problems using DDL & EXECUTE IMMEDIATE in package

    Hi...
    I have an 8i package in which I am trying to execute some DDL via EXECUTE IMMEDIATE to create temporary tables from which I then populate a REF_CURSOR by selecting from the last table created in the DDL. The problem is that the compiler doesn't seem to like the DDL.
    Here's what I'm using:
    CREATE OR REPLACE PACKAGE BODY NEREP_REF
    AS
    Procedure GetNE_REF (
    i_Node IN VARCHAR2,
    io_cursor IN OUT t_cursor )
    IS
    sql_stmt varchar2(200);
    v_cursor t_cursor;
    BEGIN
    sql_stmt := 'CREATE TABLE tmp AS SELECT * FROM nerep4;';
    EXECUTE IMMEDIATE sql_stmt;
    OPEN v_cursor FOR
    SELECT NE_Node, NE_Type, EHA, Status, Curr_Func, TP_Name,
    Order_Item_Name, Required_Start, Required_End, Trail_Name
    FROM tmp
    WHERE NE_Node = i_Node ;
    io_cursor := v_cursor;
    END GetNE_REF;
    END NEREP_REF;
    The problem is that when I compile the package I get the errors below:
    SQL> @sp_nerep_body
    Warning: Package Body created with compilation errors.
    SQL> show err
    Errors for PACKAGE BODY NEREP_REF:
    LINE/COL ERROR
    20/7 PL/SQL: SQL Statement ignored
    23/14 PLS-00201: identifier 'NE_NODE' must be declared
    So it seems that it doesn't like the DDL (have I got the sql_stmt assignment in the wrong place maybe?) and then it complains it can't find the columns, which is reasonable because of course it doesn't know that the table 'tmp' comes from the result of the DDL statement!
    If I change the table name in the 'OPEN v_cursor FOR' select clause to a table that already exists (ie: not created in this package) it runs just fine and I get the data I asked for... the problem is that I need to create this table on the fly by using DDL in my package!
    This is driving me crazy - basically I need to be able to execute DDL to do various 'create table ... as select ... from ...' statements which eventually builds a final table which I then want to populate using a REF_CURSOR so I can return the results back to ASP via ADO... but I just can't get the DDL bit to work no matter what I try!!
    Can anyone see what I'm doing wrong here?
    Mike.
    null

    Here are a some ideas to try:
    Remove the extra semicolon from your sql_stmt, so that line reads:
    sql_stmt := 'CREATE TABLE tmp AS SELECT * FROM nerep4';
    Ensure that you have proper privileges as an individual user, not just through a role, by:
    connecting to the database using username system and password manager and granting yourself the proper privileges. For example, if you are user SCOTT, then:
    SQL> GRANT CREATE TABLE TO SCOTT;
    Then, exit and connect as yourself and try to compile and execute your procedure again.
    If that still doesn't work, try testing one little piece at a time until you can identify the part that causes trouble. For example, start with a procedure that does nothing but try to create the tmp table using execute immediate, then add the other pieces, then try to put the procedure in a package.

  • Which performance view ddl locate?

    SQL> create table houyichong(hello varchar2(100));
    SQL> insert into houyichong values('hello oracle');
    SQL> commit;
    SQL> select sql_text from v$sqlarea where sql_text like '%houyichong%';
    SQL_TEXT
    insert into houyichong values('hello oracle')
    select sql_text from v$sqlarea where sql_text like '%houyichong%'
    not find dd:l create table houyichong(hello varchar2(100));
    why?and where i can find the ddl just executed?

    938261 wrote:
    SQL> create table houyichong(hello varchar2(100));
    SQL> insert into houyichong values('hello oracle');
    SQL> commit;
    SQL> select sql_text from v$sqlarea where sql_text like '%houyichong%';
    SQL_TEXT
    insert into houyichong values('hello oracle')
    select sql_text from v$sqlarea where sql_text like '%houyichong%'
    not find dd:l create table houyichong(hello varchar2(100));
    why?and where i can find the ddl just executed?TABLE_NAME defaults to be UPPERCASE?

  • DDL - locking problem

    I am using Oracle 9i database on Windows 2000 server. I am facing extreme difficulty in running DDL commands, when trying to alter tables.
    A form is using a table xyz, and i have opened the form in developer 6i, then made some cosmetic changes and then saved and closed the fmb file.
    Now when I am trying to add a column in the same table, it goes into a hang. If I exit forms builder (i.e. disconnect from the connection which had once used that table), the DDL quickly executes. Similar is the problem when trying to drop/create/alter triggers.
    I am unable to figure out why Oracle has locked the object which was being referred in the form. I am facing severe problems at the customer site, when we make modifications to the production database, and when trying to replicate the schema changes in the live database, all the users have to be logged out (including exiting the report background engine!!) for the DDL execution to take place.
    In case somebody has faced this problem, or if aware of the cause/remedy, pls reply.
    Thanks in advance

    I think it is a privilege issue. I can run that statement without problems when I connect with near dba permissions on 9iR2 and 10gXE, but it gives the same error when I execute under a normal user.

  • Blocking DDL Queries Across Schemas

    I am experiencing a problem where DDL queries executed on two different schemas seem to be blocking each other and hence taking longer time to execute. If they are not executed in parallel they complete within the expected time.
    What pointers should I research or look upon?
    P.S - We are using 64 bit Oracle 11gr2 Standard Edition RAC server.

    You are saying that parallel execution of DDL queries are blocking each other user request; so as Sb has said, post your DDL queries, how and when you are running DDL queries, what error you are getting; i mean provide us more information as much as you can (because none of here are able to see your monitor, what exactly you are doing and what exactly oracle is saying) etc. There are many ready made SQLs available on this forum and/or google by just search with this forum or google, post your effort to get the solution then we will try our best to give you solution.
    Not something like, "Doctor (forum members), today i am not feeling well (DDL queries are blocking each other), please give me some medicine (some sql to solve the question)"
    Regards
    Girish Sharma

  • Transaction issue with DDL

    Is it true that you'll get error trying to execute DDL to a certain table if there's an active transaction to that table? take a look at this case:
    insert into t1 values(1,2,3)
    drop table t1as you can see, I havent' commited yet, so the transaction to t1 should still be active.
    I tried opening a new session in SQL Developer just to confirm that the DML insert hasn't been committed yet
    select * from t1and yes, it returned no rows.
    I was expecting error, but the
    drop table t1didn't produce any error. It executed succesfully. Am I missing something? thanks

    You would need to do the INSERT and the DROP in two different sessions in order to generate an error (ORA-00054: resource busy and acquire with NOWAIT specified).
    DDL does an implicit commit before and after the DDL is executed. So your DROP statement first commits the INSERT then drops the table and finally issues another commit. That doesn't generate any errors because by the time the table is dropped, there is no active transaction. Additionally, even if there was an active transaction, the you'll never get an error waiting for a lock that your session already has. Since locks are held by the session, different statements in the same session cannot block each other.
    Justin

  • How does Oracle process DDL w/ refs to yet created objects?

    If I have DDL for four procedures in one file, say ProcA ProcB ProcC and ProcD.
    ProcA references ProcD
    ProcB references ProcC
    How does Oracle compile ProcA and ProcB if the order of the DDL in the file is like above.
    Meaning ProcA and ProcB are compiled and ProcC and ProcD have yet to be created?

    That's a fundamental problem with standalone procedures/functions - with any dependencies, you will have invalid objects after the initial pass. However, those procedures will be automatically recompiled as soon as executed.
    If these four procedures were in a package, there would be no compilation dependency issues at all. Exactly what my knowledge told me.
    What if it was concerning packages and a procedure in PackageA calls a Procedure in PackageB and PackageA's DDL is execute first, what happens?

  • Ddl script

    Hi all,
    my publications has a dll script ( "CREATE TABLE ...." for creation of an off-line table); the first time client (WIN32 - WINXP-SP2) synchronizes the table is created, but every subsequent synchronization the client re-executes the script and generates warning.
    Is this a correct behavior of oracle Lite?
    Thanks

    I get this whenever I update the schema. Meaning I altered (add/drop/modify) a publication item. My DDL scripts execute again, but since there are no DROP statements issued, then there usually isn't an issue.

  • Problem dequeueing even with sys privilege - DEQUEUE ANY

    On one database instance we are seeing this; Connected user has DEQUEUE ANY sys privileges;
    However, a dequeue fails saying insufficient privileges; This works on other database instances?
    Any ideas? This is with database - (10.2.0.3.0 - 64bit Production)
    Thanks
    Vijay
    SQL> select * from USER_SYS_PRIVS;
    USERNAME PRIVILEGE ADM
    PUBLIC DEQUEUE ANY QUEUE NO
    PUBLIC ENQUEUE ANY QUEUE NO
    PUBLIC DEBUG CONNECT SESSION NO
    PUBLIC DEBUG ANY PROCEDURE NO
    PUBLIC SELECT ANY DICTIONARY NO
    6 rows selected.
    SQL> DECLARE
    2 dOpt dbms_aq.DEQUEUE_OPTIONS_T;
    3 mprop dbms_aq.message_properties_t;
    4 deq_msgid RAW(16);
    5 payLoadData MyPayload;
    6 BEGIN
    7
    8 dOpt.wait := 1;
    9
    10
    11 dbms_aq.dequeue(
    12 queue_name => 'MyQueue',
    13 dequeue_options => dOpt,
    14 message_properties => mprop,
    15 payload => payLoadData,
    16 msgid => deq_msgid);
    17
    18 END;
    19 /
    DECLARE
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_AQ", line 335
    ORA-06512: at line 11
    SQL>

    Thanks for the comment;
    I don't think this is a design flaw; Design is such that queues are owned by a separate
    schema user; Our install/upgrade architecture requires that the DDL be executed by
    a separate user. This prevents me from granting object level privileges on the queues
    because they have to be granted as the owner of the queue; I get around that by
    granting "DEQUEUE ANY QUEUE" sys privilege which can be granted by a non
    queue object owner (by SYS or DBA).
    See this related topic.
    Granting queue privileges as a DBA user to queues not owned by DBA
    Also, if this was a design flaw, then why would it work on other database instances?
    The fact that I am granting "DEQUEUE ANY QUEUE" to PUBLIC should be sufficient for
    any database user to dequeue the message.

  • Help to make this dynamic sql work

    Hi,
    I have many DDLs to execute and these DDLs change over time, so I try to load these DDLs into a table (y) and write a proc to loop through them. But I run into some problems and need your help.
    Here are the details:
    create table y ( x varchar2(4000));
    CREATE TABLE error_log (
    error_log_ID NUMBER(20),
    statement VARCHAR2(2000),
    error_msg VARCHAR2(400),
    Action VARCHAR2(16)
    CREATE SEQUENCE SEQ_error_log
    START WITH 1
    INCREMENT BY 1
    NOMINVALUE
    NOMAXVALUE
    NOCYCLE
    CACHE 20
    NOORDER
    CREATE OR REPLACE PROCEDURE CUST_UPDATE1 (
    schema_name IN VARCHAR2 ,
    table_tablespcae_name IN VARCHAR2,
    index_tablespcae_name IN VARCHAR2
    ) AS
    v_code NUMBER;
    v_errm VARCHAR2(400);
    sql_stmt1 VARCHAR2(3000) ;
    CURSOR c1 IS SELECT x FROM y;
    BEGIN
    FOR i IN c1 LOOP
    sql_stmt1 := i.x;
    DBMS_OUTPUT.PUT_LINE ( 'x = '|| sql_stmt1 );
    / **************************** worked if use this hard coded ********************************
    sql_stmt1 := 'CREATE TABLE '||schema_name||'.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE '|| table_tablespcae_name;
    BEGIN
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHEN OTHERS THEN
    v_code := SQLCODE;
    v_errm := SUBSTR(SQLERRM, 1 , 400);
    INSERT INTO error_log VALUES ( SEQ_error_log.nextval, sql_stmt1, v_errm, DECODE(v_code, -1430, 'IGNORE', 'CHECK') );
    END;
    END LOOP;
    END;
    Test:
    exec cust_update1('SCOTT', 'USERS', 'c'); -- didn't use last parameter
    Senario 1. insert into y values (
    'CREATE TABLE schema_name.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE table_tablespcae_name ' );
    ===> error_log show: ORA-01918: user 'SCHEMA_NAME' does not exist
    Senario 2. insert into y values (
    '''CREATE TABLE ''||schema_name||''.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE ''|| table_tablespcae_name' );
    ==> error_log show: ORA-00900: invalid SQL statement
    3. I hard coded the exact dynamic from step 2 and assigned to sql_stmt1, ( as commeted out in my code) it WORKED.
    Thanks
    George

    hi,
    do the scenario1 but you have to substitute the schema_name and table_space name with your actual string before calling the dynamic sql.
    ei.
    sql_stmt1 := replace(sql_stmt1,'schema_name',schema_name);
    sql_stmt1 := replace(sql_stmt1,'table_tablespcae_name',table_tablespcae_name);
    BEGIN
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHEN OTHERS THEN
    v_code := SQLCODE;
    v_errm := SUBSTR(SQLERRM, 1 , 400);
    INSERT INTO error_log VALUES ( SEQ_error_log.nextval, sql_stmt1, v_errm, DECODE(v_code, -1430, 'IGNORE', 'CHECK') );
    END;
    Cheers,
    J

  • Help with creating a sql file that will capture any database table changes.

    We are in the process of creating DROP/Create tables, and using exp/imp data into the tables (the data is in flat files).
    Our client is bit curious to work with. They do the alterations to their database (change the layout, change the datatype, drops tables) without our knowing. This has created a hell lot of issues with us.
    Is there a way that we can create a sql script which can capture any table changes on the database, so that when the client trys to execute imp batch file, the sql file should first check to see if any changes are made. If made, then it should stop execution and give an error message.
    Any help/suggestions would be highly appreciable.
    Thanks,

    Just to clarify...
    1. DDL commands are like CREATE, DROP, ALTER. (These are different than DML commands - INSERT, UPDATE, DELETE).
    2. The DDL trigger is created at the database level, not on each table. You only need one DDL trigger.
    3. You can choose the DDL commands for which you want the trigger to fire (probably, you'll want CREATE, DROP, ALTER, at a minimum).
    4. The DDL trigger only fires when one of these DDL commands is run.
    Whether you have 50 tables or 50,000 tables is not significant to performance in this context.
    What's signficant is how often you'll be executing the DDL commands on which the trigger is set to fire and whether the DDL commands execute in acceptable time with the trigger in place.

  • First-time connection to HSQLDB

    I'm attempting a connection to HSQLDB, but have some questions about making the connection without an existing database.
    In the connection URL, the last part is supposed to be a URL to a database, but nothing currently exists. Additionally, the username and password both do not exist yet because the database doesn't.
    Must a database be created in advance of connecting to it? (I would guess no because then how would in-memory databases work?) If not, what should I enter in the username, password, and connection URL to make this work?
    Thanks.

    And since I had to create this example for other purposes earlier on, you get it at no extra charge :-)
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class SimpleHsqlDbExample {
       public static void main(String[] args)
          throws Exception
          System.out.println("Preparing connection");
          Class.forName(DRIVER);
          Connection conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);     
          Statement stat = conn.createStatement();
          System.out.println("Issuing DDL");
          stat.execute(CREATE_TABLE);
          stat.close();
          System.out.println("Creating content");
          PreparedStatement ps = conn.prepareStatement(CREATE_CONTENT);
          for(int i = 0; i < 100; i++) {
             ps.setInt(1,i);
             ps.setString(2,"Example content: " + i);
             ps.executeUpdate();
          ps.close();
          System.out.println("Acquiring the data");
          ps = conn.prepareStatement(SELECT_CONTENT);
          ps.setInt(1,42);
          ResultSet rs = ps.executeQuery();
          while(rs.next()) {
             System.out.println("Retrieved data (" + rs.getString(1) + ")");
          conn.close();
          System.out.println("Done.");     
       private static final String URL = "jdbc:hsqldb:file:sprocdb;SHUTDOWN=true";
       private static final String DRIVER = "org.hsqldb.jdbcDriver";
       private static final String USERNAME = "sa";
       private static final String PASSWORD = "";
       private static final String CREATE_TABLE = "CREATE TABLE example (id integer primary key, content varchar(32) not null)";
       private static final String CREATE_CONTENT = "INSERT INTO example(id,content) VALUES (?,?)";
       private static final String SELECT_CONTENT = "SELECT content FROM example WHERE id = ?";
    }

Maybe you are looking for