SQL-Scripts into a Shell script
Hi!
After creating the database on a Linux machine, we need to create our Schema in that database.This Schema has many objects(tables, views,
procs, triggers etc.). So executing each individual script would not be sensible. Is it possible to pack all sql scripts into one shell script and run that one?
Thanks for your feedback/examples/links!
If it's one-off task, why not put all of them in a SQL file and run it from SQL* Plus rather than using shell to cause sql plus which will in turn have to call the script?
If it's a recurring task and you insist that you want to do it from Unix shell, you can do something like this:
Place all scripts in a single file and put it under $HOME for ex. (save it as run_all_scripts.sql)
Then write a shell script something like this:
#!/bin/ksh
connect_schema=scott/tiger
sqlplus -s $connect_schema <<EOF
@$HOME/run_all_scripts.sql
EOF
Regards
Venkat
Similar Messages
-
Sql Loader by using shell script, not able to insert data
Hi,
I am trying to dump the data by using shell script.(in shell script i am having sqlldr command)(its a host excutable method cocurrent program)
When i am loading the data, by placing my files(.ctl,.prog,.csv,symbolink file for .prog) in $Custom_top/bin, it is loading exactly. 17000 records inserted.
But if i am loading the data by placing my files in $custom_top/custom_folders. unable to insert total data. only 43 records inserting.
Please any one can help me.
Thanks in advance.
Rama.Srini, Thanks a lot for ur reply,
Oracle Apps version R12,
Microsoft windows XP profissional
Version 2002 service Pack 3
My Control file Script is:
load data
infile '$XADP_TOP/data/CPIU/in/XXOKS_Price_Increase.csv'
append
into table XXOKS_CONTRACT_PRICE_INCR_DTLS
fields terminated BY ',' optionally enclosed by '"'
TRAILING NULLCOLS
(EXCLUSION_FLAG,
LEGACY_NUMBER,
CUSTOMER_NUMBER,
CUSTOMER_NAME,
REQUEST_ID,
CONTRACT_NUMBER,
CONTRACT_START_DATE,
CONTRACT_END,
REQUEST_LINE_ID,
LINE_START_DATE,
LINE_END_DATE,
ITEM_NUMBER,
ITEM_DESCRIPTION,
UNIT_PRICE,
QTY,
NEW_UNIT_PRICE,
LINE_AMOUNT,
NEW_LINE_AMOUNT,
PRICE_INCREASED_DATE,
PERCENTAGE_INCREASED,
ORIGINAL_CONTRACT_AMOUNT,
NEW_CONTRACT_AMOUNT,
PRICE_INCREASE_AMOUNT)
My .prog File is: Please fidn that i created symbolink file also for my .prog.
if [ -z $XADP_TOP ];then
echo "XADP_TOP environment variable is not set!"
exit 1
fi
cd $XADP_TOP/data/CPIU/in
DATE=`date +%y%m%d:%H%M`
i_program_name="$0"
i_ora_pwd="$1"
i_user_id="$2"
i_user_name="$3"
i_request_id="$4"
i_ftp_host_name="$5"
i_ftp_user_name="$6"
i_ftp_user_password="$7"
ftp_prog() {
# FTP Function to reuse the FTP Commands
if [ $# -ne 6 ];then
echo "Usage : ftp_prog <Hostname> <User name> <Password> <Remote Directory> <command> <filename>"
exit 2
fi
l_ftp_host_name="$1"
l_ftp_user_name="$2"
l_ftp_user_password="$3"
l_ftpdir="$4"
l_ftp_command="$5"
l_ftp_filename="$6"
ftp -v -n ${l_ftp_host_name} <<EOF
user ${l_ftp_user_name} ${l_ftp_user_password}
ascii
cd ${l_ftpdir}
${l_ftp_command} ${l_ftp_filename}
quit
EOF
#exit $?
# setting the ftp directory
#ftpdir="/`echo ${TWO_TASK:-$ORACLE_SID}|tr "[A-Z]" "[a-z]"`/CPIU"
##ftpdir="/FinTEST/quoting/PS/ar"
ftpdir="$XADP_TOP/data/CPIU/in"
# setting the in directory and out directory
indir="$XADP_TOP/data/CPIU/in"
outdir="$XADP_TOP/data/CPIU/out"
ftp_prog ${i_ftp_host_name} ${i_ftp_user_name} ${i_ftp_user_password} ${ftpdir} get XXOKS_Price_Increase.csv
echo $ftpdir
echo "Converting the data file into unix mode"
dos2unix XXOKS_Price_Increase.csv XXOKS_Price_Increase.csv
chmod 777 XXOKS_Price_Increase.csv
cd $XADP_TOP/bin
echo "Trying to excute sqlldr and entering into the into control file"
$ORACLE_HOME/bin/sqlldr userid=$i_ora_pwd control=XXOKS_PRICE_INCR_LOAD log=$XADP_TOP/log/XXOKS_PRICE_INCR_LOAD_${DATE}.log;
exit_status=$?
echo "Checking the status and giving permissions to the data file which in in dir"
if [ $exit_status -eq 0 ]; then
cd $XADP_TOP/data/CPIU/in
chmod 777 XXOKS_Price_Increase.csv
echo "try to move data file into out dir"
# Moving the file to out directory
mv XXOKS_Price_Increase.csv ${outdir}/XXOKS_Price_Increase.csv_${DATE}
#echo "ready to zip file in out dir step6"
# Zipping the file
#gzip -f ${outdir}/XXOKS_Price_Increase.csv_${DATE}
echo "deleting the file which is in dir"
# Deleting the file from in directory
/bin/rm -f ${indir}/XXOKS_Price_Increase.csv
# Deleting from the remote directory
ftp_prog ${i_ftp_host_name} ${i_ftp_user_name} ${i_ftp_user_password} ${ftpdir} delete XXOKS_Price_Increase.csv
echo "sqlloader finished successfully."
else
echo "Error in loader"
##echo "Loader error in Price Increase Detials File ${i_file}"
fi
exit $exit_status
And My Log file Comments are
SQL*Loader: Release 10.1.0.5.0 - Production on Thu Dec 3 01:32:08 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: XXOKS_PRICE_INCR_LOAD.ctl
Data File: /oesapp/applmgr/GIS11/apps/apps_st/appl/xadp/12.0.0/data/CPIU/in/XXOKS_Price_Increase.csv
Bad File: XXOKS_Price_Increase.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table XXOKS_CONTRACT_PRICE_INCR_DTLS, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
EXCLUSION_FLAG FIRST * , O(") CHARACTER
LEGACY_NUMBER NEXT * , O(") CHARACTER
CUSTOMER_NUMBER NEXT * , O(") CHARACTER
CUSTOMER_NAME NEXT * , O(") CHARACTER
REQUEST_ID NEXT * , O(") CHARACTER
CONTRACT_NUMBER NEXT * , O(") CHARACTER
CONTRACT_START_DATE NEXT * , O(") CHARACTER
CONTRACT_END NEXT * , O(") CHARACTER
REQUEST_LINE_ID NEXT * , O(") CHARACTER
LINE_START_DATE NEXT * , O(") CHARACTER
LINE_END_DATE NEXT * , O(") CHARACTER
ITEM_NUMBER NEXT * , O(") CHARACTER
ITEM_DESCRIPTION NEXT * , O(") CHARACTER
UNIT_PRICE NEXT * , O(") CHARACTER
QTY NEXT * , O(") CHARACTER
NEW_UNIT_PRICE NEXT * , O(") CHARACTER
LINE_AMOUNT NEXT * , O(") CHARACTER
NEW_LINE_AMOUNT NEXT * , O(") CHARACTER
PRICE_INCREASED_DATE NEXT * , O(") CHARACTER
PERCENTAGE_INCREASED NEXT * , O(") CHARACTER
ORIGINAL_CONTRACT_AMOUNT NEXT * , O(") CHARACTER
NEW_CONTRACT_AMOUNT NEXT * , O(") CHARACTER
PRICE_INCREASE_AMOUNT NEXT * , O(") CHARACTER
value used for ROWS parameter changed from 64 to 43
Table XXOKS_CONTRACT_PRICE_INCR_DTLS:
43 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 255162 bytes(43 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 43
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Thu Dec 03 01:32:08 2009
Run ended on Thu Dec 03 01:32:08 2009
Elapsed time was: 00:00:00.19
CPU time was: 00:00:00.04
Plz srini help me.
Thanks in advance
Rama.. -
Hello all,
We are running Oracle 10G on Unix and I am fairly new to Unix. I know how to assign a SQL select statements values to an alias in a SQL environment such as TOAD, such as for example;
Select LogID ID, LogType Type, LogDate Date from audit_logs
where LogDate = sysdate;
That will give the determined values the labels of ID, Type, and Date respectively. But how do I assign the multiple SQL select values to shell script variables in UNIX? I have found how to do it for a single value but not a multiple value.
Thanks in advance
Regards
AlanoThanks for reply.
What we want to do is ensure a relevant file was deleted by a database package\procedure that is part of a third party application. My aim will be to interrogate the relevant table, extract the three relevant fields and join them together into one line\string that will be appended to a lof file
Thanks again in advance
Regards
Alano -
SQL in Connection with shell scripts
Hello everyone,
I have a conceptual question:
If people like to implement their SQL-Scripts attached on a shell script(Ruby, Perl, or even OS-Shell), what are actually the benefits doing this? Can someone please give me a szenario, which is very effectively if we do it with combination with shell-script.
My second question: does oracle sql developer support this shell combination?
Thank you..Wrapping sql script in a shell script provides flexibility. Shell can provide better parameter validation than SQL, better output handling, and better error trapping. Personally I would have the sql script separately for purist modularisation reasons, but you can merge the two.
e.g.
getdate.sql
select sysdate from dual;getdate.sh can look like this
sqlplus user/pwd @getdateor
sqlplus user/pwd <<EOSQL
@getdate
EOSQLor
sqlplus user/pwd <<EOSQL
select sysdate from dual;
exit
EOSQLMy preference would be for either of the first two.
You can use various shell facilities to capture the output of the sql statement for use elsewhere. Variations of the above example can be use to get the current database date and time into the shell environment for use in other queries, or in the shell itself.
You can run SQL Developer from the command line, but the tool of choice for command line is SQL Plus. -
Error Handling with sql *plus from a shell script
When I execute sql plus in a shell script with the wrong username/pass pair, the shell script hangs without terminating. What is the proper way to execute sql plus in a shell script that will catch a login failure and make sure the script doesn't hang?
Example:
We execute the following in our shell script:
sqlplus ${ORACLE_INST} @./sql/ftp_ledger_put.sql
Now if somebody comes along and alters the login then the script would hang. Is there a way to have the script exit gracefully?Not the most elegant solution but.......
sqlplus <<EOD 2>&1 >some_log_file
user/pwd
@somescript
exit
EOD
Because sqlplus allows for 3 tries at log in if user/pwd is not valid it will try to use subsequent lines. Each will fail.
You have to look in some_log_file to determine success/failure
Ken -
Merging all DB scripts into a single script for deployment
Hi,
I'm using an Oracle Database Project in Visual Studio to store single scripts for each database object, which I like a lot. What I don't know is how to merge all those scripts into a single script now that I'm ready for deployment. I would prefer to give the DBA guy a single script with all the objects and not one script per DB object.
Is there any way to achieve this?
JulioHi,
I'm playing with this stuff these days and Yes, there is a possibility:
Under Visual Studio:
Open your Database Edition Project
Goto "Server Explorer"
You should have previously created a connection to your Target DB.
Open that connection. you have a collection of folders.
Select/Open the Schema Folder, then the Tables Folder.
Select the Tables you want to Script, right-click and select "Generate Create Script to Project".
Enter a Scriptname and click OK
That's all.
Going back to your Project, you shuld find a Script into your "Script" Folder.
The problem is that you cannot create separate Scripts when selecting multiple tables, as I stated in my Post "ODT lacks some functionnalities"
Hope it helps
Rgds
P.Cury -
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]$ -
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
=============================================================== -
How to submit an input dynamically to an sql script in a shell script
Dear all,
I have a shell script myscript.sh, in that I am running an sql script , say mysql.sql, the sql script prompts for a value, and I have to type that prompted value to run the script. How can I give this value in my shell script itself.
Sample script
#!/bin/bash
echo "script starting at $(date)"
sqlplus apps/apps @mysql.sql
echo "script completed at $(date)"
exit
Regards,
CharanHi,
Please see
$cat sql_para.sh
#!/bin/bash
. .bash_profile
sqlplus -s apps/apps @status $1
$cat status.sql
select status from v$instance where host_name='&1';
exit;$./sql_para.sh TEST
You may also see
http://www.nsa.no/259/shell-scripting-dbas-using-awk-manipulate-oratab
https://communities.bmc.com/communities/docs/DOC-9942
Thanks -
Passing Multiple Parameters to SQL Script from a Shell Script
Hi Friends,
I have SQL script which accepts 6 parameters.
I am calling this from a shell script as shown below:
sqlplus -s ${ORACLE_ID} @${SQLPATH}KORONT_041.sql ${USER_ID} ${PDC} ${item_number} ${KORDC} ${PDCSET} ${last_Updated_in_hours} Out of the six parameters, item_number is not a mandatory parameter.
When i pass all six parameters, there is no issue.
But when i leave item_number blank, i am getting the below error
Enter value for 6:
User requested Interrupt or EOF detected.Based on the error, it seems that the NULL values for item_number is ignored and SQL*PLUS is waiting for one more input from user.
How can i overcome this issue?
Regards,
SreekanthHi,
I am calling the shell script from concurrent program and below is the log file of the concurrent program.
Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
KORONT_041_SH module: KORONT - Daily Item Master Update
+---------------------------------------------------------------------------+
Current system time is 29-JUN-2011 10:09:35
+---------------------------------------------------------------------------+
REQUEST_ID: 68510795
USER_ID: 4219
PDC: 85
Item Number:
KORDC: 124
PDCSET: 1100000003
last_updated_in_hours: 24
EMAIL_ID: [email protected],[email protected]
SQLPATH: /e381/oracle/asodev01appl/custom/motont/1.0.0/sql/
RPTDIR: /e381/oracle/asodev01comn/admin/out/ASODEV01_asoprdb2
RPTFILE: o68510795.out
Table truncated.
*Enter value for 6: User requested Interrupt or EOF detected.*
Table truncated.
old 15: AND ic.organization_id = &&4
new 15: AND ic.organization_id = 1100000003
0 rows created.
Input truncated to 9 characters
old 8: AND organization_id = &&4
new 8: AND organization_id = 1100000003
0 rows created.
End of SQL
No record.
+---------------------------------------------------------------------------+
Executing request completion options...
+------------- 1) PRINT -------------+
Printing output file.
Request ID : 68510795
Number of copies : 0
Printer : noprint
+--------------------------------------+
Finished executing request completion options.
+---------------------------------------------------------------------------+
Concurrent request completed successfully
Current system time is 29-JUN-2011 10:09:38
+---------------------------------------------------------------------------+Regards,
Sreekanth -
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 thisnewbie 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 -
How to Compile the PL/SQL Package/ Procedure using shell script
Hi,
I tried to Compiled the shell script but I am facing some error.
Can any one help me how to compile the PL/SQL shell script without error. Awaiting for your valuable reply.
Thanks,
Arun Prakashuser8726849 wrote:
PL/SQL shell script without errorWhat's a PL/SQL shell script?
Can you please post exactly what you are trying to do (As in the actual code that you are executing and its output)? Also please post it in \ tags (See FAQ). -
Passing parameters into a shell script through alias Names ????
I have two alias names ord and dev. And the content of them are as follows.
alias ord
ord='cd ${ORDER}/bin; export APPL_NAME=order; . SetupAppl order'
alias dev
dev='cd ${APPL_ROOT}/bin; export APPL_ENV=dev; . SetupEnv dev'
Alias ord calls a shell script called SetupAppl. Alias dev calls a shell script called SetupEnv.
I am trying to pass a parameter when calling the alias name dev, something like dev WEST. And I
want to read that parameter inside the shell script SetupEnv.
The way I want to execute them, first run the alias ord and then the alias dev. But, when I try
to read the parameter in SetupEnv by $1 it is showing the value of the parameter passed to SetupAppl
ie order and not WEST.
Is there any way to read the value (WEST) passed as a parameter when executing the alias name.
example : dev WEST and reading the value WEST inside SetupEnv
The reason I am executing those scripts (SetupAppl and SetupEnv) with dot(.) in the front is because
those scripts have some export statements which needs to exported to the environment.
Any help on this is highly apprecaitedHi everybody,
I posted same question earlier for UNIX/shell script and rec'd one response. Thanks to Bob.
But the requirement has been changed and now my mgr wants the same task using PL/SQL. Could somebody help me ?
Question again....
I am working on a task which gets report on every remote database.
I created a small database: ‘REPORTS_DB’ and I created 6 'sql' scripts on that database. While executing the first script, it calls the other 5 different 'sql' scripts. All these 5 sql scripts use a '@db_link' (hard coded) and gets that database's report to the database: REPORT_DB.
It is working well. But,
We have 42 databases and I have to get reports of all the 42 databases. Since it is not efficient to create 42 sets of sql scripts, I want to make it automated.
I know (but I don't know HOW) I can pass a parameter (database link name) while running the first script (which calls the other 5 scripts), so that the parameter replaces the @db_link in all the 5 scripts and gets the report of the related (@db_link) database.
Could somebody tell me how to do this task using SQL and PL/SQL ?
OR
send me a sample PL/SQL script to do this task?
Sorry for the inconvenience and thanks in advance.
- JT -
Calling pl/sql stored procedure from shell script ( kshell)
hello.,
i have written a stored procedure. i need to call this stored procedure from a unix shell script ( korn shell).
can anyone please help me how can i do it.actually there are 3 stored procedures. so my shell script has to call each stored procedure, execute it then go to next stored procedure execute it.
if by chance inbetween any stored procedure do not execute then the shell script has to tell me that this stored procedure failed to execute.
please help me in this.
thanks
madanSorry Madan,
Following is the complete solutiion:
!# /usr/bin/ksh
sqlplus -s user/pass@server << EOF > a.log
exec proc1;
exec proc2;
exec proc3;EOF
if [ $? -eq 0 ]
then
echo "\n Procedures completed successfully at `date`"
else
echo "!!! FAILED!!!"
echo "Details can be found in a.log File"
fi -
Generate RMAN backup Script using unix shell script
Hello,
Could somebody give me a unix shell script that would generate RMAN script based on some user defined parameters in a config file.
e.g.
rman.conf
CHANNELS=4
USE_CATALOG=Y
DEVICE='sbt_tabe'
etc.,
many thanks,
kamYou can actually encapsulate the RMAN commands inside the shell script.
However if you really want to create a seperate RMAN script file, you can use the unix shell's "echo" command to write set variables to a file.
Thus, for example,
echo "rman target / catalog rman/rmanpassword@crcat" > RMAN_Script.rmn
echo "backup database plus archivelog" >> RMAN_Script.rmn
echo "backup archivelog all" >> RMAN_Script.rmn
creates RMAN_Script.rmn with 3 commands.
Maybe you are looking for
-
Camera Raw 5.2.0.65 opens in German in Photoshop CS4
Hi, Mac OS X 10.5.6 MBP. I installed the Camera Raw 5.2.0.65 plug-in a while back but since I do most of my image processing in LR 2.2 I hadn't used Camera Raw in PSCS4 or Bridge until tonight when I opened a JPEG from PSCS4 and it opened in Camera R
-
GWHA - argh! Can't get it to work!
I swear, if gwha had a neck I'd choke it. I'm so frustrated that I can't get this service to function. I'm pretty sure everything's configured correctly, but if I stop an agent it never gets restarted by gwha. Server: OES2, fully patched. GroupWise 7
-
Order of execution of VPD policies
Hi, I have a table on which I have defined two policies (one for column masking and one for row filtering). From whatever testing I have done, it seems the policy functions get executed in the order in which the policies were created. Does oracle gua
-
DRCP Data resident connection pooling
Hi, I have a quesiton form SR Please confirm do you use DRCP "database resident connection pooling" ? How do I determine if DRCP is enabled in my environment Could someone help. This is urgent Thanks, Prasad
-
1 hour clip in time-line goes gradually out of sync
Hello, I captured a one hour mini-DV tape to a G4 Powerbook as one clip in FCP 4.5. As it plays in the timeline, it gradually goes out of sync and eventually goes way out of sync. Why would this happen? The tape itself plays fine in the camera and as