EXECUTE sql file in an procedure,just like sql prompt.

Hi,
I am using ORACLE 11g on an AIX box.
Just to explain first :- Assume we have an .sql file in which i have 20 DML statements. Like 10 inserts,5 updates and 5 deletes. Now if i want to run this file in any particular DB , the best thing for one file i can do is .. simply go to the prompt i.e. SQL> on that DB and run that file :-
SQL>@/oracle/scripts/metadata_update.sql
just this will execute the whole file. Also here i can spool and keep the log of execution.
Now i want the same functionality but this time their are many files and and i have to run them on different DB's.
Can anyone suggest me some code in which if i pass the filename and the DB's name .. it should execute in that DB and create a log file in the same directory as the sql file.
Something like procedure, which will take file name and DB name as parameter
and then we will read file using UTL_FILE
and then go to the destination DB with the help of TNSENTRIES we have.
execute it and store the log for the same.
Please suggest some sample code or ideas.
thanks in advance.

VIRU wrote:
Our team gets those scripts on regular basis. We need to apply them on different DB's around 4 of them.
So i wanted a utility by which i can apply it from one procedure.PL/SQL is wrong tool for this job.
When your only tool is a hammer, all problems are viewed as nails.
While a hammer is a GREAT tool, it is suboptimal to divide 1 board into 2 pieces
sqlplus user/pass@remote1 @new_script.sql
sqlplus user/pass@remote2 @new_script.sql
sqlplus user/pass@remote3 @new_script.sql
sqlplus user/pass@remote4 @new_script.sql

Similar Messages

  • How to execute .sql file in Stored Procedure?

    Hi,
    I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
    This .sql file will have set of update statement. I need to pass value to this update statement.
    Kindly please help me.
    Regards,
    Irfan

    This is required as part of Data Migration where  i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
    How have you determined that it's "better" to have seperate scripts?  I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
    So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
    Question: Why do you have tables with different names that all need the same process doing to them?
    Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
    e.g.
    create procedure update_table(tbl_name varchar2) is
    begin
      execute immediate 'update '||tbl_name||' set lastupdate = null';
    end;
    As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer.  Please do take the time to read the FAQ and post appropriate details so people can help you.

  • How do I create video files in M4V format just like iTunes video clips?

    Hello everyone,
    I have bought many video clips from iTunes which I like to play when I have invited guests.
    Now, as you know, some video clips are not available on iTunes. I do have some music DVDs though and would like to add some video clips from the DVDs to my iTunes library. I converted them to the M4V format. However, the format still seems to be different from the format that iTunes uses for its music video clips. Because when I add a video bought from the iTunes store AND one of my own videos in a playlist, iTunes tells me that it is not usual to mix videos and music in the same playlist.
    Does anyone have a suggestion how I can create the same format for the videos I get from my DVDs, so that I can mix them in the same playlist together?
    Thanks for your help!

    Umm... has anyone pondered a situation for a days if not weeks on end before mustering up the courage to ask for help and then found the solution minutes after asking? Yeah, this is one of those occasions. Weird.
    In my defense, the user interface seems a bit obtuse. When you click "Playlists" and then "Create Playlist" at the bottom of the screen you then must click "Dates, "Folders", or "All Videos" to search for videos. The "obtusity" is that it didn't seem intuitive to me that I then had to search in those other headings after I selected to create a playlist. I assumed that the "Create a Playlist" window that then popped up would include all videos in the watched folders. When you see a video you will find that there is a green circle with a plus sign on the upper right corner. Clicking that will add it to the playlist that you are creating. When you're satisfied with the playlist, give it a name and then save it.
    *sigh* 
    Message Edited by BetaPsi on 06-10-2009 01:35 PM

  • Error while executing Multiple Stored Procedure through .sql file

    Hi Guru's.
    I am new to ORACLE. I am facing problem while creating Stored Procedure through .sql file.
    I have one test.sql file with Stored Procedure is like,
    CREATE OR REPLACE PROCEDURE skeleton1
    AS
    BEGIN
         DBMS_Output.Put_Line('skeleton1');
    END skeleton1;
    CREATE OR REPLACE PROCEDURE skeleton2
    AS
    BEGIN
         DBMS_Output.Put_Line('skeleton2');
    END skeleton2;
    Now when i try to execute this test.sql file through SQL PLUS it gives me Error like this
    I am opening test.sql file from SQL PLUS,
    SQL>
    1 CREATE OR REPLACE PROCEDURE skeleton1
    2 AS
    3 BEGIN
    4 DBMS_Output.Put_Line('skeleton1');
    5 END skeleton1;
    6 /
    7 CREATE OR REPLACE PROCEDURE skeleton2
    8 AS
    9 BEGIN
    10 DBMS_Output.Put_Line('skeleton2');
    11* END skeleton2;
    SQL> /
    Warning: Procedure created with compilation errors.
    SQL> show errors;
    Errors for PROCEDURE SKELETON1:
    LINE/COL ERROR
    6/1 PLS-00103: Encountered the symbol "/"
    SQL>
    Please suggest how to create multiple CREATE PROCEDURE using single .sql script file....
    Regards,
    Shatrughan

    Hi,
    Try this
    CREATE OR REPLACE PROCEDURE skeleton1
    AS
    BEGIN
    DBMS_Output.Put_Line('skeleton1');
    END ;
    CREATE OR REPLACE PROCEDURE skeleton2
    AS
    BEGIN
    DBMS_Output.Put_Line('skeleton2');
    END;
    /Save the file and call it.
    Regards,
    Bhushan

  • Dynamically calling a .SQL file

    hi,
    How to execute a procedure which is calling another sql file where the name of the SQL file am getting dynamically.
    strtoexec := 'begin '||'@'''||fullfilepath||'''; end; ';
    execute immediate strtoexec.
    plz advice.

    Bluntly put. What are you are attempting to design and code is wrong. Period.
    Two primary reaons.
    1. One DOES NOT call SQL script files from PL/SQL (even it this was as easy as you seem to think).
    SQL code and PL/SQL code must reside INSIDE Oracle. Not outside.
    2. Your .SQL files will contain 1000's (if not more) non-sharable SQL statements.
    What does non-sharable SQL do?
    - fragments the shared pool, leading to memory allocation (malloc) errors
    - significantly impact on performance
    According to world renown experts like Tom Kyte (see http://asktom.oracle.com) non-sharable SQL is the #1 reason for poor Oracle performance.
    I have a test case where I showed our developers that running a 100,000 SQL SELECT statements using non-sharable SQL versus sharable SQL (bind variables) results in:
    100,000 exec's of a single row select not using bind variables = 24 minutes elapsed time
    100,000 exec's of a single row select using bind variables = 8 seconds
    The same SQL statement. Only difference - is it sharable (using bind vars) or not?
    So reconsider your design. It is flawed. It can result in Oracle memory errors. It is slow. It cannot scale.
    There's no place in Oracle for hacking stuff. Not if you expect performance, scalability, robustness, data integrity, concurrency, and all that good stuff that Oracle does so well.

  • Parse oracle sql file

    Good day.
    I need to develope little app for executing *.sql files.
    How can I parse sql file to retrieve oracle response for each statement while executing. (ex. sqlplus)??

    Good day.
    I need to develope little app for executing *.sql files.
    How can I parse sql file to retrieve oracle response for each statement while executing. (ex. sqlplus)??

  • Compare SQL file tables as a file content VS Documentum or Alfresco

    Hello - Documentum & Alfresco are 2 examples of Document Content Management (file repository, workflows, notifications, etc), I am interesting in the file content management where system provides file repository and some extra features like check in
    / check out and versioning. Does anyone have tried to replace a file repository with SQL file tables?

    You can use SQL Filetables for storing files as well as doing modifcations etc. for getting versioning you can enable change management or implement audit triggers in them.
    Here are some helpful links
    http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
    http://visakhm.blogspot.in/2012/07/triggers-on-filetables-in-sql-2012.html
    http://visakhm.blogspot.in/2013/09/implementing-transaction-over-file.html
    Check in checkout will not be available by default. You may need to implement it using some flags. My question is why cant you go for a versioncontrol software then like TFS? why reinvent the wheel?
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to run the .sql file in sql prompt?

    i want to run the .sql file in sql prompt

    Hi,
    You can navigate to the directory where the .sql files is stored and launch the SQL Prompt.
    After you login, you can run your script like this :
    SQL>@my_script.sql;
    Regards,
    Sandeep

  • How to execute a script(.sql) file from a PL\SQL procedure

    I would like to know how to execute a .sql file from a stored procedure and the result of it should update a table. My .sql file contains select statements.

    Hi!
    just go through the following piece of code -
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    str varchar2(200);
      3  begin
      4    str := '@C:\RND\Oracle\Misc\b.sql';
      5    execute immediate(str);
      6* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 5ORA-00900: invalid SQL statement
    Cause: The statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.
    Action: Correct the syntax or install the Procedural Option.
    Regards.
    Satyaki De.

  • File Ownership while executing sql script from stored procedure

    We have a test_command.sql script which is spooling the result into a file. From database we have one Store Procedure(run_sql) which is
    calling and executing the .sql script.
    When we are calling the sql script directly from the database, i e SQL > @/dccops/test_command.sql it is creating the
    file under the Ownership of OS user which is connected to the system.
    The problem we are facing is when we are executing the stored procedure i e exec run_sql(), the file is creating under
    Oracle User.
    Could u please suggest me a solution inorder to create the output file under the user who is logged to the OS.

    First of all, your usage of IM speak is NOT appreciated. Please do not address anyone as if they were a 12-year old.
    'Our Applcation is in C. So we have to call the procedure to run the sql script.'
    This is just utter nonsense!
    Oracle has Pro*C which allows Embedded SQL in C. There is also OCI (Oracle Call Interface) to call Oracle directly in C, and there is OCCI, to do the same in C++.
    Apart from that, Oracle has Ole DB for Windows platforms, to allow for a .NET compatible interface to Oracle.
    There is NO NEED AT ALL to call PL/SQL to run a SQL script.
    Sybrand Bakker
    Senior Oracle DBA

  • Executing multipule .sql files in Sequence

    Hi ,
    I am new to oracle world . I need to execute 150 .sql files from my local machine . I am trying do something like this ...
    but facing many errors ... I am using oracle 10 g
    Please advice me .
    CREATE OR REPLACE PROCEDURE MYPROC AS
    BEGIN
    DECLARE
    CNT NUMBER :=0;
         @c:\sql\1.sql;
    CNT:=CNT+1;
    @c:\sql\2.sql;
         CNT:=CNT+1;
         commit;
    EXCEPTION
    BEGIN
         ROLLBACK;
         DBMS_OUTPUT.PUT_LINE('TRANSACTION ROLLEDBACK')
         DBMS_OUTPUT.PUT_LINE('Failed at Executing' CNT-1)
    CNT:=0;
    END;
    END;
    END MYPROC

    user11791474 wrote:
    i need to create pl sql because if any of these files are errored then i need to terminate my execution . I guess just executing 15o sql files in one wrapper sql will keep executing next sql files.
    do you have any idea about how to call sql files in pl sql then ?No you can't call an sql*plus file in Pl/sql.
    What you can do in SQl*plus is someting like this:
    untested
    -- set an exit condition
    WHENEVER SQLERROR EXIT ROLLBACK
    spool logscripts.log
    prompt "running script 1"
    @script1.sql
    prompt "running script 2"
    @script2.sql
    prompt "running script 3"
    @script3.sql
    prompt "running script 5"
    @script4.sql
    prompt "running script 6"
    @script5.sql
    spool off

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • Oracle SQL Developer  error - "The file-based source procedure Name is not present in the database."

    I recently started working on the Oracle SQL developer. I have 'select' privileges on the QA schema and when tried to execute proc in QA. It is giving the error as 'The file-based source <procedure Name>  is not present in the database.  Was it compiled?'
    instead 'you do not have sufficient privileges to execute this procedure'. Did research on internet but with no luck.What configuration changes needed to be done to make it work.Guide me.

    Sounds like you do not have the correct privileges.  What should have been granted to you by the QA user, or some other user with appropriate privileges, is...
    grant EXECUTE on "QA"."<PROCEDURE_OF_INTEREST>" to "<YOUR_USERID>" ;
    Note that a grant of execute on a procedure has nothing to do with grants of select on some or all of QA's tables and views.
    So, as Vadim suggests, from your connection node in SQL Developer's Connections view, if you expand the Other Users node, then expand QA and look in the Procedures node, do you see the procedure of interest?  If not, you cannot expect to be able to execute it from your userid's connection. And even if you do see it, you may have some other privilege that permits viewing but not executing, like...
    The role SELECT_CATALOG_ROLE
    The system privilege SELECT ANY DICTIONARY
    And even if you do not see it there, then having certain other privileges granted to you could permit executing it in general, like...
    The role EXECUTE_CATALOG_ROLE
    The system privilege EXECUTE ANY PROCEDURE
    Also, note that the 3.0 release is a bit dated nowadays. Upgrading to 4.0.3 production or even the 4.1 EA2 (early adopter) release will, in general, give you a better experience.
    Best wishes,
    Gary

  • How to execute stored procedure in the SQL Commands page

    i'm oracle express edition newbie :) i have this stored procedure. it not belong to a package.
    create or replace procedure "LIST_MEMBERS"
    ("MEMBER_CUR" OUT SYS_REFCURSOR)
    is
    begin
    OPEN MEMBER_CUR FOR
    SELECT * FROM members;
    end;
    now, in the SQL Commands page, how to run the stored procedure and return the records. i do this:
    begin
    execute list_members();
    end;
    but i'm getting some errors. just need some immediate help :) thanks!!!

    Example of using a ref cursor:
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure open_cur(c IN OUT SYS_REFCURSOR) is
      2  begin
      3    open c for 'select rownum rn from dual connect by rownum <= 10';
      4* end;
    SQL> /
    Procedure created.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    c     SYS_REFCURSOR;
      3    v_val NUMBER;
      4  begin
      5    open_cur(c);
      6    loop
      7      fetch c INTO v_val;
      8      exit WHEN c%NOTFOUND;
      9      dbms_output.put_line(v_val);
    10    end loop;
    11    close c;
    12* end;
    SQL> /
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    PL/SQL procedure successfully completed.
    SQL>

  • Bat file execute all *.sql files in a folder

    Hi all,
    How to write a *.bat file to execute all *.sql files in a folder?
    Because have about 20 *.sql file in a folder. There are used to fix data in my database. The number of *.sql file increases day by day. So I want to write a *.bat file to execute all *.sql file in the folder. Since I just run this *.bat file.
    Mai Thanh Hải.

    user545846 wrote:
    Hi
    I have done this many times. can guide you. :)And did it fail to work all the times you tried it?
    c:\>type test1.sql
    select 1 from dual;
    exit
    c:\>type test2.sql
    select 2 from dual;
    exit
    c:\>sqlplus scott/tiger@testdb @c:\test*.sql
    SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:37:04 2009
    Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SP2-0556: Invalid file name.
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining optionsWildcards in SQL*Plus filenames don't work. So why do you suggest that?
    Better is to use the DOS command FOR...
    c:\>for %i in (test*.sql) do sqlplus scott/tiger@testdb @%i
    c:\>sqlplus scott/tiger@testdb @test1.sql
    SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
    Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
             1
             1
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    c:\>sqlplus scott/tiger@testdb @test2.sql
    SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
    Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
             2
             2
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    c:\>... although even better would be to proceduralise the SQL into packages/procedures on the database and have just a single procedure call do all the work.

Maybe you are looking for

  • Using Subquery in Prepared Statement

    can i use subquery in my insert using prepared statement need to specify the * property eg: insert into table1 values(select * from table2)

  • How to install / use fonts in OS X?

    I've downloaded a bunch of .pcf fonts, two .NFNT fonts, and some .bdf fonts. I read a bit online, saw that fonts go in ~/Libary/Fonts, so I dumped 'em into ~/Library/Fonts, and OS X doesn't recognize or allow me to select any of them from within Term

  • Having an issue printing in Adobe Reader XI

    I am trying to print a PDF that was created with Bluebeam in Adobe Reader XI.  When it prints the first page is fine but all following sheets are shift down and to the left.  This is the first time I have had this issue with a print created with Blue

  • How can I find the find pStreamName in access plug-in

    Hi all, I must rejected all users outside Denmark from our live streaming (c-ip) and this is done in an access plug-ins But now I need to open up one of the streams, but I can't get the streaming name in the access-plug-ins only in the Auth-plug-ins.

  • Selective redundancy compression of the user menu - per user

    Hi gurus, We would like to activate the redundancy compression of the user's role menus in the session manager. Problem is that some users have our new roles with the new menu structure, and others have the old lot still... In the new concept users h