Procedure call from SQL*Plus in Korn Shell Script

I am trying to excute a procedure from sqlplus, truncate_audit_table. I doesn't execute. If I do it manually
it executes. I have tried multiple ways, as below. This is inside a Korn Shell scripts that creates the procedure
and counts the aud$ table. All that works, but does not truncate the aud$ table. It does not do it, no error, just
passes it by. Does anybody know why?
${ORACLE_HOME}/bin/sqlplus -s / << EOF | tee -a ${LOG}
set feedback on
@/backup/oracle/orcl/audit/truncate_audit_table.sql
select count(*) from sys.aud$;
exec truncate_audit_table;
exit
EOF
${ORACLE_HOME}/bin/sqlplus -s / << EOF | tee -a ${LOG}
set feedback on
@/backup/oracle/orcl/audit/truncate_audit_table.sql
select count(*) from sys.aud$;
begin
     truncate_audit_table;
end;     
exit
EOF
This is the procedure that is being called:
create or replace procedure truncate_audit_table
as
begin
execute immediate 'truncate table sys.aud$';
end;
/

aud$ is owned by sys. You can see it does the count with or without the "\".
It creates the procedure under SYS , but does not execute it.
Truncate aud$ table...
Procedure created.
COUNT(*)
422
1 row selected.
===============================================================
audit_maintenance.ksh Completed: Thu Oct 26 14:03:17 GMT 2006
===============================================================

Similar Messages

  • Passing a variable from SQL*Plus to Korn

    Sorry if this isn't the correct forum, not sure where to post this otherwise. And excuse the poor shell script programming - I have no excuse.
    I have a shell script that generates another shell script to delete database related files. I have no problems getting the filenames for the datafiles or the control files or the redo logs (just for info its to clone and rename a prod database and we don't have RMAN in place yet).
    I do have a problem with the spfile. I'm using this :
    V_SPFILE=`sqlplus -s "/ as sysdba" << EOF
    set feedback off;
    set pagesize 0;
    select value
    from v\\\$parameter
    where name like 'spfile%';
    exit;
    EOF`
    which passes "?/dbs/[email protected]" to V_SPFILE. Then later on in my script I'd like to do something like :
    mv $V_SPILE OLD${V_SPFILE}${TDATE}
    TDATE is todays date BTW.
    Trouble is, the "?" is passed to the shell script. I know that I could put something like :
    $V_SPFILE = $ORACLE_HOME/dbs/spfile${SID}.ora
    as a global variable, but I want to be sure that the spfile that is in use is renamed.
    So, how does one deal with the "?" passed to the shell script?

    Having the same problem...getting variable values FROM captivate to my inserted .swf (not widgets).
    I can set the value from the .swf to the captivate using Object(parent.parent.parent.parent).captivateVariable but not the other way around.
    Very frustrating.
    I hope someone answers your query.

  • Sql plus -s in shell script

    Hi Folks
    I have this code in my shell script but am getting the below error please check
    sqlplus -s scott@xyz/tiger @1.sql > 1.log
    and oracle home is
    /oracle/app/oracle/product/11.2.0/dbhome_1
    error thrown is
    Error 6 initializing SQL*Plus
    SP2-0667: Message file sp1<lang>.msb not found
    SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
    i have checked i have sp1us.msb please help me on this

    newbie wrote:
    Sir i have given my oracle home.
    how to check whether it is set properly o not?No, you have stated what you believe ORACLE_HOME should be. But you have NOT proven that it was correctly set in the session that threw the error, and the error itself is almost certain proof that it was NOT set correctly. And your assertion that the referenced file does indeed exist (again, your assertion, not proof) lends more weight to the evidence that ORACLE_HOME is not properly set.
    Issue the following commands, then copy and paste the entire session (full command, full output) to your next posting
    env |grep ORA|sort
    echo $PATH
    sqlplus -s scott@xyz/tiger @1.sql > 1.log

  • Calling stored proc (with 2 IN and 3 OUT) - from SQL Plus

    This is the signature of my stored proc:
    CREATE OR REPLACE PROCEDURE myschema.myproc
       p_usr_name     IN  VARCHAR2,    
       p_send_tmstmp  IN  DATE,    
       p_ret_value    OUT NUMBER,
       p_err_code     OUT VARCHAR2
    )If I need to call it from sql plus, how do I need to pass the arg?
    This is what I am doing
    execute myschema.myproc('abc123','02-MAY-2008');
    What is wrong here? If someone could help. Thx!

    Try something like this
    var usr_name    varchar2(30)  
    var send_tmstmp varchar2(11)  
    var ret_value   number
    var err_code    varchar2(10)
    begin
    :usr_name    := 'abc123';
    :usr_name := '02-MAY-2008';
    myschema.myproc ( p_usr_name           => :usr_name,
                      p_send_tmstmp        => TO_DATE( :usr_name, 'DD-MON-YYYY' ),
                      p_ret_value          => :ret_value,
                      p_err_code           => :err_code);
    end;
    print ret_value;
    print err_code;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Calling a function from sql*plus

    I can call my procedure from sql *plus
    by doing
    sql>call Proc_name(x,y);
    How do you call a function?
    null

    John,
    I think moifying the statement
    CREATE OR REPLACE PROCEDURE "OGUSER"."OGX1" (user_county in integer, user_permit in integer )
    TO
    CREATE OR REPLACE FUNCTION "OGUSER"."OGX1" (user_county in integer, user_permit in integer ) return NUMBER is
    AND before end you will have to add a return statement
    (Probably
    return 0;
    exception
    when others then
    return 1;
    end;
    This will change your procedure to a function but I am not sure you'll be able to see your dbms_output's, if you call the function using select ...
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by john saucer ([email protected]):
    I want to turn my procedure into a function.
    So I can call it with a select statement.
    I'm kind of having problems with the return statement at the top and bottom.
    I don't quite understand how to declare the type in the return. My procedure calculates 2 pl/sql tables....
    My procedure looks like.
    CREATE OR REPLACE PROCEDURE "OGUSER"."OGX1" (user_county in integer, user_permit in integer )
    as
    i integer :=0;
    j integer :=0;
    type dept_table_type is table of ogxtest%rowtype
    index by binary_integer;
    type dept2_table_type is table of ogxtest%rowtype
    index by binary_integer;
    my_dept_table dept_table_type;
    my_dept2_table dept2_table_type;
    v_cotemp number := user_county;
    v_permittemp number := user_permit;
    v_origcotemp number := user_county;
    v_origpermittemp number := user_permit;
    v_count number(2) :=1;
    v_count2 number(2) := 1;
    v_oldcount number(2) :=1;
    v_oldcount2 number(2) := 1;
    begin
    select count(*) into v_count from ogxtest where oco=v_cotemp and opermit=v_permittemp;
    select count(*) into v_oldcount from ogxtest where nco=v_cotemp and npermit=v_permittemp;
    while v_count >= 1 LOOP
    i := i+1;
    v_count2 := v_count2 +1;
    select *
    into my_dept_table(i)
    from ogxtest where oco=v_cotemp and opermit=v_permittemp;
    v_cotemp := my_dept_table(i).nco;
    v_permittemp := my_dept_table(i).npermit;
    select count(*) into v_count from ogxtest where oco=v_cotemp and opermit=v_permittemp;
    end loop;
    while v_oldcount >= 1 LOOP
    j := j+1;
    v_oldcount2 := v_oldcount2 +1;
    select *
    into my_dept2_table(j)
    from ogxtest where nco=v_origcotemp and npermit=v_origpermittemp;
    v_origcotemp := my_dept2_table(j).oco;
    v_origpermittemp := my_dept2_table(j).opermit;
    select count(*) into v_oldcount from ogxtest where nco=v_origcotemp and npermit=v_origpermittemp;
    end loop;
    for i in 1..v_count2-1
    loop
    dbms_output.put_line(' reassigned to - orig county ' | |my_dept_table(i).oco | | ' orig permit ' | |my_dept_table(i).opermit| | ' new county ' | |
    my_dept_table(i).nco | | ' new permit ' | |my_dept_table(i).npermit );
    end loop;
    for j in 1..v_oldcount2-1
    loop
    dbms_output.put_line(' reassigned from - orig county ' | |my_dept2_table(j).oco | | ' orig permit ' | |my_dept2_table(j).opermit| | ' new county ' | |
    my_dept2_table(j).nco | | ' new permit ' | |my_dept2_table(j).npermit );
    end loop;
    end;
    <HR></BLOCKQUOTE>
    null

  • How to execute procedure returning data rows from sql plus

    Hi,
    I want to execute a stored procedure that returns data rows from sql plus. please let me know the syntax for the same.
    Thanks,
    YG

    user13065317 wrote:
    Even if i get the result set into the cursor, do i have to do normal fetch into all the coumn variables within a loop
    But suppose no of columns in my result set varies depending on a parameter to the stored procedure.
    Is there any straightforward way to retrieve all the data irrespective of no of columns in the result set.There is no such thing as a "+result set+". Oracle does not create a temporary data set in memory that contains the results of your query. What would happen if this result set is a million rows and is too large to fit into memory? Or there are a 100 clients each with a 100,000 row result set?
    This is not scalable. You will be severely limited in the number and sizes of these "+result sets+" that can be created in server memory.
    A cursor is in fact a "program" that is created by compiling the SQL source code that you provide. This source code is parsed and compiled into what Oracle calls an execution plan. This is nothing but a series of instructions that the cursor will execute in order to return the rows required.
    Thus the result set is actually the output from a cursor (a program). Likewise, bind variables are the input parameters to this program.
    All SQLs are parsed and compiled as cursors and stored in the SQL Shared Pool. Oracle gives you handle in return to use to address this cursor - bind values to it, execute it, describe the output structure returned by the cursor, and fetch the output from the cursor.
    On the client side, this handle is used in different ways. In PL/SQL alone, this cursor handle can be used as an implicit cursor (you do not even see or use the cursor handle in your PL/SQL code). Or you can use a PL/SQL cursor variable. Or a DBMS_SQL cursor variable. Or a reference cursor variable.
    Why so many different client structures for the very same SQL cursor handle returned by Oracle? Because to allow you, the programmer, all kinds of different features and flexibility.
    The ref cursor feature is the ability to pass this cursor handle around, not only between PL/SQL code, but also from PL/SQL to the actual client process (Java. VB, SQL*Plus, TOAD, etc).
    The primary thing to remember - irrespective of what the client calls this (e.g. ref cursor, SQL statement handle, etc), this all refers to the same SQL cursor in the Shared Pool. And that this SQL cursor is a program that outputs data, and not a result set in itself.

  • How execute this stored procedure from SQL PLUS???

    Hello folks....
    Help me please...
    I have this procedure....
    CREATE OR REPLACE PROCEDURE TEST(COD OUT VARCHAR2, NUM OUT
    VARCHAR2, ID OUT VARCHAR2)
    AS
    BEGIN
    END;
    SO, I4D LIKE TO EXECUTE IT FROM SQL PLUS::
    BUT, I DONT KNOW HOW TO DO..PLEASE SEND ME A SAMPLE..
    THANK U

    Thank u man!!!
    look, my error before was :
    SQL> set serveroutput on
    SQL> declare
    SQL> cod varchar2(100);
    SQL> num varchar2(100);
    SQL> id varchar2(100);
    SQL> begin
    SQL> TEST( cod, num, id );
    SQL> EXEC DBMS_OUTPUT.put_line( cod || ' ' || num || ' ' ||
    id );
    SQL> end;
    SQL> /
    i put the EXEC....
    thank u!!!

  • How to view  a stored procedure from sql plus

    Can anyone please tell what is the command for viewing the content of the stored procedure from sql plus ?
    Thanks

    Hi,
    I use this simple script to retrieve.......
    EDTRAD@T_E_S_9-->l
    1 select text from all_source where name = 'GET_MAN' -- proc name here
    2* order by line asc
    EDTRAD@T_E_S_9-->/
    TEXT
    FUNCTION get_man (in_man SSBOSS.CLNTWORK.manager%type)
    RETURN varchar2 IS
    CURSOR get_man(in_man SSBOSS.CLNTWORK.manager%type) IS
    SELECT name
    FROM ssboss.clntwork
    WHERE agency = 'TM'
    AND manager = in_man
    AND manager is not null
    AND manager != '**OB**';
    v_man SSBOSS.CLNTWORK.name%type := null;
    BEGIN
    OPEN get_man(in_man);
    FETCH get_man INTO v_man;
    IF get_man%notfound THEN
    v_man := 'Manager Not Found !';
    RETURN (v_man);
    CLOSE get_man;
    END IF;
    RETURN (v_man);
    CLOSE get_man;
    END;
    21 rows selected.
    EDTRAD@T_E_S_9-->

  • How to Strip Extraneous Output from SQL*Plus Session

    We are running Oracle Database 11g on Solaris 10, and I am trying to use SQL*Plus to create a temporary .sql file that I can execute in a later step of a Korn shell script. Here is the code:
         $ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
    --whenever oserror exit failure;
    --whenever sqlerror exit sql.sqlcode;
    set serveroutput on
    set termout off
    set trimspool on
    set verify off
    set heading off
    set feedback off
    set echo off
    spool /usr/oracle/temp/apply_site_security_for_oracle_database_11g.ksh.tmp
    declare
         Value_DSC varchar2(2000);
         CommandLine_DSC varchar2(4000);
    begin
         select v\$parameter.value into Value_DSC from v\$parameter where lower(name)='diagnostic_dest';
         CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
         dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
         dbms_output.put_line(CommandLine_DSC);
         CommandLine_DSC := 'host ls -ld ' || Value_DSC;
         dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
         dbms_output.put_line(CommandLine_DSC);
    end;
    spool off;
    exit;
    EOF
    I've tried to turn off everything I don't need, but I am missing something. When I run the script, I get the following in the temporary file:
    SQL>
    SQL> declare
    2 Value_DSC varchar2(2000);
    3 CommandLine_DSC varchar2(4000);
    4
    5 begin
    6 select v$parameter.value into Value_DSC from v$parameter where lower(name)='diagnostic_dest';
    7
    8 CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
    9 dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
    10 dbms_output.put_line(CommandLine_DSC);
    11
    12 CommandLine_DSC := 'host ls -ld ' || Value_DSC;
    13 dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
    14 dbms_output.put_line(CommandLine_DSC);
    15 end;
    16 /
    --Ready to execute: host chmod 751 /s01/app/oracle
    host chmod 751 /s01/app/oracle
    --Ready to execute: host ls -ld /s01/app/oracle
    host ls -ld /s01/app/oracle
    SQL>
    SQL> spool off;
    I am hoping to whittle this down to just the following lines so I can execute them as a script.
    --Ready to execute: host chmod 751 /s01/app/oracle
    host chmod 751 /s01/app/oracle
    --Ready to execute: host ls -ld /s01/app/oracle
    host ls -ld /s01/app/oracle
    Any ideas?
    Edited by: shew01 on Jan 19, 2010 10:51 AM

    I just found it. Just add "-S" to the sqlplus command. Argh... I hunted for that a while back. Why didn't I remember it??????????
    This works:
         $ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
    whenever oserror exit failure;
    whenever sqlerror exit sql.sqlcode;
    set serveroutput on
    set linesize 2000
    set pagesize 0
    set termout off
    set trimspool on
    set feedback off
    spool /usr/oracle/temp/apply_site_security_for_oracle_database_11g.ksh.tmp
    declare
         Value_DSC varchar2(2000);
         CommandLine_DSC varchar2(4000);
    begin
         select v\$parameter.value into Value_DSC from v\$parameter where lower(name)='diagnostic_dest';
         CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
         dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
         dbms_output.put_line(CommandLine_DSC);
         CommandLine_DSC := 'host ls -ld ' || Value_DSC;
         dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
         dbms_output.put_line(CommandLine_DSC);
    end;
    spool off;
    exit;
    EOF
    Edited by: shew01 on Jan 19, 2010 11:02 AM

  • External Procedure call from Trigger

    I'd like to call an external C Procedure from
    an Oracle Trigger.
    In trying to get an example to work, after setting up the listener and tnsnames.ora for external procedures, the following SQL*Plus command behaves strangely:
    CREATE LIBRARY TTest as "c:\winnt\system32\TTrigger.dll";
    After entering this, the command line prompts for more data as if the command was not terminated. Tried single quotes, double quotes, forward slash, backward slash...
    What is wrong with this command?
    Thanks

    hi,
    COuld you send me the configuration parameters for listner and TNSNAMES? I am working so hard to set it up but getting stuck and I am sure that I am missing some configuration set up.
    Please could you mail your tnsname a nd listner files to bellow shown address?
    [email protected] ?
    Thanks in advance
    Suresh

  • Dbms_job.submit procedure called from Forms

    Folks,
    Since the DBMS_JOB.SUBMIT cannot be executed directly within a form, I created a simple procedure on the database which makes the call to DBMS_JOB.SUBMIT as follows:
    FUNCTION web_newsletter_submit_job(p_letter_id NUMBER) RETURN NUMBER IS
    v_jobnum NUMBER;
    BEGIN
    DBMS_JOB.SUBMIT (v_jobnum, 'send_mail_html2 (''DailyRacingForm<[email protected]>'', ''[email protected]'', ''DailyRacingForm<[email protected]>'', ''test subject'', ''test body'');',
    TRUNC(SYSDATE) + 22/24);
    RETURN v_jobnum;
    END;
    From SQL/Plus I can declare a varialbe and execute this procedure as follows:
    v_jobnum := web_newsletter_submit_job(22) ;
    then I can view the v_jobnum and find the job in the DBA_JOBS table.
    My problem is when I execute the 'web_newsletter_submit_job' function from with Forms, my job never gets created. The function actually returns a job number and my Form display it via the Message() function; however, the job number never shows up in DBA_JOBS table.
    Any ideas why I can successfully create the job from sql/plus but not from Forms ???
    Regards,
    Bob

    you made a FORMS_DDL('COMMIT') right? without commiting, the jobe will never get executed.
    Cheers, Stefan

  • Execute a mapping deployed with OWB 9.0.4 from SQL*Plus

    Hello,
    I could execute a mapping designed with OWB 9.0.3 from SQL*Plus with the next sentence:
    SQL> exec my_mapping.main;
    But now, with OWB 9.0.4, mappings are deployed as functions (in 9.0.3 were deployed as procedures) and they need parameters.
    Somebody know how I can execute deployed mappings with OWB 9.0.4 from SQL*Plus? I don't know the parameters I need to call a mapping.
    Thanks in advance,
    Pedro.

    Well, I've solved the problem with roles but
    I've executed the script called sqlplus_exec_template.sql and it fails at Stage 2 because the next sentence
    l_audit_execution_id := wb_rt_api_exec.open(l_task_type, l_task_name, l_location_name);
    returns me NULL.
    It is not clear the value that the variable called l_location_name have to stored. The script explain that this variable store the physical name of the
    location to which the task was deployed. I understand that this variable have to store the schema where the mapping was deployed. That's right?
    So I called the script in this manner:
    SQL> @sqlplus_exec_template OWBRUN904I OJBHT PLSQL MY_MAPPING "," "," ;
    where OWBRUN904I is the name of the Runtime Repository Schema, OJBHT is the
    schema where MY_MAPPING is deployed, PLSQL is the task type and MY_MAPPING is
    the name of the mapping I've designed.
    Can you tell me why the scripts fails?
    Regards,
    Pedro

  • How to pass table type variable into function from SQL*PLUS ?

    How to pass a table type variable from sql*plus prompt into a function ?
    Thanx in advance.

    Krishna,
    Do you mean like this?SQL> DECLARE
      2      TYPE t_tbl IS TABLE OF VARCHAR2(20);
      3      l_sample_tbl           t_tbl;
      4
      5      FUNCTION print_contents ( p_tbl IN t_tbl )
      6      RETURN VARCHAR2
      7      IS
      8          l_string            VARCHAR2(1000);
      9      BEGIN
    10          FOR i IN 1..p_tbl.COUNT LOOP
    11              IF (i = 1) THEN
    12                  l_string := p_tbl(i);
    13              ELSE
    14                  l_string := l_string || ', ' || p_tbl(i);
    15              END IF;
    16          END LOOP;
    17          RETURN (l_string);
    18      END print_contents;
    19
    20  BEGIN
    21      l_sample_tbl := t_tbl();
    22      l_sample_tbl.EXTEND;
    23      l_sample_tbl(1) := 'one';
    24      l_sample_tbl.EXTEND;
    25      l_sample_tbl(2) := 'two';
    26      l_sample_tbl.EXTEND;
    27      l_sample_tbl(3) := 'three';
    28      l_sample_tbl.EXTEND;
    29      l_sample_tbl(4) := 'four';
    30      l_sample_tbl.EXTEND;
    31      l_sample_tbl(5) := 'five';
    32      DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
    33  END;
    34  /
    one, two, three, four, five
    PL/SQL procedure successfully completed.
    SQL> HTH,
    T.

  • Stored Procedure call from JDBC sender for Oracle Database

    Hi,
    I have a requirement to call stored procedure using JDBC sender adapter for retriving data from an Oracle database.
    I need to execute first stored procedure call from Querry SQL statement and then trigger second stored procedure call for confirming the succesful retrival of those records from the update SQL statement.
    Querries:
    1. Can we trigger stored procedure from Update statement of JDBC sender.
    2. Can we call stored procedure from Querry statement, since I have read on other sdn threads that stored procedure calls on Oracle database are not allowed. If not possible to have "Execute stored procedure" would the function call (select * from table(function name)) work same as stored procedure.
    3. In a JDBC sender the Querry statement and Update statement are executed in same session call and same database connection. What happens if the querry statement was not succesful, would the update be still triggered.
    Please note PI does not have direct access to main table and hence the need to have separate stored procedure calls.
    The PI version is PI 7.11 sp4.
    Appreciate your inputs.
    Thanks.
    Siddhesh S.Tawate

    >1. Can we trigger stored procedure from Update statement of JDBC sender.
    I think not possible using update statement.
    > Can we call stored procedure from Querry statement, since I have read on other sdn threads that stored procedure calls on Oracle database are not allowed. If not possible to have "Execute stored procedure" would the function call (select * from table(function name)) work same as stored procedure.
    Yes using select query you can call stored procedure.
    >. In a JDBC sender the Querry statement and Update statement are executed in same session call and same database connection. What happens if the querry statement was not succesful, would the update be still triggered.
    No select and update handles in the same session using the same thread so if one transaction fails update should not proceed.

  • Execution Times of Stored Procedures Called from Other Stored Procedures

    If I execute sys.dm_exec_procedure_stats, it will produce execution times of my stored procedures executed recently.
    However, stored procedures called from other stored procedures do not show up.
    Is there code that can return the execution times of stored procedures even though they are called from other stored procedures.

    Look at the example. It is counting nested execution.
    CREATE PROC z1SP AS SELECT * FROM Production.Product;
    GO
    CREATE PROC z2SP AS SELECT * FROM Production.Product WHERE Color is not null; EXEC z1SP;
    GO
    SELECT object_name(2002822197), object_name(2034822311);
    --z1SP z2SP
    EXEC z1SP; EXEC z2SP;
    GO 10
    SELECT * from sys.dm_exec_procedure_stats
    database_id object_id type type_desc cached_time last_execution_time execution_count
    16 2002822197 P SQL_STORED_PROCEDURE 2014-12-16 13:02:45.170 2014-12-16 13:02:46.717 20
    16 2034822311 P SQL_STORED_PROCEDURE 2014-12-16 13:02:45.460 2014-12-16 13:02:46.687 10
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

Maybe you are looking for