How to execute a SQL procedure in UNIX

How to execute a SQL procedure in UNIX

Check this out..
-Sri
<< a.sql >>
create or replace procedure junk(nout out varchar2) is
        x varchar2(20);
begin
        select 'Sam' into x
        from dual;
        nout := x;
end;
<< Shell script >>
sqlplus -s / << DOC
scott/tiger
variable x varchar2(20);
set autoprint on
@a.sql
begin
junk(:x);
end;
exit
DOC
<< Execution of Shell SCript >>
# sh b.sh
Procedure created.
PL/SQL procedure successfully completed.
X
Sam

Similar Messages

  • How to execute one sql file in unix

    Hi,
    I need to run the follwing script in a file in unix , then run the corresponding spooled file again
    SET echo OFF;
    SET sqlblanklines ON;
    SET feedback OFF;
    SET linesize 1500;
    SET trimspool ON;
    SET termout OFF;
    SET pagesize 0;
    spool updatedfix.sql;
    SELECT ' <update stmt>
    spool OFF;
    SET termout ON;
    SET echo ON;
    SET feedback ON;
    How can the above script in a file be executed in unix
    like
    ed script
    @ script
    then
    @ updatedfix.sql;
    plz help
    thanks

    I haven't got unix to hand but the principle is the same in windows batch files..
    c:\temp>type gen_update.sql
    set echo off
    set sqlblanklines on
    set feedback off
    set linesize 1500
    set trimspool on
    set termout off
    set pagesize 0
    spool updatedfix.sql
    select 'update emp set comm = -1 where comm is null;' from dual;
    select 'exit' from dual;
    spool off;
    set termout on
    set echo on
    set feedback on
    exit
    c:\temp>sqlplus user/pass@db @gen_update.sql
    SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:10 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
    SQL> set feedback on
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    c:\temp>sqlplus user/pass@db @updatedfix.sql
    SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:37 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
    10 rows updated.
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    c:\temp>Just run one after the other in the script file.

  • How to execute a sql script in dbms_job?

    how to execute a sql script in dbms_job?

    See my response to Re: how to execute a sql script file in procedure or trigger.
    Cheers, APC

  • How to execute a stored procedure/function in TOAD?

    Hi, All ,
    Can someone please tell me how to execute a stored procedure/function in TOAD?
    I have tired
    EXECUTE PROCEDURENAME(888), but it doesn’t work.
    TOAD give me the error: invalid SQL statement.
    Thanks a lot

    Write PL/SQl block.
    i.e Begin
    Procedure name..
    end;
    Then it will be excuted.
    Ashutosh

  • How to execute a stored procedure every 5 minutes in biztalk admin console

    Hi 
    how to execute a stored procedure every 5 minutes in biztalk admin console without using biztalk orchestration
    we need to update table data every 5minutes 
    please replay asap...........
    thanks advance....

    WCF adapter is best suited for the same. Use ‘Template’ feature of WCF adapter. Template is mainly used to add wrapper elements around the body of the outgoing message from send port.
    Below mentioned post is perfectly suited for you.
    http://social.technet.microsoft.com/wiki/contents/articles/19845.invoke-a-sql-stored-procedure-on-the-biztalk-wcf-send-port-without-needing-an-orchestration.aspx
    Regards,
    Rachit
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • How to execute multiple sql statements in parallel ?

    Hi There,
    I have 10 stored procedures, each one will take approximately 5 seconds to run individually.
    Now I need to combine the results of these 10 stored procedures into single result set.
    So I have created one more stored procedure "proc_AllSPs" to get the single result set.
    The procedure "proc_AllSPs" is taking one minute to run because all the procedures inside the "proc_AllSPs" are running
    one after the other and taking 5 seconds each.
    If there is any other way that all the procedures run parallelly, then the procedure "proc_AllSPs" can run in 5 seconds time.
    Sorry if I am not being elaborated.
    PLease get back to me if any piece of information is needed.
    Any kind of help is truly thankful.
    Thanks,
    SequelBug

    Could you tell me how to execute two stored procedures or two sql statements in parallel
    For eg:
    First procedure name is proc_sp1 which takes 1 minute to run
    Second procedure name is proc_sp2 which takes 1 minute to run
    I want to accomplish the below query in 1 minute by executing statement1 and statement2 parallelly.
    go
    select * from openrowswt('sqloledb','server','exec proc_sp1')    --statement1
    union
    select * from openrowset('sqloledb','server','exec proc_sp2')     --statement2
    go
    OR
    go
    Select * into #Temp1  from openrowswt('sqloledb','server','exec proc_sp1') --statement1
    select * into #Temp2 from openrowset('sqloledb','server','exec proc_sp2') --statement2
    Select * from #Temp1
    UNION ALL
    Select * from #Temp2
    go
    Thanks,
    SequelBug

  • How to execute a store procedure

    Hi Forum
    I have a store procedure with 4 variables in and 1 out, how to execute via sql this procedure for obtain the result in the out variable.
    Thanks and regards

    SQL> create or replace procedure test_proc (
      2     a in number,
      3     b in number,
      4     c in number,
      5     d in number,
      6     outvar out number) is
      7  begin
      8     outvar := a + b + c + d;
      9* end;
    SQL> /
    Procedure created.
    SQL> variable var1 number;
    SQL> exec test_proc (1, 2, 3, 4, :var1);
    PL/SQL procedure successfully completed.
    SQL> print var1
          VAR1
            10
    SQL>

  • How to execute a select statement in unix shell script

    Hi,
    How to execute the below statement in unix shell .
    select count( ID) into v_count from tbl_data1
    where ID =V_ID;
    thanks
    BCJ

    Thanks for the reply.
    few more doubts,
    the V_ID value is a user input getting inside the unix script, so how can i pass the value in to the a.sql.
    also needs the v_count value inside the unix script for further process.actual requirement is like,
    declare
    v_count number;
    begin
    select count( ID) into v_count from tbl_data1
    where ID =$V_ID;
    if v_count>1 then
    process 1;
    else
    process2;
    end if;
    end;
    thanks a lot

  • How to execute the packaged procedure(having out param) in TOAD for Oracle

    Hi.
    Could you help me
    How to execute the packaged procedure having out parameters in TOAD for Oralce..
    Thanks..

    Use anonymous PL/SQL block to execute it.
    Example.
    DECLARE
      <out variable name> <out variable data type>;
    BEGIN
      <package name>.<procedure name>(<out variable name>);
    END;

  • How to Execute a Remote Procedure in Portal using Database Link

    Hi,
    I followed the instructions to create a Portal form for a remote procedure. But I am encountering the following error. Can someone advise what may be the cause?
    Failed to execute - Missing string(create_package_body) language(us) domain (wwv) sub_domain (wwv_builder) (WWV-04300)
    ORA-04020: deadlock detected while trying to lock object PUBLIC.PORTLET_SCHEMA (WWV-11230)
    Failed to parse as PORTAL - (WWV-08300)
    PURPOSE
    How to execute a remote procedure in Portal using Database Link.
    DESCRIPTION
    This procedure assumes that you have two databases, one of which is remote, and Portal is configured in the other.
    Remote Database A:
    ==================
    1) Create a procedure as follows: Create or Replace PROCEDURE SCOTT.ADD_TWO_VALUES ( v_one IN NUMBER, v_two IN NUMBER, v_result OUT NUMBER) as begin v_result :=v_one+v_two; end; 2) Grant execute privileges to PUBLIC on the procedure.
    Database B (where Portal is configured): ========================================
    1) Create a public database link and choose to connect as a specific user (say SYSTEM). By default, in an Oracle 8i database, the "global_names" parameter in initSID.ora (or init.ora) file is set to "true". This Global Naming parameter enforces that a dblink has the same name as the database it connects to. Therefore, if the remote global database (A) name is "ora8.acme.com" then the database link should also be named as "ora8.acme.com".
    2) Create a synonym for the procedure in Database A. Make sure you fully qualify the procedure name in the remote database (like SCOTT.ADD_TWO_VALUES).
    3) Create a dynamic page to execute the procedure. The ORACLE tags in the dynamic page will look similar to the following: <ORACLE> DECLARE v_total NUMBER; BEGIN ADD_TWO_VALUES(:v_one,:v_two, v_total); htp.p('The total is => '); htp.p('<input type="TEXT" VALUE='||v_total||'>'); htp.para; htp.anchor('http://<machine.domain:port#>/pls/portal30/SCOTT.DYN_ADD_TWO_VALUES.show_parms', 'Re-Execute Procedure'); END; </ORACLE>
    4) Portal does not have an option to create a form based on a synonym. Therefore, if you want to create a form instead of a dynamic page, create a wrapper procedure and then create a form based on this procedure. For example: Create or Replace PROCEDURE PORTAL30.ADD_TWO_VALUES_PR ( v_one IN NUMBER, v_two IN NUMBER, v_total OUT NUMBER) as begin add_two_values(v_one, v_two, v_total); end;
    5) Grant execute privileges to PUBLIC on the procedure.

    hello...
    any input will welcomed... Thanks..

  • How to execute an SQL query present in a string inside an ABAP program?

    hello,
    How to execute an SQL query present in a string inside an ABAP program

    Raut,
    You can execute Native SQl statements.
    Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC.
    There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
    In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    Pls. Mark If useful

  • How to execute a  .sql file from a batch file

    Hi all
    I've to take backup of a database weekly twice on every wednesday & Friday @ 5pm IST. I've written a hot backup script, which works every well.
    now i want to automate the script. ie i want this script to run on wednesday & friday @ 5pm without any human interfearance ie with out actually any1 executing this script.
    i created a batch file prod.bak with the following lines
    @echo off
    set oracle_sid=testdb
    set oracle_home=d:\oracle\ora92
    sqlplus /nolog
    connect sys as sysdba/oracletest@testdb
    this batch file when eexecuted connects me to sql prompt.
    Now i want to execute my backup script bkp.sql automatically when it is connected to sql prompt.
    (i tried with these lines in the above batch file...
    call bkp.sql---it just opens the bkp.sql file in notepad & displays the script
    start bkp.sql---same as call
    connect / as sysdba/pwd@[email protected] --- does not work simply remains a the sql prompt.
    At 17:00 /Every:w,f "d:\bkp.sql"---does not work simply remains at the sql promt.)
    Can any1 let me know what should i write in the batch file that will execute the bkp.sql file automatically after it gets connected to sql prompt. M using oracle 9i.
    I'll manage he time through windows utility of scheduling task.. Let me know how to execute the .sql file from a batch file.
    Thanks
    Tripti

    Try
    sqlplus "sys/oracletest as sysdba" @bpk.sql
    Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
    Remember to put an exit at the end of the bpk.sql script.

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • How to execute oracle stored procedure through php as externally?

    hi...
    i am searching for the way that how to execute oracle stored procedure through web service, i am using php and mysql, i have some stored procedures in oracale database, i want to execute them, from php, means the database will be remain mysql, and the stored procedures of oracle will be executed externally...
    Kind regards,
    Wilayat.

    Ok, so first of all this is a kind of strange question. Since Oracle and MYSQL can happily live side by side.
    Make sure you have the oracle client (instant or regular ) installed and OCI_8 is set up and working correctly in PHP. If it is, when you run the phpinfo() routine you will see oci_8 on there. IF PHP connects just fine from the command line yet apache wont connect check permissions and things like the LD_Library Path.
    Then in php, right along with your MySQL statements run Oracle Statements eg:
    <?php
    $OraDB = oci_connect(name,pass,tnsname);
    $MySQLdb = mysql_connect([parms]);
    $oraQueryText = "begin sp_some_proc([some parms]); end;" ;
    $mysqlQuery = " Some mysql Query";
    $oraQuery = oci_parse($OraDB,$oraQueryText );
    oci_execute($oraQuery);
    mysql_execute([parms]);
    ?>
    Use the standard fetch code to get data from either of them.
    If you cannot and I mean absolutely cannot get an admin to link in OCI_8 then you still have recourse although it will be tedious as hell. PHP allows you to exec calls to the OS. You still MUST make sure the Oracle Client is installed and that sqlplus runs from the command line. You will more then likely have to have a shell script written to do this as well, but maybe not as I have never tried it with the exception of capturing the return value of sqlplus and you will have to dig into sqlplus to get it to send its results to a file you can then parse with php.
    Good Luck!

  • How to execute a sql file inside a plsql file?

    It's easy to exec a plsql inside a sql. Simply
    start my_proc.plsql
    exec my_proc;
    But how to execute a sql file inside a plsql file?
    declare ...
    begin
    start my_sql.sql?
    end;
    Thanks.
    - Zac

    Doesn't work. Even though @ is different from start in this case but it just doesn't like the way sql and plsql are mixed. For example:
    DECLARE n NUMBER := 0;
    BEGIN
    select COUNT(*) INTO n from user_tab_partitions;
    DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
    if n = 0 then
    DBMS_OUTPUT.put_line('createViewsProcs.sql');
    @createViewsProcs.sql
    else
    DBMS_OUTPUT.put_line('createPartitionViewsProcs.sql');
    @createPartitionViewsProcs.sql
    end of;
    END;
    SQL> @postimp.sql
    SQL> DECLARE n NUMBER := 0;
    2 BEGIN
    3 select COUNT(*) INTO n from user_tab_partitions;
    4
    5 DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
    6
    7 if n = 0 then
    8 DBMS_OUTPUT.put_line('createViewsProcs.sql');
    9 @createViewsProcs.sql
    9 SET SERVEROUTPUT ON SIZE UNLIMITED;
    10 SET TERM ON;
    11 SET ECHO ON;
    12 EXEC DBMS_OUTPUT.put_line('STARTING VIEWS, PROCS, ETC, THIS MAY TAKE A FEW MINUTES');
    13 EXEC DBMS_OUTPUT.put_line(SYSTIMESTAMP());
    14
    15
    16 CREATE OR REPLACE PACKAGE db_convert AS
    17 FUNCTION ......
    32 END;
    33 /
    SET SERVEROUTPUT ON SIZE UNLIMITED;
    ERROR at line 9:
    ORA-06550: line 9, column 5:
    PL/SQL: ORA-00922: missing or invalid option
    ...

Maybe you are looking for

  • Installing Oracle SOA suite 10.1.3.10 for Windows

    He, I have a probleme with Oralce SOA suite instalation. I can't find the Oracle Database verssions in the oracle website, supported by Oracle SOA suite 10.1.3.10. Oracle Database 10g Release 1 (10.1.x) 10.1.0.5 or later Oracle Database 10g Release 2

  • How do I install Mavis Beacon Deluxe 20 on macbook pro? I had MB (20) on my last macbook pro.

    How do I install Mavis Beacon Deluxe 20 on macbook pro? I had MB (20) on my last macbook pro.

  • Disk Utility doesn't offer sparse images

    I want to make disk images of hard drives, but Disk Utility no longer offers the "sparse image" format. Why is this? iMac (27-inch Mid 2011), OS X Mountain Lion (10.8.2)

  • Query Regarding IDOC  "WMMBID02"

    Hi, I have a follwoing requirement that makes use of a standart IDOC WMMBID02. This IDOC WMMBID02 has data stored within into different segments that have structures. I need to read that data and store it into an INTERNAL Table. Is there any specific

  • Breakpoint Madness

    Hi All, I'm using dvdsp 4.1. I've created a dual layer project which I'm having some difficulty with. At first, I was getting an error message telling me that the app could not find an appropriate point to put the layer break. I had selected automati