oracle anonymous block , unix shell script

Posted on 2014-08-06
Last Modified: 2014-08-18
How to run oracle anonymous block  through unix shell script.

I have created one anonymous block i.e.
v number:=9;
insert into a values (v);
end ;

I have created one sql file blk.sql  for above statement.

then i hve created 1 shell script

sqlplus us/Pwd@abc  @blk.sql

I have excueted the above shell script but data is not inserted into table.

Is it right way to call the sql block using @
Please help.
Question by:digs developer
    LVL 23

    Expert Comment

    Have you tried a redirect?

    sqlplus us/Pwd@abc < blk.sql

    Open in new window

    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Try a commit inside the block.
    LVL 22

    Expert Comment

    by:Steve Wales
    As written when you finish the SQLPlus statement, you don't automatically exit sqlplus.

    Are you querying the table from the same session or another session ?

    If the same session - the data is there.  I tested using exactly your statements as provided, and they work.

    From another session - you won't see anything, because you haven't committed the change to the database.  Issue a commit from the sqlplus prompt, or quit to commit the change to the database.

    To make it happen automatically, put "quit" in a line by itself in blk.sql after the "/"

    Author Comment

    by:digs developer
    I want to run 3 different anonymous blocks of files .
    sqlplus us/Pwd@abc  @blk_1.sql

    How can I run it? Please suggest.
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Either 3 sqlplus calls or create blk_all.sql with the contents:

    sqlplus us/Pwd@abc  @blk_all
    LVL 34

    Accepted Solution

    Another option:

    sqlplus us/Pwd@abc << EOF

    Open in new window


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
    Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
    This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
    This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now