Running a sql script from stored procedure

Hi everyone!
Has anybody tell me how to execute a sql script from a stored
procedure!
Thanks in advance!
Sasa

>
Hi everyone!
Has anybody tell me how to execute a .sql file from a stored
procedure!
Thanks in advance!
Sasa Sorry, a .sql file!!

Similar Messages

  • 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

  • Getting windows error during running the sql scripts from form 6i

    I made a little form application. The purpose of this application is to generate explain plan for a particular SQL. Some sql scripts run internally in order to populate the result on form’s screen after pressing the form’s button but I am getting windows error during running the sql scripts from form 6i.
    I am using forms 6i with patch 17 with Oracle 10G database on windows 2000 professional on same computer.
    This application runs fine with 8i.
    Please inform me where the problem is and how to overcome it.
    Zafri.

    I am using Text_IO in my form's when button press trigger , inorder to create the
    text file, then in the same when button press triger
    I am calling RMAN via host command in order to run the script which was created by text_IO.
    Below you find some of the code. I will appreciate if you solve the problem.
    when button press trigger:
    Declare
    in_file3 Text_IO.File_Type;
    linebuf3 VARCHAR2(1800);
    output11 varchar2(1000);
    BEGIN
         output11:='C:\EXPLAIN_PLUS\misc\rm_file.bat ';
    Host(output11,no_screen);
    :sql.execution_plan:= 'Working........................';
    synchronize;
    in_file3 := Text_IO.Fopen('c:\explain_plus\misc\create_table.txt', 'w');
    Text_IO.Put_Line(in_file3, linebuf3);
    Text_IO.put_line(in_file3,' ');
    Text_IO.put_line(in_file3,' run { sql "create table PLAN_TABLE (statement_id,...object_name varchar2(30),object_instance numeric,object_type varchar2(30),optimizer varchar2(255),search_columns number,id .....partition_start varchar2(255),partition_stop  varchar2(255),partition_id numeric,other long,distribution varchar2(30)) "; } ');
    Text_IO.put_line(in_file3,' ');
    Text_IO.put_line(in_file3,' ');
    Text_IO.FCLOSE(in_file3)
              Declare
    un VARCHAR2(80);
    pw VARCHAR2(80);
    cn VARCHAR2(80);
    output VARCHAR2(1000);
    output2 VARCHAR2(1000);
    dummy varchar2(40);
    in_file Text_IO.File_Type;
    linebuf VARCHAR2(1800);
    BEGIN
         Get_Connect_Info(un,pw,cn);
         /* for Plan_table Begg. Second INNER BLOCK */
         declare
              dummy2 varchar2(40);
         begin
         select table_name into dummy2 from all_tables where table_name='PLAN_TABLE';
         if dummy2 = 'PLAN_TABLE' then
         output2:='rman target/ nocatalog @C:\EXPLAIN_PLUS\MISC\TRUNC2.txt ' ;
    Host(output2,no_screen);
         end if;
         exception
         when no_data_found     then
    output2:='rman target/ nocatalog @C:\EXPLAIN_PLUS\misc\create_table.txt ';
    Host(output2,no_screen);
         end; --

  • Returning SQL cursor from Stored Procedure

    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..

    RP wrote:
    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
    First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
    In it's simplest form you would be creating a procedure along these lines...
    SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
      2  begin
      3    open p_rc for p_sql;
      4  end;
      5  /
    Procedure created.
    SQL> var rc refcursor;
    SQL> exec get_data('select empno, ename, deptno from emp', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc;
         EMPNO ENAME          DEPTNO
          7369 SMITH              20
          7499 ALLEN              30
          7521 WARD               30
          7566 JONES              20
          7654 MARTIN             30
          7698 BLAKE              30
          7782 CLARK              10
          7788 SCOTT              20
          7839 KING               10
          7844 TURNER             30
          7876 ADAMS              20
          7900 JAMES              30
          7902 FORD               20
          7934 MILLER             10
    14 rows selected.
    SQL> exec get_data('select deptno, dname from dept', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
            40 OPERATIONS
            50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
    Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
    SQL> select * from x;
    C
    A
    B
    C
    SQL> select * from y;
    C
    D
    E
    F
    SQL> ed
    Wrote file afiedt.buf
      1  select x.col1, x.col2, x.col3
      2        ,y.col1 as col4
      3        ,y.col2 as col5
      4        ,y.col3 as col6
      5  from (
      6        select max(decode(rn,1,col1)) as col1
      7              ,max(decode(rn,2,col1)) as col2
      8              ,max(decode(rn,3,col1)) as col3
      9        from (select col1, rownum rn from (select * from x order by col1))
    10       ) x
    11  cross join
    12       (
    13        select max(decode(rn,1,col1)) as col1
    14              ,max(decode(rn,2,col1)) as col2
    15              ,max(decode(rn,3,col1)) as col3
    16        from (select col1, rownum rn from (select * from y order by col1))
    17*      ) y
    SQL> /
    C C C C C C
    A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005}

  • Calling a perl script from stored procedure

    Can anyone tell me how to call/run a perl script from a stored procedure? If you have a sample code, please include it.
    Thanks in advance

    If you have a web server setup that runs perl, you can do this by using the utl_http package...Here is some code I use to run a perl script and print the results to a web page on our site.
    The in_URL parameter is the address of the perl code(i.e. http://website/path/perlscript?param1=value1&param2=value2 etc)
    PROCEDURE call_perl(in_URL VARCHAR2) IS
    /* This is setup to allow a perl program to be submitted as a batch program
    using the standard Portal batch program.
    Sometimes these jobs take a long time to run, so the timeout value must
    be set to a large value. The default timeout is 60 seconds, which is not long enough. */
    req utl_http.req;
    resp utl_http.resp;
    value VARCHAR2(1024);
    BEGIN
    req := utl_http.begin_request(replace(utl_url.escape(replace(in_URL,'%3A',':')),CHR(13)));
    utl_http.set_transfer_timeout(req, 18000); -- Set timeout to 5 hours for this specific request.
    resp := utl_http.get_response(req);
    LOOP
    utl_http.read_line(resp, value, TRUE);
    htp.p(value);
    END LOOP;
    utl_http.end_response(resp);
    EXCEPTION WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
    WHEN utl_http.init_failed THEN
    htp.p('INIT FAILED');
    WHEN utl_http.request_failed THEN
    htp.p('REQUEST FAILED');
    htp.p(NVL(utl_http.get_detailed_sqlerrm,' No more detail available.'));
    END;
    If you don't have a web server setup, I don't know offhand how you could do this.
    Laurel

  • Running Unix script from stored procedure

    At present, I run a unix script to export my data for backup using telnet. I would like my users to run the commands on their own without my help. My users do not know telnet (they have no IT knowledge). So, I plan to create a form using Developer/2000 and let them run the procedure thru a stored procedure.But, my problem is how can a stored procedure call a unix script?

    Hi,
    solution, used by me.
    Create a stored procedure that produces a text file with utl_file. The content of the file is the script you want to execute on your Unix box.
    On your Unix Box write a shell script that scans the utl_file_dir for Files. If a file is in, chmod 744 to grnt execute rights to it and execute it.
    I have a example if you want.
    Start the script with crontab or let it loop with a sleep inside.
    HTH
    Detlev

  • Migrating SQL Script to stored procedure...

    I created a SQL script file to run in SQLPlus to
    generate a fixed-format text file (See EDI_PrepForSend
    below)
    How do i do the same thing in a stored
    package/procedure? Can I utilize the
    script I already have working? I need to
    do it in a stored procedure because I need
    to do dynamic queries.
    TIA
    Chuck Plinta
    [email protected]
    ++++++++++++++++++++++++++
    -- EDI_PrepForSend.sql
    SET CONCAT '#';
    SET ESCAPE OFF;
    SET TERM OFF
    -- Set's for flat file
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 50
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET HEADING OFF
    SET VERIFY OFF
    SPOOL o:\ClientData\EDI-Send\&2\EDI-HCFA-Dtl-&1-&3.txt
    COLUMN MC_Number FORMAT A15 HEADING MC_Number
    COLUMN MC_Line_Number FORMAT A3 HEADING Ln#
    COLUMN MC_CPT_Code FORMAT A5 HEADING Code
    COLUMN MC_CPT_Modifier FORMAT A2 HEADING Mod
    COLUMN MC_FDOS FORMAT A8 HEADING FDOS
    COLUMN MC_LDOS FORMAT A8 HEADING LDOS
    COLUMN MC_Line_Charge FORMAT 99999.99 HEADING Charge
    SELECT MC.ICN MC_Number,
    '???' MC_Line_Number,
    MC.CPT_Code MC_CPT_Code,
    MC.CPT_Modifier_1 MC_CPT_Modifier,
    TO_CHAR(MC.First_DOS,'YYYYMMDD') MC_FDOS,
    TO_CHAR(MC.Last_DOS,'YYYYMMDD') MC_LDOS,
    MC.Charge MC_Line_Charge
    FROM &1.Decision_Support DS,
    &1.Medical_Claims MC
    WHERE DS.Reprice_Status = 'U' AND
    MC.CID = DS.CID
    ORDER BY MC.ICN, MC.CID;
    SPOOL OFF

    You need to put your select statement in a parameterised function that returns a REF CURSOR. This is all well documented in the PL/SQL users guide.
    Then you amend your SQL*PLUS script to call the function
    VAR rc REFCURSOR
    EXEC :rc := yr_function('&1')
    PRINT rc
    Cheers, APC

  • Calling shell script from stored procedure.

    Hi Everybody,
    Could anyone tell me how to call a shell script from a stored procedure.
    Thanks,
    Vasu

    You would need to write a Java stored procedure that calls out to the underlying operating system. Tom Kyte has an example of this here
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:952229840241
    Make sure that you're very aware of the security implications here, however. Your commands will run as the Oracle user on the host operating system, which makes it possible that a coding error and/or an attacker could do something like delete or corrupt Oracle data files, so you'll probably want to harden the code substantially.
    Justin

  • OEM12c Job - Run a SQL Script from a central location against multiple targets

    Hi All:
    I need to execute a SQL script that can be run as OEM Job against multiple targets from a single location so that the output csv files are all in that central location. My problem is that the sql script job documentation says "Make sure that the script file is installed in the appropriate location on all targets". Is anyone aware of a way I can do this so that the SQl script is executed from a location on my OMS console?
    Cheers

    Hi
    Create SQL job to run against on the server. Save those results (csv) file in local target. And crete one OS job, to collect all csv files into your OMS Console.
    Regards
    Krishnan

  • Launch the SQL*Loader From Stored Procedure???

    Is it possible to aaunch the SQL*Loader from a stored procedure? Please help!

    Try the documentation on external procedures

  • Privilege error while running Create Table Script inside Stored Procedure.

    Hello All,
    I have Oracle 10G server and SQL Developer Client,
    I have One User with Appropriate Rights, Login with that user from SQL Developer(client),
    Within my Procedure, Dynamic SQL script is like If I pass in a TABLE NAME as parameter, It Creates that table, but now problem is It throws an error for Privilege.
    Where as if I Execute Create table script outside the procedure(as Normal SQL), it executes Ok, but why it throws Privilege error within procedure ?
    Whether any extra Rights needed for this user to execute such Create Table Dynamic SQL?
    Please Help.
    Thanks,
    j@y

    Elic
    Thanks a lot dude...
    It works now,
    regards,
    j@y

  • Problems Running a SQL script from within Forms 4.5

    Hi ORACLE experts,
    I need some help,
    We are building a GUI that allows users to prepare queries. The
    query is stored in a variable that is used as a parameter to a
    HOST call. The host command runs the script and the script
    creates the output report.
    Host (sqlplus -s /nolog @

    Sergio Lostal (guest) wrote:
    : Hi ORACLE experts,
    : I need some help,
    : We are building a GUI that allows users to prepare queries.
    The
    : query is stored in a variable that is used as a parameter to a
    : HOST call. The host command runs the script and the script
    : creates the output report.
    : Host (sqlplus -s /nolog @

  • 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.

  • Running sql script from pl/sql

    Is there any standard way to run an external sql script from pl/sql
    I really appreciate any assistance.

    If you want, I did start writing a function reading and executing statements out of sql script with utl_file.
    can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';
    the function could be extended for DDL, session setting, etc...
    Regards
    Laurent

  • Running SQL scripts from CF server

    Hi,
    I'm new to ColdFusion, but not to database or web
    development. I'm wondering if there's anyway I can run a SQL script
    on a database from my CF server. I'm running CF 5 on a 2003 Windows
    server with a couple Oracle 9i DBs on the backend. I want to move
    data from one DB to the other, but can't use a DB link between the
    two, so a colleague suggested using CF to migrate the data. Is this
    possible?
    Thanks

    It's possible. For each db, cold fusion needs a connection
    and sufficient permissions.

Maybe you are looking for

  • Exporting with Adobe Media Encoder CC 2014 loses sound.

    So... I've been having a hell of a time with the new Adobe creative cloud when it comes to video editing.  The drop of .flv format, unable to straight export .H24 formats from after effects, it's a total nightmare.  Here's the issue, to export as a .

  • Whats the point of having page thumbnail view in Pages 5...

    ...when it has absolutely 0 functionality?!?!?!? Can't copy/paste, can't select multiple pages, can't rearrange, can't insert...seriously...other than being able to delete and navigate, its been stripped of its most important functions.

  • 'undefined' in webmail body

    one of our users went away (using laptop/internet explorer/wireless) said several messages in uwc show up with 'undefined' in the body. i believe this coincides with my application of t patch -60 to the messaging server. Sun Java(tm) System Messaging

  • Adobe reader page commune à plusieurs dossier

    Bonjour, Notre entreprise à ces dossiers techniques au format PDF (dossier contenant de 15 à25 pages) sur les produits que nous fabriquons. Ma question : Est-il possible d'avoir une page commune entre plusieurs dossiers? ( exemple: nous inscrivons un

  • Vorlage mit mehreren Sprachen bearbeiten

    Hallo Leute, folgendes Problem: Ich habe eine Vorlage: Diese muss bearbeitet werden (Ich muss nur ein Paar Elemente entfernen und eine Tabelle aktualisieren). Oben rechts sieht man die drei Sprachen, wenn man darauf klickt gelangt man jeweils zu der