Insert file to oracle db by C shell script
Hi,
Could you pls help me how I can write script on C shell of Sun solaris to load data to Oracle database from text file with "," fields separator. Send me the samples script if can. Thanks you very much.
Vu Tuan - Vietnam Mobile Telecom services co.
Thanks Yoann very much, I tested sqlldr already as your help, But problem with me is how to set ulcase2.dat is variable in ulcase2.ctl file?, following is script in SunSolaris, how I can use SQLDLR command in this scrip? :
find $LOADER_DIR -type f ! -size 0 -print | egrep 'RLOS.txt' | \
while read file
'How to input $file to RLOS tables exist in ortacle database by sqlldr format as following "
(sqlldr USERID=scott/tiger CONTROL=ulcase2.ctl LOG=ulcase2.log)
esac
done
could you pls see an help me.
thankis in advands
Similar Messages
-
Unable to pass parameter in oracle procedure through unix shell script
Hi Experts,
I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
Follwoing is the sample procedure which i tried to exceute from the unix.
Procedure:
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
sql_stmt varchar2(1000) := NULL;
v_count number := 0;
v_owner varchar2(100) := owner;
begin
sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
execute immediate sql_stmt into v_count;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
DBMS_OUTPUT.PUT_LINE(v_count);
END;The script which I used is:
Unix
#!/bin/ksh
parm=$1
echo start
sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
set serveroutput on;
select '$parm' from dual;
exec owner.PRC_TESTING_OWNER('$parm');
EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
Following the procedure which i am trying to implement.
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
v_owner varchar2(100) := owner;
CURSOR main_cur IS
select
i.ROWID rid ,
emp_name,
deptid
from v_owner.employee;
CURSOR subset_cur(c_deptid NUMBER ) IS
SELECT *
FROM v_owner.DEPT d
where d.dept_id=c_deptid;
--##main loop
FOR i IN main_cur LOOP
FOR j IN subset_cur(i.deptid) LOOP
BEGIN
insert into v_owner.RESULT_TABLE
END;
END LOOP;
END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
used in cursor? :(
Can anybody help me regarding the same?
Thanks in Advance !! :DIt's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
You would need to use something like ...
declare
l_owner varchar2(30) := 'SCOTT';
l_ref_cursor sys_refcursor;
type l_ename_tab is table of scott.emp.ename%type;
l_ename_array l_ename_tab;
begin
open l_ref_cursor for
'select ename
from ' || l_owner || '.emp';
loop
fetch l_ref_cursor bulk collect into l_ename_array limit 10;
exit when l_ename_array.COUNT = 0;
for x in 1 .. l_ename_array.count
loop
dbms_output.put_line(l_ename_array(x));
end loop;
end loop;
close l_ref_cursor;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01 -
Executin oracle stored procedure from shell script
Hi everyone,
I want to know how to execute a orace stored procedure from a shell script not a sql file.
Its a oracle stored procedure with in parameters.
Can anyone send immediate reply its very urgent.
Thanks in Advance
with regards
ThazulHello everyone,
Whenever i am using the previous script
because of <<! and !>> in the beginging and the end of oracle scrip. Shell is displaying the error 'newline or ;' unxexpeted and the error no is 48.
After that i used a different script like
DIRRUNNER=/oracle/tvg
count=0
while [ 1 -eq 1 ]
do
for x in `ls $DIRRUNNER/RUNNER_*.TXT`
do
count=`grep -c $x $DIRRUNNER/runner.log`
if [ $count -lt 1 ]
then
chstr=`echo $x|awk -F/ '{printf $NF }'`
dir=$DIRRUNNER
file=$chstr
PATH=$PATH:/usr/local/bin:.
export PATH
ORACLE_SID=BBPROD
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
echo "exec runrace('$dir', '$file')" > runner.sql
sqlplus -s tvgus/tvgus@bbprod @runner.sql
echo $x >>$DIRRUNNER/runner.log
fi
done
count=0
sleep 2
done
The above one is working fine but after executing the procedure control is still remaing in the sqlplus environment, but i want the control back to my shell
Can anyone help to resolve this, its pretty urgent.
Thanks in Advance
Thazul.
null -
FTP files from Unix box to Windows ( Shell script )--inplemention in Apps
Hi,
I have an requirement like need to send files generated at a particular path in the UNIX sever into Windows machine.
This should be a scheduler( can we create any shell script
) for this...
Note : files generated at Unix move into Windows box....
Please check and help on this... and let me know if any clarification required on my requirement.
Thanks,
Pavan KThis is relatively easy to do. You will need to write the shell script code and register it as a concurrent program of type "Host". Pl see the Application Developer Guide (for 11i and R12) at http://www.oracle.com/technology/documentation/applications.html for details on how to register a shell script "Host" custom program.
ML Docs 266268.1, 147455.1, 1013907.6 and 156636.1 have some more info too.
HTH
Srini -
Oracle declare function in shell script
Please tell me oracle declare function now able to run in shell script?
I am calling in shell script like @/myscript.sql it is not working properly, reset update and other oracle command is working fine in shell script.I am running below code.
#!/bin/sh
sqlplus system/manager@prod_db <<ENDOFSQL
update apps.fnd_concurrent_queues set node_name = 'host1', target_node ='host1' where node_name='host3';
update apps.fnd_concurrent_queues set node_name = 'host2', target_node ='host2' where node_name='host4';
commit;
DECLARE
VALUE BOOLEAN;
l_node_id number;
BEGIN
select node_id into l_node_id from fnd_nodes where NODE_NAME = 'host5';
VALUE := fnd_profile.save ('NODE_TRUST_LEVEL', 3, 'SERVER',l_node_id,null,null);
END;
ENDOFSQL
Below ERROR i am getting after running above code via shell script with oracle user
SQL>
0 rows updated.
SQL>
0 rows updated.
SQL>
Commit complete.
SQL> SQL> DECLARE
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5 -
Oracle 10g and Korn Shell Scripting
I have a table,SALES_STAGING, with 3 main columns.
Sales_Date, Sales_type,Sales_Code.
A sale is added to the table then waits until approved to be processed. The Sales_Code is 1(waiting approval). Then manually changed to 2 every 30 minutes by sales staff except on weekends. By Monday,a large queue develops. This must be changed because the queue is slowing the system. Can someone help create a Unix Korn shell script to
1) Run every 30 minutes via Crontab
2)login to the Oracle DB.
3)Count the number of records to be processed, if any.
4)Update another 'log' table with the time it ran and the records to be processed
5)if there are less than 20 add another 50 to be processed by changing the Sales_Code from 1 to 2.
This would really help out tremendously! Thank you.Wait... Isn't this forum designed for the sharing of information? The experts here shouldn't be concerned whether the request is from a Student, Oracle newbie or Developer and should focus on the request. If you are capable of assisting then I am hoping you will out of the core respect for professionalism and the motivation to provide something of value to others. If not, don't waste my time or any one else by responding with preconceived judgments and insulting remarks as these will be reported.
Sales transactions can peak at 20,000 per hour with an average of several million thru the week. Those sales by VIP customers are immediately identified and have a priority for approvals because their balances can easily exceed $1,000,000.00. There is a pre-approval process to be introduced but until programs can be modified/tested and deployed we need a quick fix. The programming system isn't slow, it's the limited human resources approving VIP customers. My request was to keep it simple and expand on it myself to include the entire scope of our project. dbms_scheduler, although a good idea will require DBA assistance and there is no resource available. I need a simple working model to give me some direction/ideas... -
Get all .pdf file in a folder and do shell script
Hi, I need to convert many pdf to ps using pdf2ps, and I'm try to do this with applescript:
tell application "Finder"
set pdf_folder to (choose folder)
set pdf_path to POSIX path of (item of folder pdf_folder whose name...)
end tell
repeat with k in pdf_path
set kl to ... -- same of k but with extension .ps
do shell script ("pdf2ps "&k&" "&kl)
end repeat
but I don't know how implement that.
Can anyone help me?
Thanks!01. The 'tell application "Finder" ... end tell' code block is not required to call 'choose folder'. View the 'Standard Additions' dirctionary.
02. 'choose folder' returns a single alias - if only a single folder is to be selected, or a list of 'alias'es - if 'multiple selection allowed' is set to true.
03. 'pdf2ps' is not part of Apples' UNIX commands installation; and you did not provide a valid URL for others to download the UNIX command.
Code to process only a single selected folder.
-- Code starts here --
try
do shell script ("pdf2ps " & (quoted form of (POSIX path of ((choose folder) as string))))
end try
-- Code ends here --
Code to process multiple selected folders.
-- Code starts here --
set pFolder to choose folder with multiple selections allowed
if ((count pFolder) > 1) then
set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
set pFolder to text items of pFolder
repeat with i from 1 to (count pFolder)
set (item i of pFolder) to quoted form of (POSIX path of (item i of pFolder))
end repeat
set AppleScript's text item delimiters to " "
set pFolder to pFolder as string
set AppleScript's text item delimiters to oAStid
else
set pFolder to pFolder as string
end if
try
do shell script ("pdf2ps " & pFolder)
end
-- Code ends here -- -
Extracting file from oracle repository from a shell
Hi all,
I have to extract file from a SCM configuration in a Unix AIX environment using a shell.
I can't use command line tool because I'm in a unix environment (Right?).
Is possible I think using scm api but I don't find any usefull exampleClose your question here and open here
Oracle Discussion Forums » Oracle Database » Application Express -
Query to insert file in Oracle database 9.2.0.1.0
how can I can reafear to a file field of an oracle database 9.2.0.1.0 in a query?
ThanksHi
Use external table definiton.
Ott Karesz
http://www.trendo-kft.hu -
Oracle Error Handling in Shell Scripts
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
Best Regards
Antoniouser5647282 wrote:
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
Piping the output of 'exit' to sqlplus????????? what do you expect from this?
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?any error returned by sqlplus as $? would be a fatal error of sqlplus itself, not any error returned by processing a sql statement. If your script ord.extractor_porven.sql were to generate, say, an ORA-00001, that is NOT an error in sqlplus and so does not return to the OS as an error of sqlplus.
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
there is no "urgent" here.
"Urgent" means one of two things -
1) people are dying, or
2) you have a customer-facing, revenue-producing production system that is down.
(And to get some perspective on the second case, keep the first in mind.)
For the first, you call whatever civil emergency service seems appropriate.
For the second, you open an SR with Oracle - which requires a paid-up support contract. For them to consider your problem "urgent", you will need to demonstrate that your problem falls under item #2. I seriously doubt your problem fits that criteria.
Best Regards
Antonio -
How to write CLOB parameter in a file or XML using shell script?
I executed a oracle stored procedure using shell script. How can i get the OUT parameter of the procedure(CLOB) and write it in a file or XML in UNIX environment using shell script?
Edit/Delete MessageSQL> var c clob
SQL>
SQL> begin
2 select
3 DBMS_XMLGEN.getXML(
4 'select rownum, object_type, object_name from user_objects where rownum <= 5'
5 ) into :c
6 from dual;
7 end;
8 /
PL/SQL procedure successfully completed.
SQL>
SQL> set long 999999
SQL> set heading off
SQL> set pages 0
SQL> set feedback off
SQL> set termout off
SQL> set trimspool on
// following in the script is not echo'ed to screen
set echo off
spool /tmp/x.xml
select :c from dual;
spool off
SQL>
SQL> --// file size
SQL> !ls -l /tmp/x.xml
-rw-rw-r-- 1 billy billy 583 2011-12-22 13:35 /tmp/x.xml
SQL> --// file content
SQL> !cat /tmp/x.xml
<?xml version="1.0"?>
<ROWSET>
<ROW>
<ROWNUM>1</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>BONUS</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>2</ROWNUM>
<OBJECT_TYPE>PROCEDURE</OBJECT_TYPE>
<OBJECT_NAME>CLOSEREFCURSOR</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>3</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>DEPT</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>4</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>EMP</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>5</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>EMPTAB</OBJECT_NAME>
</ROW>
</ROWSET>
SQL> -
Catching oracle exception in shell script
Hi,
I'm trying to catch an oracle exception in a shell script. Below is my shell script -
#!/bin/sh
var=115326311
logfile=shell_log.txt
sqlplus -s mbl/sop01 <<EOF
WHENEVER SQLERROR EXIT SQL.SQLCODE;
@plsql.sql $var;
EOF
return_type=$?
if [ $return_type != 0 ]
then
echo 'Error with code';
echo "$return_type";
exit 0;
fi
and this is the sql script -
set serveroutput on;
DECLARE
--set serveroutput on;
--v_company_id NUMBER := 'company_id';
v_name VARCHAR2(100);
BEGIN
--set serveroutput on;
dbms_output.ENABLE();
SELECT ename INTO v_name FROM emp WHERE emp_ID = &1;
DBMS_OUTPUT.PUT_LINE('Inside SQL File'||' || '|| v_name);
END;
exit
I'm basically passing an employee number that does not exist and hence the sql file would throw and no_data_found exception, which i'm trying to catch in the shell script. When I try to execute the shell script I get the below error --
DECLARE
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 8
Error with code
123
he sql file is aborting and the error there is just thrown to the command line, which I don't want. I want it to be captured in the shell script and perform my own logic. Also, it says the error code is 123 - I'm not sure from where this is being picked up, shouldn't it actually be the ORA-1403 code ?Hello,
1403 is out of range for the return value, see https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1342602684748
We can raise errors in a given range but the shell will only keep an
unsigned byte in the status return value (values 0..255). It takes our exit file and
just looks at that last byte.
It also shows how to get around this limitation.
Regards
Marcus -
Shell scripting for oracle DBs
looking for good source for shell scripting for oracle DBs
Just buy 'Classic Shell Scripting' and 'the Unix Desktop Reference' both published by O'Reilly and you have it all.
But if you want a platform agnostic scripting language use Perl. Comes with Oracle.
However both bash and kornshell are a lot easier compared to Perl.
Sybrand Bakker
Senior Oracle DBA -
Moving files into directory using shell script
Can someone tell me how I move files into directory using *nix/linux shell script?
I have files which created from stored procedures using utl_file. The files name for example:
DKH_104_12345
DKE_101_42324242
DKH_102_32432
DKE_101_34553
Then I create directories automatically for example:
/oradata/apps/dmp/output/101
/oradata/apps/dmp/output/102
/oradata/apps/dmp/output/103
/oradata/apps/dmp/output/104
Using this procedure :
CREATE OR REPLACE PROCEDURE Xorganize AS
v_item VARCHAR2(5);
v_DirName VARCHAR2(50);
v_FileName VARCHAR2(50):='xorganize';
v_FileExt VARCHAR2(5):='.sh';
v_ID UTL_FILE.file_type;
CURSOR res IS
--find the directory name from table
SELECT brn_cde FROM vcr_brn_cde ORDER BY 1;
BEGIN
--used by utl.file funtion
SELECT PRD_DIR INTO v_DirName
FROM CR_SYS_PRM
WHERE CLT_CDE ='FIF';
SELECT v_FileName||v_FileExt INTO v_FileName FROM dual;
v_ID:=UTL_FILE.FOPEN(v_DirName,v_FileName, 'w');
utl_file.PUTF(v_ID,'%s\n','@@echo OFF');
utl_file.PUTF(v_ID,'%s\n','cls');
utl_file.PUTF(v_ID,'%s\n','echo Reorganizing ...');
OPEN res;
LOOP
FETCH res INTO v_item;
EXIT WHEN res%NOTFOUND;
utl_file.PUTF(v_ID,'%s\n','mkdir '||v_item);
END LOOP;
CLOSE res;
OPEN res;
LOOP
FETCH res INTO v_item;
EXIT WHEN res%NOTFOUND;
utl_file.PUTF(v_ID,'%s\n','move _'||v_item||'_.* '||v_item||'\');
END LOOP;
CLOSE res;
utl_file.PUTF(v_ID,'%s\n','FOR /F "usebackq delims=" %%1 IN (`dir /b *.`) DO @rd/q %%1');
utl_file.PUTF(v_ID,'%s\n','cls');
utl_file.PUTF(v_ID,'%s\n','echo Reorganizing ...Done');
utl_file.fclose(v_ID);
END;
Everything works fine, BUT, the script is generated in dos/windows scripting.
Now I need to run the script in *nix/linux shell, which I still can’t do it (because of my knowledge :p).
And also I don’t know if the script already generated in *nix/linux shell version, how do I chmod +x the script from stored procedure, I can’t use ‘host’ command in my tools
Thanks a lot
-firmanIf you're using 9i then UTL_FILE.FRENAME() will execute something like a Unix mv command.
If you want to do a chmod then you'll need to check out how to use a Java Stored Procedure to execute OS calls.
Cheers, APC -
Hello,
I have the following function in PL/SQL:
Create or replace function fqman."test" (name in varchar2, url in varchar 2, page in varchar2, uname in varchar2, password
in varchar 2, key_ in varchar2, pass in varchar2, file1 in varchar2, file2 in varchar2) return number
as language java
name 'Data.file(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,
java.lang.String,java.lang.String,java.lang.String) return int;Data is a java class I have in my /home directory (AIX machine). I would like to run this function NOT through Oracle, but through a shell script. So, I have to write the test function in a .sh file.
I started doing that. I did the following:
fntest()
name =$1
url=$2
page=$3
uname=$4
password=$5
key_=$6
pass=$7
file1=$8
file2=$9
}I do not know how to finish the function. Any help will be appreciatedPerhaps the following will do:
#!/bin/bash
fntest() {
name="'$1'"
url="'$2'"
page="'$3'"
uname="'$4'"
password="'$5'"
key="'$6'"
pass="'$7'"
file1="'$8'"
file2="'$9'"
ORACLE_SID="ORCL"
export ORAENV_ASK=NO
. oraenv -s
sqlplus -s / nolog <<EOF
set pages 0 feed off
connect username/password
BEGIN DBMS_OUTPUT.PUT_LINE(fqman.test($name,$url,$page,$uname, etc..)); END; /
exit;
EOF
Maybe you are looking for
-
R12 Up Grade benifits for Purchasing, iProcurement,Inventory
Dear All, We are planning to upgrade from 11i to R12, can any one help me what are new features in R12 for Purchasing, iProcurement,Inventory and waht are the benifits if we go for upgrade. Please let me know.. Regards, Kevin, P.
-
Report displaying Material Standard Price and PO Price
Hello Experts We have materials which are purchased. Price control is maintained as standard price and standard price is maintained using T Code MR21 periodically. Due to this when PO price is different from standard price maintained in material mast
-
Posting a document using RFBIBL00
Hi, I want to post certain details using this program. I have populated the three structures: BGR00, BBKPF(header data) and BBSEG(line item data). The session gets opened but is terminated while reading the header data strucure. It gives this error:
-
IPod Nano 6th Generation Pedometer
I have a brand new iPod Nano 6th Generation, which has the built in Pedometer into it. For some reason, when I go to use it with Nike+ and syncing it to iTunes it doesn't work. None of the Walks I have done actually go onto the Nike+ website. Nike+ c
-
What do you think X2 or X2-01 is better?(Overall)
I have used both of this phones let me know your Comments....