Any reason why the update is not working in this sql:
Code:
#!/bin/ksh
#setup your environment
. /opt/lnpsite/nm00/scripts/setup_env nm00
for tn in `cat /home/cpac/Resync/sv_tn.list`
do
`sqlplus -s ${DB_USERID} << EOF
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
alter session set nls_date_format = 'YYYY/MM/DD HH24:MI:SS';
update sv set old_ts=sysdate, status=7 where status=1 where tn='$tn' and rownum < 1;
commit;
EOF`
echo "Set TN=${tn} to OLD"
done
Here is the error I get:
Code:
sv_table_tn_update.ksh[8]: update: not found [No such file or directory]
Set TN=2535314426 to OLD
---------- Post updated at 09:40 AM ---------- Previous update was at 08:52 AM ----------
never mind. found the root cause.
---------- Post updated at 09:41 AM ---------- Previous update was at 09:40 AM ----------
Here is the fix and it works:
Code:
do
`sqlplus -s ${DB_USERID} << EOF
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
alter session set nls_date_format = 'YYYY/MM/DD HH24:MI:SS';
update sv set old_ts=sysdate, status=7 where status=1 and tn='$tn' and rownum < 1;
commit;
EOF`
Moderator's Comments:
Please use CODE tags; not ICODE tags when displaying full line (and especially multi-line) sample input, output, and code segments.
Last edited by Don Cragun; 08-20-2015 at 05:14 PM..
Reason: CODE tags - not ICODE tags, again
I guess the spaces at the beginning of the lines were the problem(?)
In any case, a couple of observations:
- The clause "rownum < 1" is always false. Oracle's pseudo-column rownum has an integer value of 1 or higher. Looks like in your case the shell script does not throw any error, but the update statement doesn't update anything either.
- The backticks from "sqlplus" to the "EOF" are not necessary if do not want to assign the output of the sqlplus command to a shell variable.
- If your file: sv_tn.list has a large number of rows, then connecting to sqlplus and updating the database for each row may be too expensive and inefficient.
If you only want to update all rows with the "tn" values in the sv table, then you may want to go through the sv_tn.list file, collect all "tn" values into a comma-delimited list and then issue a single update like so:
Code:
update sv set old_ts=sysdate, status=7 where status=1 where tn in $tn_list
How can I make that sql run fatser by updating and committing in chunks of 1000 for ex?
Please use this working version:
Code:
for tn in `cat /home/cpac/mnaji/Resync/sv_tn.list.split1`
do
`sqlplus -s ${DB_USERID} << EOF
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
update sv set old_ts=sysdate, status=7 where status=1 and tn='$tn';
commit;
EOF`
count=`expr $count + 1`
echo "Record # $count - Setting TN=${tn} to OLD on SV"
done
Last edited by Corona688; 08-20-2015 at 02:32 PM..
Reason: Please use code tags, not icode
(
count=0
echo "SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF"
while read tn
do
echo "update sv set old_ts=sysdate, status=7 where status=1 and tn='$tn';"
echo "commit;"
count=`expr $count + 1`
# Printing to stderr avoids feeding this text into sqlplus
echo "Record # $count - Setting TN=${tn} to OLD on SV" >&2
done < /home/cpac/mnaji/Resync/sv_tn.list.split1 ) | sqlplus -s ${DB_USERID}
Hi,
I am trying to extend unix variable value with mysql resultset. It's working fine in terminal but not working in shell script.
#!/bin/bash
export prcs_nm=$1
export tbl_nm=$2
export rslt=$(
mysql -sN -u root -proot123 -e "
select sql_query
from retail_db.config where prcs_nm =... (3 Replies)
I am having one heck of a time, and I need anyone that can assist in finding my issue here....
First off, here is the script we are using:
pastebin dot com slash njwUg6vd
All usernames and passwords have been edited out. We are using an actual database user, and not root (tried both).
I... (0 Replies)
Hi all,
I have script, which performing sql queries and put output into file.
When I run this script manually, its working fine, but when I want to schedule it with cron I am getting errors...
I defined LD_LYBRARY_PATH and ,but no result. After I defined it, I am getting error:
# more... (4 Replies)
I want to spool files from unix using a sql script that would
take values from another sql query within the KSH script..
unix loop
select order_date from date_tbl
for each order_Date i need to call this spool script with the value
sqlplus scott/tiger@order_db @/ordspool/order_date.sql... (2 Replies)
Hi,
I'm trying to build a shell script that reads a set of accounts from a file. For each account I need to perform a set of sql queries. So I have a loop with a set of sqlplus connections to retrieved my data.
Is it possible to have a single sqlplus connection before entering the loop and... (4 Replies)
Trying to compile all SQL files using a shell script. But the below code is not working. Below Code works fine when for loop is not there(commenting line no: 1,2 and 9).
1. sq_lfile=`ls *.sql`
2. for current_sql_file in $sql_file
3. do
4. sqlplus uname/pass@Service>>SQLLOG << -ENDOFSQL... (3 Replies)
Hi i want to run a query in loop(unix loop) every 2 hours and spool the result to a file.
i am trying but getting error here is the script
$ while true
do
sqlplus ank/ank<<!
spool ank.lst
select * from v$database;
exit
sleep 7200
done
:D (2 Replies)
Hello,
I am doing a shell script which contain a pl/sql loop to search for 3 values, i would like to call another shell script inside this sql loop each time it find the values. so how can i call shell script from pl/sql using its variables, any idea?
Here is idea about the code:
my... (1 Reply)
Connected to oracle database
sqlplus << EOF
$CONNECTSTR
set heading off
set trimspool on
set feedback off
select ID,DATE from sysadm.TEST where VALUE = 'A' order by ID;
value_id = ID
value_date = DATE
EOF
1. Is it possible to reference the values, ID,DATE in unix shell script.
2.... (20 Replies)
Hi,
I am getting the error "No matching <<", when i run the below. Is it that we can't execute SQL in a Unix loop. I am executing a SQL in a loop. Is it the EOF is written wrongly.
. /opt/app/wlsconfigv61/domains/profiles/oracleV901.profile
export DBUSER=ecdb01
set -A DBINSTANCE... (3 Replies)