Embed SQL in shell script
I'm trying to embed sql statements in shell.
I'm new to this..
Can someone please pass some relevant document links on the web which demonstrates it?
What I'm looking for is:
1) How to pass variables from shell environment to sql
2) How to pass values back to the shell from sql
Example:
Say, I want to run a concurrent request ( inside a shell script) . Then I want to check the status of this concurrent requests from FND_CONCURRENT_REQUESTS
For which I have do a:
#/bin/bash
#Submit the request
CONCSUB APPS/APPS SYSADMIN 'System Administrator' SYSADMIN CONCURRENT FND FNDSCURS >> /tmp/${TWO_TASK}request.log
#Here, I pull out the value of request id from the log #in v_request_no
v_request_no=`cat /tmp/${TWO_TASK}request.log | cut -d" " -f3`
echo "Submitted request No: ${v_request_no}"
Now, I want to check the status of this request, for which I want to embed the sql:
select status_code from FND_CONCURRENT_REQUESTS where request_id=${v_request_id}
How do I embed this?
And later, I want to pass the value of "status_code" back to my shell and do some manipulation.
How do I get the value ( of status_code) back in shell script?
I did a quick hunt on the google to find a relevant doc. No luck yet, so I thought I'll post it here and then go back to some more hunting.
Message was edited by:
itzz.me
Replying to myself instead of editing previous post. Confusing either way, hopefully I picked the less-confusing route.
The second script snippet that I posted would work really well except for one tiny detail: exit codes have to be numeric. The status_code column in FND_CONCURRENT_REQUESTS is certainly not numeric. :-)
Here's something that should work. I even checked it for syntax this time, because, well, it's really ugly. :-) Needless to say, you'll need to modify it slightly to plug into your script, since I hard-coded a requestid for purposes of illustration. Please note that the sqlplus command in the here document is enclosed in backticks, not single quotes:
----begin code snippet---
#!/bin/bash
v_request_id=2415616 #Just an example, sub your own value here
status_code=`sqlplus -s apps/appspass<<EOF | grep Code | cut -f2 -d:
select 'Code:' || status_code
from fnd_concurrent_requests
where request_id = $v_request_id;
exit;
EOF`
echo "Status code is: $status_code"
----end code snippet-------
If you can't pass in the apps password from the environment, and have to hard-code a password into the script (yecccchhh), I'd suggest setting up a read-only user with SELECT privileges on FND_CONCURRENT_REQUESTS, and running sqlplus as the read-only user instead of apps.
Similar Messages
-
Hi All,
I need help on sql loader shell scripting basically since my input file is csv file will load into some target table say xx_90 along defining with control and data file. what where the data that goes into the bad file a segment of scripting that keep watching on badfile directory path if any bad file it finds it should move to a sperate database error table.
Plz any sqlloader shellscripting experts can provide me the solution for this. Its a very urgent code i need to deliver I need the sample code for this your help is highy appreciated
thanku
sahanathanku..............when the load fails it moves to bad file script something like filewatcher it sees the data in the badfile and loads into the database error table........as i am basically businessobjects developer as for time being they have assinged me the task i did few manual loading on sql loader but i never have any experince on writing unix scripting i am quite worried to get this script done........
can i use the samecode for the failed bad records into seperate external table......
here i would change the path location and the rest goes as it isright............................i have the script for loading the datainto the targetsomething like this:
sqlldr userid=ops$NGPTQMS/[email protected] \
control=${evncpaq1/apps/cp/cm/r11.5.10/geae/gl/include/PAY0001_test.ctl} \
data=${evncpaq1/data/infile/mon_gross_det.dat} \
log=${evncpaq1/data/infile/mon_gross_det.log} \
discard=${evncpaq1/data/infile/mon_gross_det.dis} \
errors=999
#bad=${BAD_FILE} \
if [ $? -ne 0 ]; then
echo "Error ! The sql loader call failed "
exit 1
fi
IF any error is there in the script plz modify it and plz provide the complete code where to incorporate the code which you have written for bad file. Would be set it in seqence the steps so that i can run it in cron tab basically i have no other support for me to assist me on the job.......
my dba has sent me the mail something like this:
Please see the attached script to archive the source file once we are done with loading the data to the database. You already have the script for loading the data to the database. Please incorporate the attached script with your loading script. This script is generic and can be used to archive the bad file also once it has been loaded into the database (in case of any failures). This script send an email in case of any failures to the defined email distribution list. Right now the assumption is to run this through the cron. It we need to run this through the Appworx I will have to do some changes in the script. Also we will have to install the appworx agent on the server. Please let me if we need to need to run this through appworx I will create the appworx module for the same.
and the archive script he sent is:
. $HOME/.profile
# Script to Archive SysLog files
# This script accepts 2 parameters
# - 1: Script Name 2: File Name
# Created By : Pravin Darbare
# Creation Date : 03/19/2008
# Modified Date :
# Modification History :
echo "Starting SysLog_archiving Process"
# Set Environmental Variables
echo "Invoke Set Variable Script `date '+%H%M%S'`"
# Set Local Script Variables
#SCRIPT_NAME=$1
SOURCE_DIR=$1
FILE_NAME=$2
# Zipping and Archive Source File
echo "Zip Source file `date '+%H%M%S'`"
#cp $LOAD_SRC_FILES/$SOURCE_DIR/$FILE_NAME $LOAD_SRC_FILES/syslog/Old_$FILE_NAME
gzip /$SOURCE_DIR/$FILE_NAME
check_rtn_status=$?
if [ $check_rtn_status != 0 ]; then
echo "Zipping source file Syslog process unsuccessfull"
mailx -s "Zipping source file during Syslog unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
exit 1
fi
echo "Archive Source File `date '+%H%M%S'`"
mv /$SOURCE_DIR/$FILE_NAME.gz /$SOURCE_DIR/archive/$FILE_NAME.gz$FILE_EXT
check_rtn_status=$?
if [ $check_rtn_status != 0 ]; then
echo "Archiving source file during Syslog load process unsuccessfull"
mailx -s "Archiving source file during Syslog load process unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
exit 1
fi
# example of calling file Syslog_archiving_Files.sh /apps/syslog/source_dir a.txt
# example of calling file (Bad file) Syslog_archiving_Files.sh /apps/syslog/source_dir_bad a.txt
# You need to have directory "archive" in both pathes .
based on the complete detailed mail must having some view plz provide me something like exact code the rest path directories i will change it........
for me its highly urgent to keep up my job
Your support is highly appreciated
Thanks&Regards
sahana -
Hi,
I want to study in details about how to use shell script in pl/sql codes. Can any one suggest some useful link on the same.
Nordiksmon wrote:
BluShadow wrote:
miriam_omaha wrote:
If you mean execute a shell script from a procedure, there are ways, not easy ways, to execute a shell script - try this thread on that topic:Not easy?
What's not easy about setting up a job using DBMS_SCHEDULER which can directly call any executable at the operating system level?that doesn't meet the requirement, it's about executing host commands from within plsql.Which you can do with DBMS_SCHEDULER by creating a job to execute straight away. DBMS_SCHEDULER can execute operating system commands...
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#i1010013
>
'EXECUTABLE'
This specifies that the program is external to the database. External programs implies anything that can be executed from the operating system's command line. AnyData arguments are not supported with job or program type EXECUTABLE. -
Passing variable from sql to shell script
Usually we can pass arguments from shell script to the sql that us called inside the shell script. But I also want to do the reverse. I have the location of my backup path in a table. I want to run the rman script (shell), read this parameter from the table and use this to construct the "format" path in rman. Anyone has any ideas about this. Thanks.
To achieve getting the modified value from the table everytime the job runs, I encapsulated this in another job.
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME => 'TEST_LOGS_MAIN',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'declare
v_aname varchar2(32);
begin
select aname into v_aname from attr where attrid = 3;
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME => ''TEST_LOGS'',
JOB_TYPE => ''EXECUTABLE'',
JOB_ACTION => ''/opt/sql/testy.sh'',
number_of_arguments => 1,
COMMENTS => ''TEST'');
dbms_scheduler.set_job_argument_value(''TEST_LOGS'',1,v_aname);
dbms_scheduler.enable(''TEST_LOGS'');
end;',
REPEAT_INTERVAL => 'FREQ=MINUTELY',
ENABLED => TRUE);
END;
/ -
Calling sql through shell script
How do i call a sql file through shell script in unix ?
Rahul India wrote:
export ORACLE_HOME=$ORACLE_BASE/product/10g
cd $ORACLE_HOME
set `sqlplus -s <SCHEMA_NAME>/<SCHEMA_PASSWORD> <<EOF
@r_100.sql
exit;
EOF`THIS SCRIPT IS OK?You'll also need to set ORACLE_SID
And I don't know why everyone is putting the reference to sqlplus inside a "set" valuation, nor why they are putting the reference to the script in a redirected input stream. All you need is
sqlplus -s user/password @r_100.sqlAnd to insure the invironment is correctly set:
export ORACLE_SID=whatever
export ORAENV_ASK=NO
. oraenv
unset ORAENV_ASK=NO
sqlplus -s user/password @r_100.sql -
Loading incomplete using sqlplus_exec_template.sql in shell script
Hi,
I've tried to automate the dataloading by calling sqlplus_exec_template.sql for each mapping in the shell script bash. (I comment out the last exit line in the script). But the loading were always partially complete for those that take longer time, says more than 5 or 10min. I've also tried to call each mapping in different shell and got the same result. How do you work around this? Below is part of the lines in my shell script. Thanks.
sqlplus -s test_rta/test_rta << EOF
@sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_SUP_MAP' ',' ','
@sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_PART_MAP' ',' ','
EOFI 've tried to use :
sqlplus username/[email protected] @C:\OWB\owb\rtp\sql\sqlplus_exec_template.sql
rtschema OWBLOCATION SQL_LOADER CRD_APPL_MAPPING "," ","
where OWBLOCATION I have used the deploy location of the mapping for my case, created within OWB. The value is CCS_DEPLOY.
But the error is the same :
======================================================
Stage 1: Decoding Parameters
| location_name=CCS_DEPLOY
| task_type=SQL_LOADER
| task_name=CRD_APPL_MAPPING
Stage 2: Opening Task
declare
ERROR at line 1:
ORA-20001: Task not found - Please check the Task Type, Name and Location are
correct.
ORA-06512: at line 261
========================================================
could you tell me the SQL used by WB_RT_API to get the task from runtime schema. So that I could check the correct location myself.
Or how could I view the pl/sql of WB_RT_API_EXEC which is wrapped.
Thx for your help.
Rg.
CH -
Capturing Users with running sql in shell script after every 10min
Hi All,
we have a strange prob. of database crash, therefore decided to check what users do when OS/DB crashes,
i need your input in RUNNING/SCHEDULING such a script which gathers all active users with running SQL and append in a logfile so that we are aware of what happened when DB/OS Crashed.
i can run this run a query from V$SESSION,V$SQL, and V$PROCESS but i need your input writing such a SHELL Script and scheduling can run by CRON.
Regards.Here ya go.
(Assuming you want a script to run against one sid)
script:
#!/bin/ksh
# Set environment
. $HOME/.profile
export ORACLE_SID=your sid
sqlplus <<! > /some_report_file
/ as sysdba
sql you want to execute here*
exit
cron entry:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /your/script/name/here > /dev/null 2>&1 -
Dear All,
I want to call an sql script within a unix shell script. I want to pass a parameter into the shell script which should be used as a parameter in teh sql script.
e.g
$ ./shell1.sh 5000129
here 5000129 is a prameter
inside shell script i am calling one sql script
e.g.
@script1.sql;
inside the sql script I have an update statement
UPDATE abc set xx = 22 where id = 500129;
as you can see the 5000129 passed as shell script parameter, is being passed as parameter in the sql script.
Please can you advise how can I achieve this?
Many Thanks,Hi
You could try something like this.
tmpSQLFile=$EXTLOG_DIR/tmpSQLFile_$$.sql
tmpSpoolFile=$EXTLOG_DIR/tmpSpoolFile_$$.sql
export ORACLE_PWD=`cat /home/oracle/secure/runtime_user.dat`
echo "spool $_tmpSpoolFile" > $_tmpSQLFile
echo "SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON LINESIZE 10000 TIMING OFF" >> $_tmpSQLFile
echo "begin" >> $_tmpSQLFile
echo "DW_MGT_SCHEMA.PKG_RUNTIME_HANDLER.SP_UPD_RUNTIME_EXT_CTL_LOG_TDT(p_transfer_date => '$today', p_schedule_id => $schedule_id);" >> $_tmpSQLFile
echo "end;" >> $_tmpSQLFile
echo "/" >> $_tmpSQLFile
echo "exit" >> $_tmpSQLFile
sqlplus ${ORACLE_USER}@${ORACLE_SID} @$_tmpSQLFile << EOT
`echo $ORACLE_PWD`
EOTCheers
Gary -
Can I embed a full shell script inside an applescript?
I have a friend who is running Tiger on a PPC Mac and wants to download a large number of files from the web. Unfortunately, this friend is barely able to do basic web browsing with Safari or Firefox.
I thought of just sending him a shell script with a lot of curl commands, but I don't suppose making it executable on my Mac would make it executable on his. I would like to be able to send him an Applescript that he could just run by clicking on it, but it would be awkward to make each curl command a separete shell script within the applescript..
Is there a way of directly including in an applescript a multi-line shell script as a single entity that invokes only one shell? I know I can do it by putting the shell script in a separate file and have the applescript give it the necessary permissions, but then I'd have to explain to my friend where to put the shell script!While it is possible to do this in the Applescript if the shell script gets at all complicated escaping characters and debugging will be much harder then it needs to be.
For example taking twtwtw's example and just adding one Applescript variable gives:
set dir to POSIX path of (choose folder)
set ss to "cd " & dir & "
echo 'This is a file list for the \"" & dir & "\" folder'
echo
ls -l"
set dlf to do shell script ss
display alert dlf giving up after 10
Twtwtw's suggestion of creating an Applescript application bundle is, I believe, the best way to go. You can keep the shell script and Applescript separate making maintenance and debugging much simpler and your friend just gets one 'file' to install and run.
regards -
Need to call Shell script that uses SQL loader in APex4.1/11g
Hi there!
I have a requirement, wherein I have to call a shell script that connects to an external server, ftp's a file in and then uses sqlloader to load data into our table. Now we have the ftp script that does this for another program, but is a scheduled job. I wanted to call the ftp shell script from within APEX. Any suggestions on how this can be done, what PL/SQL logic can we use? I see online some people using dbms scheduler for this?
Thank you
SunHi,
Create some sh script on your oracle host machine where you can join into external server and run the process.
something like:
run_external_sh.sh
#!/bin/sh
ssh ext_user@ext_host ./sqlloader/import/import.shThen create a external JOB to call it via ORACLE(PL/SQL)
-- Call Shell Script.
BEGIN
DBMS_SCHEDULER.create_program (
program_name => 'external_call_sh',
program_type => 'EXECUTABLE',
program_action => '/local_host/call_external/sh/run_external_sh.sh',
number_of_arguments => 0,
enabled => TRUE,
comments => 'Call external SH script');
END;
/Now you can create a scheduled/or not scheduled JOB
-- Job defined by an existing program and schedule.
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'jb_external_call_sh',
program_name => 'external_call_sh',
schedule_name => 'external_call_scheduler', -- created scheduler
enabled => TRUE,
comments => 'Job defined by an existing external_call_sh program and schedule.');
END;
/Now you can call the JOB in APEX in PL/SQL process.
BEGIN
-- Run job synchronously.
DBMS_SCHEDULER.run_job (job_name => 'jb_external_call_sh');
END;Regards
J :D -
Pls give some shell scripting for sql/plsql
pls give some shell scripting for sql/plsql
794244 wrote:
pls give some shell scripting for sql/plsqlNeither SQL or PL/SQL are shell script languages. Both are server side languages that executes inside an Oracle database server process.
This is an important concept to understand when using SQL*Plus for example to "script" interaction with an Oracle database. -
Passing shell script variable to sql file by reference (bind variable)
Hi All,
I need to import around 50 files every 15 minutes into my target table.
I am using shell script and call procedure to do transform.
I used crontab to do this automate task.
Here is my shell script and sql file:
shell script:
#!/bin/sh
export ORACLE_HOME=/u01/app/oracle/product/9.2.0.4.0
export PATH=$ORACLE_HOME/bin
find /path_rawfile/rawfile -iname raw\*.in > myfile.lst
nfile=1
while [ true ]
do
read iFile #read a line
if [ $? -ne 0 ] #Break if EOF
then
break
fi
#$PATH/sqlplus -s /NOLOG @load_raw.sql $iFile
#/bin/mv -f $iFile /path_rawfile/rawfile/done/
done < myfile.lst
sql file:
connect test/test@evn1
set serveroutput on
variable filename varchar2(50)
begin
:filename := '&1';
exec my_tranform(:filename);
dbms_output.put_line(:filename);
end;
exit;
Even I used bind variable pass to procedure my_transform...
But when i query in sys.v_$sqlarea, the :filename:='&1' still hard parse to sqlarea.
One filename one statement and keep increasing ..
Could everyone help me to change it to bind varialbe(soft parse)?
I would like to incresae my database performance.
Thanks in advance.
Cheer
Message was edited by:
luxIt is the procedure.
It's my fault.
Here is my SQL file again:
conn test/test@evn1
variable filename varchar2(500);
exec :filename:='&1';
exec my_transform(:filename);
exit;
I call this sql file from shell script and call in loop due to i need to load all file one time.
Once i use <<EOF it raise error that's why when I deleted it.
Anyway, what I need to do here is to use bind variable (soft parse).
Since I need to load around 50 files every 15 minutes.
exec :filename:='&1'; this statmet have found hard parse in v_$sqlarea.
I would like to change this to bind varialbe.
Thanks again for your help. -
How to call shell script from a pl/sql procedure
Hi all,
I am little bit new to plsql programming, i have a small problem as follows
I have to call a shell script from a pl/sql procedure ..
Please suggest me some methods in oracle 10g, which i could make use of to achieve my goal. also please tell me what are the constraints for those methods if any.
I already came across dbms_scheduler, but i have got a problem and its nor executing properly its exiting giving 255 error or saying that permission problem, but i have already given full access to my shell scripts.
Thanks in advance
Best Regards
SatyaHi,
Read this thread, perhaps is there your response :
Host...
Nicolas. -
Executing if condition in a sql prompt with in a shell script
Hi all,
i need to write a shell script where i need to execute a sql statement. if the count from the above sql is greater than certain value i need to execute a another sql statement.After some time i need to check the count again using above sql and if the count is less than certain value i need to execute a different sql statement. One more time i need to check the count and then i need to get an email.
Could anyone help me in completing this script
Thanks,Could anyone help me in completing this scriptNot really because "shell script" is OS & Shell dependent & you decided to NOT share these details with us.
Just write a PL/SQL procedure & then you have an OS independent solution! -
Catch a value from a pl*sql function in a shell script
Hi all,
I have a shell script that simply calls the following pl*sql function.
echo "execute scott.my_pkg.test('FDLmaster');\n exit;" >./pippo.sql
sqlplus scott/tiger @/fidcap_ftp/FDL/SCRIPTS/pippo.sql
What I have to do to catch the value returned from the function test?
Thanks in advance
best regards
MarioSQL> create or replace function do_something return varchar2 is
2 begin
3 return ('Something');
4* end;
SQL> /
Function created.
SQL> select do_something from dual;
DO_SOMETHING
Something
SQL> save pippo
Created file pippo.sql
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
[linuxas tmp test10]$ echo exit >>pippo.sql
[linuxas tmp test10]$ VAR=`sqlplus -s scott/tiger @pippo`
[linuxas tmp test10]$ echo $VAR | cut -f3 -d" "
Something
[linuxas tmp test10]$
Maybe you are looking for
-
Solid State Hard Drive vs Mechanical
I'm ready to order a new MacBook Pro, which hard Drive would I be better off with. The solid state is 600 bucks, for only 128 gig I can get a 350 gig 7200 for much less
-
How to call webservices from ADF page
Hi, I am using ADFBC. I want to call webservices from ADF page.please give examples of sample program on how to call a web service from the ADF pages.please give examples. please help me. Thanks,
-
Installing HTTP Server After APEX2.2
Hiii i have installed the APEX 2.2 and after i have finished i remembered that i have to install the HTTP Server os installed it .... but i dont know if it will Succeed or NOT ... now i am in the POST INSTALLATION TASKS ON " Configuring Oracle HTTP S
-
Error when loading the callback component
Hi friends Am getting this error. Error when loading the callback component. Am working in Travel expense workflow which is 2 level based on condition. If its EG > 8 its one level and EG < 8 its 2 level. When the approver does the approval am chan
-
Changed the name of "home" now site won't work
hi. I changed my home page. What i did was make a duplicate, then deleted the original home folder, then renamed the duplicate to 'home'. (it won't allow me to use a cap "H" though) I had the site masked and forwarded via Godaddy, and now my domain w