How to call SQL Script in DBMS_SCHEDULER
How to call SQL Scripts in DBMS_SCHEDULER?
Things I got working
1) Successfully created and tested a PL/SQL that was created under SQL Workshop->SQL Scripts (I named it 'TEST'). I was able to run this no problem.
2) Successfully created a DBMS_SCHEDULER that runs every minutes. (See below)
begin
dbms_scheduler.create_job(
job_name => 'myjob',
job_type => 'plsql_block',
job_action => 'null;',
start_date => '19-JUL-11 03.10.00 PM', /* Remember to use the DB time, not your local time if not specifying a timezone */
repeat_interval => 'freq=minutely',
enabled => true);
end;The problem i am having is to make the PL/SQL script (named 'TEST') runs every minute. Its probably very easy to do that but i dont seems like finding any examples online.
I tried replacing the job_action attribute to " job_action => 'begin TEST; END;', " However, that did not work.
I am stuck here for couple hours already, any clues would be great :)
Thanks in advance
John
Application Express 4.1.0.00.32
Edited by: John Lau on Aug 14, 2012 12:47 PM
Edited by: John Lau on Aug 14, 2012 12:48 PM
The PL/SQL is pretty long, I would like to call it from a different location rather then putting the whole coding as part of the argument. Sounds like I should be looking into procedure package in database?
I will do some more research on procedure package, how to create one and how to call from it.
Thanks
John
Similar Messages
-
How to call SQL script from PL/SQL block
Hi All,
I have a pl/sql block from which i need to call a *.sql script file.
Please tell me that how can i do this?
Thanks and Regards.> Though just for knowledge sake, would you please tell if there is a way
to call a sql script from a pl/sql block.
This question stems usually from a confusion about client-server and which is which in Oracle.
SQL*Plus is a client. PL/SQL is a server side language. SQL is a server side language.
When entering either one of these two languages in SQL*Plus (or TOAD, SQL-Developer, etc), the content is shipped to an Oracle server process, is parsed there, and is executed there.
The Oracle server process servicing the client can accept a single SQL statement or PL/SQL block at a time.
It cannot accept a block of SQL statements delimited with a semicolon. That is a client concept where the client will read each delimited statement and send that, one after the other (in synchronous call mode) to the Oracle server for execution.
The Oracle server does not have a "script parser". It understands SQL. It understands PL/SQL. And that is what it expects from the client.
Whether the client supports the SET command, the HOST command, SPOOL command, ability to run scripts, and so... have no bearing on what the server itself is capable of doing. The server does not care what feature set the client has. It is tasked with servicing the client via SQL and PL/SQL.
It is not tasked to support or emulate client features like running SQL scripts.
Nor confuse PL/SQL with the very limited command set of SQL*Plus. The two has nothing in common. And just as PL/SQL cannot understand C# or Delphi commands, it cannot understand SQL*Plus commands. -
Scheduling an sql script using dbms_scheduler
Hi Experts,
I am having an oracle 10g database on windows platform. I have an sql script which has a normal set of sql statements (insertion and updation).
I would like to schedule to run this sql script using dbms_scheduler but I've gone through certain sites and came to know that it's not possible to schedule an sql script using dbms_scheduler. Please let me know how I can schedule this script using dbms_scheduler.It is possible - in 10g and above you can use DBMS_SCHEDULER to call an external procedure, which in this case could be a call to your SQL file.
Get's a bit more complicated with older versions, but still doable.
But - unless there is a really good reason why you cannot do so, move this into a PL/SQL procedure as suggested.
Carl -
Hi,
How to Validate SQL scripts?
I am having set of sql files i wish to run one by one if there is any error at one file i need to notify to the user.I have created Bat file in-order to execute in a sequence.how to validate in bat file
say
01.sql ---Sucess
02.sql --- Fail -- intimate and not to execute rest of sql files
03.sql
04.sql
Thanks!933663 wrote:
I am going to create the database
cloneDBCreation.sql
CloneRmanRestore.sql
init.ora
initEDIDBTemp.ora
lockAccount.sql
postDBCreation.sql
postScripts.sql
rmanRestoreDatafiles.sql
dbname.bat
dbname.sqlSo i need to validate each and every .sql whether it succeed or not. if there is failure then needs to notify the user. Use the SQL*Plus macro/command, WHENEVER SQLERROR EXIT <n>, to terminate a sql script when it hits an error - and have it return a specific exit code to the caller (o/s command line in this case). Note that exit codes are typically defined as a single byte in shells - which means it can only returns 0 to 255.
In the command line shell, check the exit code of the previous command - which would be command than ran sqlplus and the sql script. If the exit code is for example 255, then you know the WHENEVER SQLERROR command was executed. And then you cease processing sql scripts.
Simplistically (I do not do Windows), it will look as follows:
--// sql script
whenever sqlerror exit 255
... rest of the script
@echo off
rem command shell script
prompt executing script 1
sqlplus -s /nolog @sqlscript1.sql
if ERRORLEVEL 255 goto :ScriptFailed
prompt executing script 2
sqlplus -s /nolog @sqlscript2.sql
if ERRORLEVEL 255 goto :ScriptFailed
goto :Success
:ScriptFailed
echo ...
goto :End
:Sucess
echo ..
goto :End
:End -
How to call a script in OWB?
I have some scripts in .sql form. I want to call/execute these script using owb10gr2.
Any pointers as to how can I call/execute these scripts in OWB ?
ThanksHi,
there are several variants for execution SQL-scripts in OWB:
1) compile your scripts as stored procedure and import definitions into OWB - after that you can call this procedure in mapping (with Pre/Post-mapping operator) or in processflow;
2) in porcessflow you can use User Defined Activity for calling SQL-scripts
Regards,
Oleg -
Shell script to call sql script
Hi All,
I have a application server and want to make a shell script to call sql script.
Please let me know how to do the same.
Regards
KumarWhat is the platform you are using and you can give the path of the sql script in your shell script as follows
1.)first create .sql file...let it is table.sql and has the contents ...
create table test(x1 varchar2(20),x2 number(4),x3 date)
exit;
(2.) write a shell script...like table.sh in vi editor
Here login is scott/tiger@sid, or apps/apps@sid or whatever you know valid schema
echo enter the login
read login
sqlplus -s $login @table
(3.)run the script
$ sh table.sh
it will create the table in your particular schema -
Calling sql script from anonymous block
Hi
how to call an script from an anonymous block, like
declare
v_reccord_account number :=0;
begin
SELECT xx.cc INTO v_reccord_account FROM
(select count(1) cc
from accounts
group by account_id
having count(account_id) > 1
)xx
where ROWNUM=1;
if v_reccord_account <1
then
dbms_output.put_line('no duplicates');
ELSE
< here i have to call this script -- @e:/test44.SQL >
end if;
end;Hi
thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
=================================================
whenever sqlerror exit sql.sqlcode
set serveroutput on
column fn new_value filename
select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
spool E:/&filename
prompt 'Checking for duplicates'
--select account_id, count(1)
--from accounts
--group by account_id
--having count(1) > 1;
prompt 'Records to be deleted'
select *
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1;
prompt ' Deleting duplicates'
delete
from accounts
where account_id in (
select account_id
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1
commit;
========================================== -
How to call java script function from JSP ?
how to call java script function from JSP ?
i have function created by java script lets say x and i want to call this function from jsp scriplet tag which is at the same page ..thanks
-
How to run sql scripts using batch file for a web dynpro data dictionary
Hi,
I want to develop a sql script to be executed on the server alongwith the installation of a product to pre-populate web dynpro data dictionary tables required for the application.
I further require to make the scripts independent of the database name,so that it can be run at any client environment.
Your help will be appreciated and rewarded.See shoblock's answer
call sql script from unix
masterfile.sql:
@file1 &1
@file2 &2
@file3 &3
@file4 &4
then just call the master script:
sqlplus userid/password @masterfile <p1> <p2> <p3> <p4> -
How to call unix script/command in ODI
Hello Gurus,
Please let me know how to call unix script/command in ODI?
Thanks
Shridharyou can call shell script using the OS command found in Package.
Step 1. Drag the OS Command in the Packgae
Step 2. In the Text mentiond call the script say for ex sh /opt/path/script.sh
Step 3. Execute.
Note : Make sure the User through which ODI is triggering does have the required permission to execute shellscript , also always provide the full path , since scripts are execute from the oracldi/bin folder so its necessary to provide the complete path of the script location.
Hope this helps. -
Hi,
Please let me know how to call shell scripts from WDA
Thanks
Bala DuvvuriHi Bala
You can not call any client side funcitons using Web Dynpro ABAP, it is possible in BSP using JavaScript.
You can use Suspend and Resume Plugs to navigate to a BSP page and perform the shell script and return to WDA using Resume Plug.
http://help.sap.com/saphelp_nw04s/helpdata/en/45/19bf8c16f25d7ae10000000a11466f/frameset.htm
Now, you can use JavaScript to execute shell script:
http://www.itjungle.com/mpo/mpo052302-story01.html
Abhi -
How to execute sql scripts from Powershell across multiple databases
Re: How to execute sql scripts from Powershell across multiple databases
I have an tsql script that I want to run across a list of databases. How is the best way to do this in Powershell? Thanks.My example below, using just the SMO and not breaking up the batches, the ExecuteWithResults give the following error when the .sql file contains a GO. My script files are as simple as a DECLARE and then a GO.
WARNING: SQL Script Failed
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-list" comm
and which is conflicting with the default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
Also, when executing from the ISE, is there a way to force the ISE to release the files. I am having to close the ISE and reopen my script every time I want to make a testing change to the .sql file.
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$scriptspath = "C:\temp\psExecuteSQLScripts\scripts"
$SQLServer = "fidevc10"
$SQLDB = "Bank03"
# Create SMO Server Object
$Server = New-Object ('Microsoft.SQLServer.Management.Smo.Server') $SQLServer
# Get SMO DB Object
$db = $Server.Databases[$SQLDB]
# Load All SQL Scripts in Directory
$scripts = Get-ChildItem -Path (Join-Path $scriptspath "*") -Include "*.sql" -Recurse
# Loop through each script and execute
foreach ($SQLScript in $scripts)
$fullpath = $SQLScript.FullName
# Read the Script File into Powershell Memory
$reader = New-Object System.IO.StreamReader($fullpath)
$script = $reader.ReadToEnd()
# Execute SQL
Write-Host "Executing $SQLScript on $SQLDB...."
try
$ds = $db.ExecuteWithResults($script)
Foreach ($t in $ds.Tables)
Foreach ($r in $t.Rows)
Foreach ($c in $t.Columns)
Write-Host $c.ColumnName "=" $r.Item($c)
Write-Host "Complete"
catch [Exception]
Write-Warning "SQL Script Failed"
echo $_.Exception|format-list -force
Write-Host " " -BackgroundColor DarkCyan -
Issue with calling Shell Script using DBMS_SCHEDULER
Hi All,
I am executing a shell script using DBMS_SCHEDULER from APEX web page. Execution part is working fine without any issues.
In my shell script file (abc.sh) I have few oracle sql procedure calls which connects back to same database and that SQL call is not executing some reason, it not giving any errors.
Inside my shell script code looks like this.
sqlplus -silent $USER/$PASSCODE@$SCONNECT > /dev/null <<END
set pagesize 0 feedback off verify off heading off serveroutput on
echo off linesize 1000
WHENEVER SQLERROR EXIT 9
BEGIN
dbms_output.enable(1000000);
do_enable_cons();
dbms_output.disable;
END;
spool off;
exit;
END
When I run this shell script file from backend it works fine now issues.
Is there any restrictions in executing sql code using DBMS_SCHEDULER? Any ones help is much appreciated.
-Regardsjames. wrote:
Thanks you sb and Sybrand . It is problem with environment variables. After running .bash_profile in the beginning of the shell script, it is working fine.
One issue is when I check the process it is showing two entries with two different process id's.
The command I used
ps -ef | grep <my script> is COPY & PASTE broken for you?
any reason why you did not show us EXACTLY was produced by OS command above?
>
Is it something wrong with my code or is it normal? Is it really executing two times ?
-Regards
bcm@bcm-laptop:~$ sqlplus user1/user1
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 20 15:14:15 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
15:14:15 SQL> !ps -ef | grep sqlplus
bcm 24577 1903 1 15:14 pts/0 00:00:00 sqlplus
bcm 24579 24577 0 15:14 pts/0 00:00:00 /bin/bash -c ps -ef | grep sqlplus
bcm 24581 24579 0 15:14 pts/0 00:00:00 grep sqlplus
15:14:23 SQL> how many different copies of "sqlplus" running on my laptop based upon actual output above? -
Calling sql script in plsql procedure
Hello,
I have a sql script named mytest.sql and i want to execute this from a stored procedure.
following is the contents of this script
spool d:\mytestsql.txt
select * from tab;
spool off
Actually i want my sql script to run daily to export some tables data.
I can execute this script from a sql prompt but i want to run it from enterprise manager.
I am using oracle 10gR2 on windows2000 system.
Any idea about scheduling the sql script to run automatically??
How to execute this sql script from a plsql procedure??
ThanksHi all,
Thanks for all the replies. I have found the solution with external procedures.
Following is the complete step by step guide.
1. Create the OSCommand Java Class using the following statement:
connect as any user:
create or replace and compile java source named oscommand as
import java.io.*;
public class OSCommand{
public static String Run(String Command){
try{
Runtime.getRuntime().exec(Command);
return("0");
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
2. Create the following Wrapper Function using the following statement:
CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
RETURN VARCHAR2 IS
LANGUAGE JAVA
NAME 'OSCommand.Run(java.lang.String) return int';
3. connect as sys
Execute dbms_java.grant_permission( 'FKHALID','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );
commit;
note: here fkhalid is the oracle user.
connect as fkhalid user:
Declare
expdp_cmd Varchar2(2000);
Begin
expdp_cmd := OSCommand_Run('cmd /c sqlplus fkhalid@mtcedwt/pwd @d:\ORA_DUMPS\mydbexp.sql');
DBMS_OUTPUT.Put_Line(expdp_cmd);
End;
In Unix
Set Serverout On
Declare
x Varchar2(2000);
Begin
x := OSCommand_Run('/home/test/myoscommand.sh')
DBMS_OUTPUT.Put_Line(x);
End;
I will check the dbms_scheduler also and will let you know the results.
Thanks -
Not able to call sql script from shell program
Hi Gurus,
I am facing issue while calling sqlplus script from my shell program. Please find below my shell script. This program I've written and registered as for one of concurrent program
in oracle applications.
p_userid_passwd=$1
p_appl_login=$2
p_user_name=$3
p_request_id=$4
v_conc_request_id=${5}
p_to_role=${6}
p_from_role=${7}
p_subject=${8}
p_body=${9}
p_dist_list=${10}
v_request=${11}
v_file_path_name=/u01/oraspt/REQUEST
cd $APPLCSF/$APPLOUT
echo "v_conc_request_id" $v_conc_request_id
echo "p_to_role" $p_to_role
echo "p_from_role" $p_from_role
echo "p_subject" $p_subject
echo "p_body" $p_body
echo "p_dist_list" $p_dist_list
echo "v_request" $v_request
ls -l $v_request
if [ $? -ne 0 ]
then
echo "No output request generated"
else
echo "Output request generated"
fi
echo "connecting to ftp for placing out file to DB server"
echo FTP to 99.60.17.11
echo username: "oraspt"
echo pw:
ftp -i -n 99.60.17.11 << EOF2
user "oraspt" orakdk
cd $v_file_path_name
put $v_request
bye
EOF2
output=`sqlplus -s /nolog <<EOT
whenever sqlerror exit failure;
connect apps/apps
set verify off;
set serveroutput on size 120000;
DECLARE
l_errbuf varchar2(300);
l_retcode varchar2(300);
BEGIN
XXFND_SEND_MAIL.SEND_NOTIFICATIONS( errbuf => l_errbuf
, retcode => l_retcode
, p_request_id => $v_conc_request_id
, p_to_role => $p_to_role
, p_from_role => $p_from_role
, p_subject => $p_subject
, p_body => $p_body
, p_dist_list => $p_dist_list);
EXCEPTION
when others then
dbms_output.put_line('Error encountered :'||SQLERRM);
END;
EOT
`
echo "connecting to ftp for deleting output file"
echo FTP to 99.60.17.11
echo username: "oraspt"
echo pw:
ftp -i -n 99.60.17.11 << EOF2
user "oraspt" orakdk
cd $v_file_path_name
delete $v_request
bye
EOF2
echo "Deleted successfully"Output for script is as below
v_conc_request_id 451906
p_to_role DC.DKHOO
p_from_role DC.DKHOO
p_subject Receivable audit report10
p_body Please find Audit Report Attachment.
p_dist_list
v_request o451906.out
-rw-r--r-- 1 applspt dba 2368 Dec 28 15:06 o451906.out
Output request generated
connecting to ftp for placing out file to DB server
FTP to 10.60.17.11
username: oraspt
pw:
connecting to ftp for deleting output file
FTP to 10.60.17.11
username: oraspt
pw:
Deleted successfullyPlease let me know how to trigger pl/sql script.
Thanks in advance for your help.
Regards
Nagendra
Edited by: 838961 on Dec 27, 2011 11:25 PMPlease find output as suggested, I've placed set -x in script.
+ p_userid_passwd=APPS/APPS
+ p_appl_login=1110
+ p_user_name=DC.DKHOO
+ p_request_id=451949
+ v_conc_request_id=451945
+ p_to_role=DC.DKHOO
+ p_from_role=DC.DKHOO
+ p_subject=Receivabless
+ p_body=report
+ p_dist_list=
+ v_request=o451945.out
+ v_file_path_name=/u01/oraspt/REQUEST
+ cd /u01/applspt/inst/apps/SPT_nfs-stg-app1/logs/appl/conc/out
+ echo v_conc_request_id 451945
v_conc_request_id 451945
+ echo p_to_role DC.DKHOO
p_to_role DC.DKHOO
+ echo p_from_role DC.DKHOO
p_from_role DC.DKHOO
+ echo p_subject Receivabless
p_subject Receivabless
+ echo p_body report
p_body report
+ echo p_dist_list
p_dist_list
+ echo v_request o451945.out
v_request o451945.out
+ ls -l o451945.out
-rw-r--r-- 1 applspt dba 2368 Dec 28 15:54 o451945.out
+ '[' 0 -ne 0 ']'
+ echo 'Output request generated'
Output request generated
+ echo 'connecting to ftp for placing out file to DB server'
connecting to ftp for placing out file to DB server
+ echo FTP to 10.60.17.11
FTP to 10.60.17.11
+ echo username: oraspt
username: oraspt
+ echo pw:
pw:
+ ftp -i -n 10.60.17.11
++ sqlplus -s /nolog
+ output=Connected.
+ echo 'connecting to ftp for deleting output file'
connecting to ftp for deleting output file
+ echo FTP to 10.60.17.11
FTP to 10.60.17.11
+ echo username: oraspt
username: oraspt
+ echo pw:
pw:
+ ftp -i -n 10.60.17.11
+ echo 'Deleted successfully'
Deleted successfully
Maybe you are looking for
-
my hard wired network works fine with vista media center connecting to the extender and also on another win7 pc connecting but my main pc connects for 1 second then on the extender the screen goes black (sounds can be heard) then after a few minutes
-
Cheque Writer (generic) gives error
Dear guruz, I am getting this error when i run the "Cheque Writer (generic)" HR_6882_HRPROC_ASSERT LOCATION pyjavaco:1 APP-PAY-06882: Assertion failure detected at location pyjavaco:1. Cause: an internal error has occurred at location pyjavaco:1. Act
-
Hi, Has anyone idea how can I dynamically add checkBox in an applet? Currently I am dispalying one TextBox in an applet and I want the same text to appear as a text box name when I click on button.. I tried adding code in PaintComponent method but it
-
i Just opened my new iMac i7 and was very excited. BUT! when i started it up my cooler fan is apparently going crazy. It seems as if theres a hardware problem before i even got it up and running. Anybody who has the same experience?
-
Automatic email from an Excel Spreadsheet
Hi i have been recently asked to find out if there may be a program or something that will automatically email all the information pertaining to a particular email address on an Excel spreadsheet. Ex: So if my email is assigned to 3 things within the