DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: How to run sql script from store procedure / or ajava

  1. #1
    Join Date
    May 2006
    Posts
    2

    How to run sql script from store procedure / or ajava

    Hi all....

    I need to run an script that contents creation table statement.

    I hope someone help.

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    why not put the create statements in the stored proc?

    you cant do it from plsql, you can do it from java if you wish

  3. #3
    Join Date
    May 2006
    Posts
    2

    not exactly...

    the promes is that the scrip file must content create table sentence or create procedure sentece or some like that... then I just want to run for example objetc.sql.... one time object.sql have create table another time object.sql have create trigger...

    I hope you help us.

  4. #4
    Join Date
    Jun 2005
    Location
    London, UK
    Posts
    159
    Stored procedures are not an ideal for installing applications. Normally a script is used.

  5. #5
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    and plsql cannot read a script file anyway, so you cant do what you want

  6. #6
    Join Date
    Apr 2006
    Posts
    377
    Quote Originally Posted by davey23uk
    and plsql cannot read a script file anyway, so you cant do what you want
    PL/SQL can actually read a script file, however in this case I think you may want to consider an external table or UTL_FILE to read the file from the O/S.

  7. #7
    Join Date
    Sep 2005
    Posts
    278
    The following Java class runs the SQLPLUS command through the OS.

    Code:
    create or replace and compile java source named script as
    import java.io.*;
    import java.util.*;
    
    public class Script{
    
    public static void run(String filename) throws IOException
    {
    	String [] Command = new String[2];
    
    	Command[0] = "sqlplus";
    	Command[1] = " @"+filename;
    
    	Process Findspace = Runtime.getRuntime().exec(Command);
    }
    }
    The wrapper function

    Code:
    create or replace procedure runSQLScript(filename varchar2)
    as language java
    name 'Script.run(java.lang.String)';
    --------contents of test.sql script can be----------

    scott/tiger@testdb
    set linesize 120

    create global temporary table temp_tab
    (col1 varchar2(10))
    on commit preserve rows;

    exit;
    ------------------------------------------------------
    --to execute the script
    ------------------------------------------------------
    exec runSQLScript('c:\test.sql');

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width