Executes the DDL statement via ksh script

I need execute a DDL statement (for example, ALTER USER) using ksh script and capture the result to be able to verify whether the statement succeeded or failed.

I wrote a script below:

SQL = "test ALTER USER...;"

If sqlplus / as sysdba < < EOF > $MYFILE

whernever sqlerror exit 1 rollback

$sql

commit;

"exit";

EXPRESSIONS OF FOLKLORE

When I run the above script, I get 'modified by the user.  Commit complete. "written in a file.

Is there an easy way to check the contents of the file for the result to a variable instead of an output file or program to see if the ALTER USER statement was successful?

There is no need to check the contents of the file, just check for the error in your shell script.  Something like:

Oracle > cat t.sh
Export ORALCE_SID = dev2
SQL = "select 1/0 from dual;"
sqlplus-s / t.log
whenever sqlerror exit 1
$sql
output
EXPRESSIONS OF FOLKLORE
If [$?-no 0]; then
echo "an error has occurred."
FI

Oracle >. t.sh
An error has occurred

John

Tags: Database

Similar Questions

  • in the trial version that I wanted to try "photomerge" like on the video statement (via the expert mode, etc.). Is not available in the trial version?

    in the trial version that I wanted to try "photomerge" like on the video statement (via the expert mode, etc.). Is not available in the trial version?

    markn32062458 wrote:

    in the trial version that I wanted to try "photomerge" like on the video statement (via the expert mode, etc.). Is not available in the trial version?

    In PSE14, Photomerge has been moved to the 'guided changes' rather than the Expert mode.

    You can still access the same way in the Organizer: Edit menu > Photomerge.

  • How to execute the SQL statement in the Application Module

    Hi people
    I´d would like to know how I can execute a SQL statement like "remove user" in the Module to request... prepareSession method...
    I m using Jdev 10 with ADF Faces
    Thank you

    This is possible, but you should think twice about it.
    If this can be done with an EO/VO do in this way.
    If you can't do it with an EO/VO you can yourself the DB operation (ApplicationModule.getDBTransaction ()) and use a call of createStatement (...) do what you want.

    Timo

  • How to execute the sql statement in the file beats?

    I want to execute after the statement
    C:\ > sqlplus/nolog
    SQL > conn scott/tiger
    SQL > select * from tab;

    I know I can achieve it following test.bat and testdb.sql file
    test.bat is:
    sqlplus/nolog @testdb.sql

    TestDB.SQL is:
    Conn scott/tiger
    Select * from tab;

    Now I don't want to use the sql file, I want only use bat file, as follows:
    test.bat is:
    sqlplus/nolog
    Conn scott/tiger
    Select * from tab;

    When I run test.bat, I find only one sqlplus /nolog execute statement, do not execute other statements.
    (1) I want to know if there is a method to run the SQL file by fighting without a sql file? How to make it happen?
    (2) if I call the sql file, how to hide the password of user? Because I don't want other people to know scott password, if I use conn scott/tiger in testdb.sql, other person can see testdb.sql and the password. Is there a good way to avoid?

    Thank you!

    It works a bit different in Windows. Create a file is like this:

    (
      echo conn scott/tiger@orcl
      echo spool c:\temp\list.txt
      echo select sysdate from dual;
      echo spool off
      echo exit
    ) | sqlplus -s -l /nolog
    
  • How to set the properties of the graph XY via VI Scripting plots

    Hello

    Is there a way to change the properties of the graph XY plots in a VI script?

    Main VI, I create an XY chart in another VI in a VI script. Now, I want to change caption of the field names and their styles etc. I notice that these properties can be implemented in the new VI (see screenshot graph Node in NEW VI.jpg property). However, I could not see these properties by calling the property node of graphical reference XY main VI (see screenshot).

    Thanks for the reply due.

    Concerning

    HB

    Hello, HB,.

    Maybe you need to use a XYGraph refnum rather than a refnum graphChart.

    ULI

  • identity of the int, executing the ddl

    Hello!!!

    IM migration a DB2 database, but I can set my "identity" PKs of oracle 11g without a trigger function

    can anyone bring a solution to this problem?

    THX

    Kind regards!!!

    Published by: user13769506 on February 17, 2011 10:55

    No, I'm guees maybe I can tell me if oracle g11 have some love:
    PK identity (1) int
    where identity itds one data type!

    There is no such datatype in Oracle.
    We use NUMBER datatype populated of SEQUENCE via the TRIGGER before INSERT

  • request to execute the select statement conditionally

    Desire: when a variable is null then run a full report, if two variables are not null and then run the report with the specified range
    I have the following query, but kept getting an error sql invliad. Can you help me?

    -------------------
    IF (: P1_START_DATE IS NULL or: P1_END_DATE IS NULL)
    THEN SELECT ename, empno, mgr, hiredate from emp;
    ELSE IF (: P1_START_DATE IS NOT NULL and: P1_END_DATE IS NOT NULL)
    Select ename, empno, mgr, hiredate from emp where hiredate between: P1_START_DATE and: P1_END_DATE;
    end if;



    Tai

    Go only;

    select empno, ename, job, mgr, hiredate
    from emp
    where (:p1_start_date is null or :p1_end_date is null)
    or (:p1_start_date is not null and :p1_end_date is not null and
          hiredate between :p1_start_date and :p1_end_date);
    
  • cursor invalidation WITHOUT DDL statements

    Hi all.

    The BP is 11.2.0.3 on a linux machine.

    As we know, the ddl statements on database objects cause cursror invalidation.

    A number of invalidation of cursor WITHOUT means of ddl statements that pool is too small?

    Here is a part of the AWR report.

    Library Hit % is close to 100%, but I can find a number of invalidation of cursor in view v$ sql.

    What could cause invalidation of cursor except ddl statements?

    Instance Efficiency Percentages (Target 100%) 
    
    Buffer Nowait %: 100.00 Redo NoWait %: 99.99 
    Buffer Hit %: 99.39 In-memory Sort %: 100.00 
    Library Hit %: 100.02 Soft Parse %: 99.99 
    Execute to Parse %: 86.93 Latch Hit %: 99.39 
    Parse CPU to Parse Elapsd %: 91.51 % Non-Parse CPU: 97.42 
    Thanks in advance.
    Best regards.

    869578 wrote:
    Hi all.

    The BP is 11.2.0.3 on a linux machine.

    A number of invalidation of cursor WITHOUT means of ddl statements that pool is too small?

    Which could cause refills, but not radiation.
    A possible cause of invalidations on your system could be the number of cursors of a parent child became too big.

    Here is a part of the AWR report.
    Library Hit % is close to 100%, but I can find a number of invalidation of cursor in view v$ sql.

    The part of the AWR library cache would be little relevant if you think you have a problem with the invalidations.
    The effectiveness of the instance is practically useless in the best of cases, http://jonathanlewis.wordpress.com/2006/12/27/analysing-statspack-2/ is not relevant in this case.

    Concerning
    Jonathan Lewis

  • Why is there a commit implied before and after execution of DDL statements

    Hi guys,.

    Please let me know why he didn't is committed before and after the execution of DDL statements implied?


    Kind regards
    Sushmita

    Helyos wrote:
    This is because Oracle has the design like that.

    Come on Helyos, which is somewhat a weak response. :)

    The reason is that it is foolish to update the structure of the database, while there are some missing data updates that have not been committed.

    Imagine having a column VARCHAR2 (50), which currently has data of size up to 20 characters.
    Someone (person A) Decides that it would be useful to change the table and reduce the size of the varchar2 column (20) instead.
    Before they do, a third party (person B) inserted data that are 30 characters in size, but not yet committed it.
    In regard to person B is concerned and that the Insert succeeded as they don't got no error message, and they continue on through their process until they reach a suitable to commit point.
    Person that has and then tries to modify the database to make varchar2 (20).

    If the database has allowed that to happen then the column would be varchar2 (20) and the uncommitted data is more, even if the insertion was successful. When person B is going to know about it? It would be wrong to tell them when they try and commit, because their operations have succeeded, so why commit would fail.

    In this case, because it's two different people, then the database will recognize there are transactions that are uncommitted on the table and don't let anyone B change it.

    If it was just one person doing the two things in the same session, then the data would be automatically validated, the executed alter and the person has indicated that they can change the database because it is (now) data over the size that they want to.

    It makes perfect sense to have the database in a consistent state of data before changes are made, so why a commit is issued in advance.

    Here's something I wrote the other day on the subject...

    DOF delivers a validation before performing the actual action
    As long as the DOF is syntactically ok (the parser is happy with it), then the validation is issued, even if the actual DDL cannot be performed for another reason.

    For example...

    We have a table with data in there...

    SQL> create table xtest as select rownum rn from dual;
    
    Table created.
    
    SQL> select * from xtest;
    
            RN
    ----------
             1
    

    We then delete the data but do not commit (demonstrated by the fact that we can roll it back)

    SQL> delete from xtest;
    
    1 row deleted.
    
    SQL> select * from xtest;
    
    no rows selected
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> select * from xtest;
    
            RN
    ----------
             1
    
    SQL> delete from xtest;
    
    1 row deleted.
    
    SQL> select * from xtest;
    
    no rows selected
    

    So now, our data are deleted, but not committed, what happens if we issue a DOF that is syntactically incorrect.

    SQL> alter tab xtest blah;
    alter tab xtest blah
          *
    ERROR at line 1:
    ORA-00940: invalid ALTER command
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> select * from xtest;
    
            RN
    ----------
             1
    

    ... data can always be restored. This is because the parser was not happy with the syntax of the DDL statement.

    So let's delete the data again, without commit and deliver a DOF that is syntactically correct, but cannot run for another reason (i.e. the database object it refers to does not exist)...

    SQL> delete from xtest;
    
    1 row deleted.
    
    SQL> select * from xtest;
    
    no rows selected
    
    SQL> truncate table bob;
    truncate table bob
                   *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> select * from xtest;
    
    no rows selected
    

    So, there we have it. Just because the statement is syntactically correct, the deletion of the data has been committed, even if the DOF could not be performed.

    It makes sense really, because if we intend to amend the definition of the database where the data is stored, it cannot take place unless the database is in a State where the data is where it should be instead of being in limbo. For example, imagine the confusion if you update data on a column and then changed the data type of columns to be of a different size, for example reducing a column varchar2 50 characters up to 20 characters. If you had data that had just updated you to more than 20 characters whereas previously it was not, then the alter table command cannot not on this subject, which could alter the size of the column and then the data would be invalid to adapt while the update at the time did not fail.

    For example...

    We have a table that allows only 20 characters in a column. If we try to insert them more in this column, you get an error for our insert as planned...

    SQL> create table xtest (x varchar2(20));
    
    Table created.
    
    SQL> insert into xtest values ('012345678901234567890123456789');
    insert into xtest values ('012345678901234567890123456789')
                              *
    ERROR at line 1:
    ORA-12899: value too large for column "SCOTT"."XTEST"."X" (actual: 30, maximum: 20)
    

    Now, if our table has allowed more character our insert statement are successful. As far as our 'application' is going to believe us, nay, we were told of the database, we have successfully introduced our data...

    SQL> alter table xtest modify (x varchar2(50));
    
    Table altered.
    
    SQL> insert into xtest values ('012345678901234567890123456789');
    
    1 row created.
    

    Now, if we tried to change our database column date back to 20 characters and it did not automatically the data beforehand then it would be happy to edit the column, but then when the data has been committed he wasn't. However the database has already told us that the data were inserted, so he can't go back to that now.

    Instead, we can see that the data be engaged first because the alter command returns an error telling us that the table data is too large, and also can not restore the insertion after the alter attempt...

    SQL> alter table xtest modify (x varchar2(20));
    alter table xtest modify (x varchar2(20))
                              *
    ERROR at line 1:
    ORA-01441: cannot decrease column length because some value is too big
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> select * from xtest;
    
    X
    --------------------------------------------------
    012345678901234567890123456789
    
    SQL>
    

    Of course, being a statement commit to the existing session, if we had tried to modify the column of the table to another session would have got us

    SQL> alter table xtest modify (x varchar2(20));
    alter table xtest modify (x varchar2(20))
    *
    ERROR at line 1:
    ORA-00054: resource busy and acquire with NOWAIT specified
    
    SQL>
    

    ... which is basically saying that we cannot change the table because someone else uses it and they did not commit their data still.

    Once the other session committed data, we obtain the expected error...

    ORA-01441: cannot decrease column length because some value is too big
    

    Hope that explains it

  • How the DDL triggers AFTER CHANGE of work?

    I thought that this general framework for DDL triggers AFTER WHAT ALTER has been like that:

    -Implicit VALIDATION before the DDL statement (here: ALTER TABLE)

    -DDL statement

    -Implicit VALIDATION after DDL statement (here: ALTER TABLE)

    -AFTER ALTER DDL trigger fires

    And I also thought that everything is inside that trigger would be 'new' code as introduced by the ALTER TABLE DDL. But it looks like I'm missing something about this situation because the trigger next dbms_metadata.get_ddl procedure and seeing 'old' DDL code (before the ALTER TABLE statement).

    What Miss me? Could you give me some advice about this behavior? If I shouldn't expect returned DDL 'current' so why should I not?

    Thank you

    / * everything is done in the SCOTT schema * /.

    create table y (col1 varchar2 (5));

    create table t (dt date default sysdate, d varchar2 (4000));

    create or replace trigger trg

    After ON ALTER scott. SCHEMA

    declare

    v_d varchar2 (4000);

    Start

    Select cast (dbms_metadata.get_ddl ('TABLE', sys.dictionary_obj_name, sys.dictionary_obj_owner) as varchar2 (4000))

    in v_d

    Double;

    insert into t (d) values (v_d);

    end;

    ALTER table add col2 int;

    Select * from t; -This is the 'old' DOF with only col1

    I understand the transaction consistent reading, and it would work if second implicit validation had not been published before a trigger has been activated... the question is: is this second implicit validation has published in the above situation or I'm wrong about this, and commit the transaction started by first implicit included relaxation itself, and after he performed the second commit implicit came into play...

    It looks like this for me, but I have not found anything in the doc Oracle stating explicitly that this is the case... Could you confirm?

    Hmmm - I found it in the section client events of the doc PL/SQL language

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/triggers.htm#g1722272

    The LOGON event starts a separate transaction and undertakes after firing the triggers. All the other events fire in the existing user transaction.

    Is the same with the AFTER DDL event where you thought to try this one.

    Why do you need the DOF immediately after it happens?

    Just capture the same and information of interest to a table. Then, later, asynchronously, run a job to get the DDL or everything that you need. The only "gotcha" If several ddl statements are issued against the table and you needed every one of them for some reason any. Not sure why you would need for each change.

  • Invoke the DDL after RAISE_APPLICATION_ERROR

    Is there a way to call the DDL statements below after I invoke the package 'triggered error '? In the Sub statement control does not go to the DDL statements, please notify

    EXCEPTION WHEN OTHERS THEN

    retval: = 1;

    RAISE_APPLICATION_ERROR (-20003, SQLERRM);

    RUN IMMEDIATELY 'ALTER TABLE CUSTOMER_LOAN_XREF ENABLE CONSTRAINT FK_CUSTOMER_LOAN_XREF_CUSTOMER;

    RUN IMMEDIATELY 'ALTER TABLE CUSTOMER_LOAN_XREF ENABLE CONSTRAINT FK_CUSTOMER_LOAN_XREF_LOAN;

    Thank you

    Ariean wrote:

    That would create an implicit validation of my transaction I want to avoid, please correct me if I'm wrong. Thank you

    For example, to create a procedure with pragma autonomous_transaction with

    RUN IMMEDIATELY 'ALTER TABLE CUSTOMER_LOAN_XREF ENABLE CONSTRAINT FK_CUSTOMER_LOAN_XREF_CUSTOMER;

    RUN IMMEDIATELY 'ALTER TABLE CUSTOMER_LOAN_XREF ENABLE CONSTRAINT FK_CUSTOMER_LOAN_XREF_LOAN;

    SY.

  • Question related to the INSERT statement

    Imagine this scenario:

    -table_a has 5 000 000 records at time t1

    -table_b is empty at time t1

    -At time t1, I execute the following statement:
              insert into table_b
                select * from table_a;
        
    -L' insert statement ends in time t2

    -Between t1 and t2, say 3 000 new records have been added to the table_a (by OLTP processes).
    Thus, at time t2, table_a has 5 003 000 records.

    My question is, at time t2, the number of records will be in table_b? Will it 5,000,000 or
    5 003 000 or somewhere between these two counts?

    I guess it will be 5,000,000 because that is the number when the insert statement
    has started to run.

    Any comment is appreciated.

    Syed Ullah says:
    Imagine this scenario:

    -table_a has 5 000 000 records at time t1

    -table_b is empty at time t1

    -At time t1, I execute the following statement:

    insert into table_b
    select * from table_a;
    

    -L' insert statement ends in time t2

    -Between t1 and t2, say 3 000 new records have been added to the table_a (by OLTP processes).
    Thus, at time t2, table_a has 5 003 000 records.

    My question is, at time t2, the number of records will be in table_b? Will it 5,000,000 or
    5 003 000 or somewhere between these two counts?

    I guess it will be 5,000,000 because that is the number when the insert statement
    has started to run.

    Any comment is appreciated.

    At time t2, it is possible that the answer is 0. Once the insert operation finishes (can be any time after t1 in your example, possibly before t2, possibly after) and assuming you checked in the same session where you run the insert, you would see 5 000 000. In other sessions you would continue to see 0 up to what the session who made the done insert one COMMIT.

    http://docs.Oracle.com/CD/E11882_01/server.112/e25789/consist.htm#CNCPT121

    Is something that you should read. He described these concepts much better than what you'll probably find in a few posts on the forum.

  • Text on the multi-state object disappears in Adobe Content Viewer

    I use InDesign CS5 to build folios for a tablet device. I created a slide show using a multi-state object. Also, I placed the text on top of the top image to indicate that it is a slide show. When I go to the Overlay creator to see a preview of the page in the Adobe, the text on the slide show content viewer disappears. Why is this happening?

    Guessing from your description, the text should be part of the first State of the ASM, and it isn't. You can add it to the first State via the MSO Panel.

  • the SQL statements used to create views

    Hello
    How can I see the full text (with table) to create a sql view:
    SQL> select text from dba_views where rownum=1;
    
    TEXT
    --------------------------------------------------------------------------------
    select "LIB_IDX","LIB_NAME","VENDOR_NAME","PROTOCOL_NUM","VERSION_NUM","PATH_NAM
    Thank you.

    Try the following in the SQL * faster before executing the SQL statement:

    SET LONG 1000
    

    If this does not work, increase it if necessary.

  • Update using a function in the select statement

    Hello

    Is it possible to do the follwing.

    I tabele and a custom function, the custome service will update the column (amount) of the table based on the value of going through the function of the select statement.

    SELECT id, stock, where an id = get_update (id);

    Now


    Get_update function will return the same id I'm passing and update the column amount to a value in the
    table a.

    When I run the satament selection I have the updated data in the column amount in my first executtion, but if execute the same statement, again, I see the changes reflected. is it possible to get data updates to the first performance himself.

    the function is of type PRAGMA AUTONOMOUS_TRANSACTION

    Concerning

    Indeed a strange requirement and probably not the way to go in a production environment. But anyway is a way to achieve your goal

    SQL> create table a
    as
       select   12 id, 500 amount from dual
       union all
       select   13 id, 600 amount from dual
    /
    Table created.
    
    SQL> create or replace type a_typ as object (id number, amount number)
    /
    Type created.
    
    SQL> create or replace function get_id (pid number)
       return a_typ
    is
       pragma autonomous_transaction;
       l_a_typ   a_typ := a_typ (null, null);
    begin
          update   a
             set   amount = 800
           where   id = pid
       returning   id, amount      into   l_a_typ.id, l_a_typ.amount;
    
       commit;
    
       return l_a_typ;
    end get_id;
    /
    Function created.
    
    SQL> select   id, d.a_typ.amount amount
      from   a, (select get_id (13) a_typ from dual) d
     where   id = d.a_typ.id
    /
            ID     AMOUNT
    ---------- ----------
            13        800
    1 row selected.
    

Maybe you are looking for