Executing oracle commands in shell using shell variable
EOD_TYPE=`sqlplus -s scott/tiger@oracledb <<EOF
set head off
set feedback off
set pages 0
spool file1.dat
select to_char(sysdate,'monddyyyy') from dual;
spool off;
EOF`
a=$(head -1 file1.dat | cut -c1-9)
echo $a
EOD_TYPE1=`sqlplus -s scott/tiger@oracledb <<EOF1
spool file2
select * from $a ;
EOF1`
file2 contains "select * from mar132008 ;" instead of the data in the mar132008 table.
where is the problem.
I think the -s option might not work in your case.
Try to run this script with
sqlplus -s scott/tiger@oracledb @file1.dat
Also add SPOOL OFF and exit to the end of the second script.
btw: other useful set commands are
SET TRIM ON
SET TRIMSPOOL ON
Similar Messages
-
Oracle 10g - can I use a variable to identifywhat user's tablesto access?
I have the following code in a trigger (PL/Sql block) of a form:
select fieldname into myvar from user1.sometable;
is there a way to use a variable instead of hard coding 'user1'? And on the same topic, could this variable be declared globally?
Thanks in advance,
DarrenHi again!
i've forgot something!
You are able to switch to another schema. If you are another user than user1, try:
alter session set current_schema = user1;after this there is no need to use synonyms or tableowners in front of the tablename in your sql-statements.
May you use this in a when-new-form-instance trigger in your first form like:
forms_ddl ( 'alter session set current_schema = ' || :parameter.your_schema );Regards -
Script getting hang while trying to execute update command in python using cx_oracle
Hi All,
My script is getting hang while executing below script and it is not throwing any error.
TEMP_PROD_cur=TEMP_PROD_schema_conn.cursor()
sql="update APP_DB_CONNECT set DRIVER=:driver,URL=:url where APPNAME=:appname and CONNECT_NAME=:connect_name"
TEMP_PROD_cur.execute(sql,{'driver':driver_name,'url':jdbc_url,'appname':app_name,'connect_name':connect_name})
TEMP_PROD_schema_conn.commit()
I tried several ways to prepare update statement to execute but the script is getting hang in all the ways.
Please help to resolve this issue.There's not enough info provided to be able to tell what's going on. You can find online ways to troubleshoot Oracle lock issues - if this is what you are experiencing.
-
Oracle 11gr2 Software Installation on Linux Using Shell Script
Hi,
I have requirement to install Oracle Software on Linux Using shell script, with out any manual entries.
Thanks,
loganathanSrini_Chavali wrote:
Pl identify exact version of database and OS.
Ed - not sure where you looked :-) but response files can certainly be used for an automated installation (which is what I think OP is referring to)
http://docs.oracle.com/cd/E11882_01/install.112/e24321/app_nonint.htm#BABFEECI
HTH
Srini
You are right. I must be losing it. My failure rate lately has been abnormally high. I don't remember exactly how I searched before .. I thought I opened the Installation Guide an searched for 'silent' in "this document only" -- but all I came up with was references to dbca and emca ... nothing for OUI itself. Now that I go back and do the same search, there it is. -
How to execute dos command in Java program?
In Perl, it has System(command) to call dos command.
Does java have this thing?
or any other way to execute dos command in java program?
Because i must call javacto compile a file when the user inputed a java file name.Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
exec(String command) that will execute that command in a dos shell.
Regards,
Gerrit. -
Calling Oracle function and Procedure using OCCI with in C++ code
Could any body send me the sample code to create and execute Oracle function and Procedure using OCCI concept in C++?.
Edited by: 788634 on Aug 16, 2010 4:09 AMHi Vishnu,
Yes, sure, you can create a PL/SQL procedure, function, package, package body, etc. from within an OCCI application. I would say that, generally, this is not the sort of activity a typical client application would perform unless there is some initialization/installation processes that need to happen. In any case, here is a simple demo showing how to create a stand alone procedure (in a real application I would use a package and body) that returns a ref cursor. The ref cursor is just a simple select of two columns in the hr.countries sample table. Of course, there is no error handling, object orientation, etc. in this demo - I wanted to keep the code as short and as simple as possible to illustrate the concept.
Regards,
Mark
#include <occi.h>
#include <iostream>
using namespace std;
using namespace oracle::occi;
int main(void)
// occi variables
Environment *env;
Connection *con;
Statement *stmt;
ResultSet *rs;
// database connection information
string user = "hr";
string passwd = "hr";
string db = "orademo";
// sql to create the procedure which returns a ref cursor as out parameter
// should be run as hr sample user or in a schema that has select privilege
// on the hr.countries table and a synonym (countries) that points to the
// hr.countries table
string sqlCreate =
"create or replace procedure get_countries(p_rc out sys_refcursor) as "
"begin"
" open p_rc for"
" select country_id, country_name from countries order by country_name; "
"end;";
// pl/sql anonymous block to call the procedure
string sqlCall = "begin get_countries(:1); end;";
// create a default environment for this demo
env = Environment::createEnvironment(Environment::DEFAULT);
cout << endl;
// open the connection to the database
con = env->createConnection(user, passwd, db);
// display database version
cout << con->getServerVersion() << endl << endl;
// create statement object for creating procedure
stmt = con->createStatement(sqlCreate);
// create the procedure
stmt->executeUpdate();
// terminate the statement object
con->terminateStatement(stmt);
// now create new statement object to call procedure
stmt = con->createStatement(sqlCall);
// need to register the ref cursor output parameter
stmt->registerOutParam(1, OCCICURSOR);
// call the procedure through the anonymous block
stmt->executeUpdate();
// get the ref cursor as an occi resultset
rs = stmt->getCursor(1);
// loop through the result set
// and write the values to the console
while (rs->next())
cout << rs->getString(1) << ": " << rs->getString(2) << endl;
// close the result set after looping
stmt->closeResultSet(rs);
// terminate the statement object
con->terminateStatement(stmt);
// terminate the connection to the database
env->terminateConnection(con);
// terminate the environment
Environment::terminateEnvironment(env);
// use this as a prompt to keep the console window from
// closing when run interactively from the IDE
cout << endl << "ENTER to continue...";
cin.get();
return 0;
} -
Execute dos commands through java
Hi,
Im trying to execute dos commands through java like
try {
java.lang.Runtime.getRuntime().exec("cmd /c cls");
}catch(IOException e){
System.out.println(e.getMessage());
}Not sure if its possible? however
open notepad would work
try {
java.lang.Runtime.getRuntime().exec("notepad");
}catch(IOException e){
System.out.println(e.getMessage());
}Im trying to execute a cls commands to clear screen but without luck.The question is, which shell do you want to clear?
I don't really know, but it could be that Runtime.exec executes its command in a new shell window... -
Advice executing oracle package using shell script.
Hi,
I am writing one shell script that accepts several parameters as an input. These parameters are then passed while executing Oracle package procedure. However this procedure has an OUT parameter and I am not aware of how to receive that parameter in shell script.
Any advice /suggestion is really appreciated.
Below is the part of code I am using ... (P_OUT is suppose to be an out parameter for package)
sqlplus -s apps/apps <<endsql
whenever sqlerror exit failure
set serveroutput on size 10000
execute TEST_PKG.GET_COC_REQ ('$P_FROM_DATE','$P_TO_DATE','$P_MONTH_YY', '$P_OUT');
endsqlThere is more than one way. Here an example :
SQL> select ename,sal from emp where empno=7902;
ENAME SAL
FORD 3000
SQL> create or replace procedure extsal (
2 empnum in number,
3 salout out number)
4 is
5 begin
6 select sal into salout
7 from emp
8 where empno = empnum;
9* end;
SQL> /
Procedure created.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ EMP=7902
$ SAL=`sqlplus -s scott/tiger << EOF
set head off
var salout number;
exec extsal ($EMP, :salout);
print salout
exit
EOF
`$ echo $SAL | awk -F. '{print $2}'
3000
$ -
Hi, i want to use tr command in awk. Please guide me. Also, how to use shell variables in awk?
please help
-
How to invoke BASH shell and execute a command in that shell in Windows 98
Hello, I have a problem and if somebody will help me, I will be very glad. Thank you.
I am using BASH shell on Windows 98 OS by means of CYGWIN. And I want to invoke this BASH shell and execute a preprogrammed command in the shell (./scan fileName.txt) from a JAVA program. But so far, I am not sucessful. I can not read or write anything from / to BASH shell. It either blocks and freezes (When I use waitFor( ) ) or appears and disappears without executing scan command (When I do not use waitFor( ) ). My code is like this:
// This method is used for compiling a file.
// It invokes BASH shell and executes "./scan fileName.txt" command
public void compileFileMethod () {
try {
Process proc = ( Runtime.getRuntime() ).exec ("C:\\MyDocuments\\CYGWIN.BAT); //I also tried to add -c ./scan fileName.txt after .BAT );
// I also tried to write "C:\\MyDocuments\\BASH.EXE" but it did not help
OutputStream ostr = proc.getOutputStream();
BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter (ostr) );
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader ( new InputStreamReader (istr) );
InputStream errorStr = proc.getErrorStream();
BufferedReader errorBr = new BufferedReader ( new InputStreamReader (errorStr) );
bw.write("scan case40.10.txt"); /* I am trying to input the scan command to the shell,but it is not working*/
bw.flush();
Vector list = new Vector (1) ;
String str;
while ( (str = br.readLine() ) != null) {
list.addElement(str);
} // End of while
Enumeration enumForList = list.elements();
while ( enumForList.hasMoreElements() ) {
String tempString;
tempString = ( String ) enumForList.nextElement();
System.out.println(tempString); // I am trying to read the outputs of the scan command but it is not reading (I can not see any output)
I tried with and without waitFor( ), it did not work
// wait for command to terminate
proc.waitFor();
// close streams
br.close();
bw.close();
errorBr.close();
} // End of try
catch ( IOException ioe ) {
JOptionPane.showMessageDialog (null, "Input / output error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
} // End of catch
catch ( SecurityException se ) {
JOptionPane.showMessageDialog (null, "Security error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
catch ( InterruptedException ie ) {
JOptionPane.showMessageDialog (null, "Interruption error occured while compiling file ", "Error", JOptionPane.ERROR_MESSAGE);
} // End of method compileFileMethod
// Thank you for your helps and time.You cannot invoke BAT files directly, you have to invoke the program that run those files which is your Windows 98 shell. For example (under windows 2000), i would invoke "cmd.exe sricpt.bat some args", rather than "script.bar some args".
Hope this will help you out. -
Printing PDF file Using Shell Command Line
Hello I am writing a program from MicroSoft Excel's Macro that will print PDF files. I have managed to get the program to work but I cannot prevent the file not being opened. Basically the PDF file would get printed but the file would automatically opened up.
I am using shell command line to write this. And this is my code:
FileName = "C:\EGB Gaming Lab\Training Manual\Testing Documents\Testing Checklists\Bill Validator*"
myShell.Run ("Acrobat.exe /t" & FileName)
I have tried using /h but it still opens the file.
I am referring to this support case:
http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
Thank youYou may be able to adopt this script:
on open dropped_items
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
-- set see to alias "Macintosh-HD:Users:mac:Desktop:app.html"
-- set dropped_items to {see}
set the_app to "Safari"
repeat with dropped_item_ref in dropped_items
--set UrlBase to "xzzx FILE://" & POSIX path of dropped_item_ref
--display dialog UrlBase
-- Activate
activate application the_app
-- Open the URL
tell application the_app
open dropped_item_ref
-- print dropped_item_ref
tell application "System Events"
tell process the_app
delay 3
-- click menu item "Print..." of menu "File" of menu bar 1
keystroke "p" using command down
delay 1
keystroke return
delay 10
keystroke "w" using command down
end tell
end tell
--quit
end tell
end repeat
end open -
How to generate "CertificateSigningRequest" by using shell command
Hi,
I want to create "CertificateSigningRequest" file by using shell command
We can create this csr file by using keychain.
Keychain Access/Certificate Assistant/Request a certification from a Certificate Authroity
I really need your help.
Thanks
MengHi,
Thanks for your message.
Yes, it is self-signed Certificate Authrity.
If it is very easy and free, please let me know.
Thanks
Meng -
How to use shell program parameters in java program??
Hai all,
I am writing a java program which must read strings from a file and must assign to variables.these strings are nothing but the output of ls -l command in shell. i need to have all those 9 fields in a file as variables.
I cant find any method that will read only string.I came accross read line but that is not what i need.So, i thought of writing a shell script and by using awk, storing those 9 fields in 9 variables.. but how to use that variables in java programming???
the shell script is executed by exec() but i need that variables also.
Help me please:(
thanks in advancei now changed the code... and closed the output file and then i read.Later i splited with the line i read.. but the same happened...
this is the code:
while ((l = inputStream.readLine()) != null)
op=new FileOutputStream("op.txt");//output of exec goes to this file
String[] cmd= {"/bin/sh","-c","ls -l "+l};
rt = Runtime.getRuntime();
proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERR");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "",op);
errorGobbler.start();
outputGobbler.start();
op.close();//the file is closed now
ip = new BufferedReader(new FileReader("op.txt")); //now i opened to read
p=ip.readLine();
a=p.split("\\s");
ip.close();
}where i went wrong? -
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.. -
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.
Maybe you are looking for
-
Selecting text in Numbers 3.0
When typing text in a cell in Numbers 2.0 after typing the first letter a window would open showing other entries in the same column that started with the same letter and I could copy and paste a selection into the new cell. This function has disappe
-
Can't copy large files to AirPort Disk Using Windows 7
Hi Everyone, I'm positng because I'm unable to copy large files to an AirPort Disk using Windows 7. I have the following setup. AirPort Extreme: - Firmware version: 7.6.1 - Airport disks secured by password - No guest access allowed - Airport Disk P
-
The bug was just reported yesterday so they might not have it available to the public for a while. I am guessing this bug has been around since 3.M.? and its very easy to verify it if its happening in your environment. Also I have been talking to oth
-
Marketing survey responses not received
Dear Experts, CRM 6.0 We have created a survey in CRM_SURVEY_SUITE and have included the URL for the survey in a mail form. Subsequently we created an email campaign which sends out the survey to the customers. Once the customers receive the survey,
-
Ever since I downloaded the gingerbread 2.1 update I can't see any pictures in my emails. I've been to 2 Verizon stores and since Verizon no longer contracts for technicians at their stores the salespeople, although nice, are pretty much useless when