LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2013, 06:51 AM   #1
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
Pass value from unix to sqlplus


Hello Team,

I am trying to delete records from DB day wise. Below is the code i am trying but it is not deleting any record. Please suggest.

Code:
#!/usr/bin/ksh

LogDirectory=/path/
DataDirectory=/path/

for date in `cat list.txt`
do
echo "delete record for $date"

sqlplus -s user/passwd@DB <<EOF > ${LogDirectory}/output.log

set linesize 32767
set feedback off
set heading off

spool ${DataDirectory}/query_output.txt
delete from table where TO_CHAR(date_column, 'MM/DD/YY') = '$date';

commit;
spool off
EOF
done
Thanks
 
Old 03-06-2013, 07:26 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try this page https://forums.oracle.com/forums/thr...hreadID=588156
 
Old 03-06-2013, 11:23 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,861
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
try to debug, eg:
Code:
select '$date' from dual;
select count(*) from table where TO_CHAR(date_column, 'MM/DD/YY') = '$date';
 
1 members found this post helpful.
Old 03-08-2013, 01:48 AM   #4
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks for suggestion, where as i was trying to extend this but unable to find correct way.

All other code part being same, i am trying to modigy the delete condition.

Code:
spool ${DataDirectory}/query_output.txt
delete from table where TO_CHAR(date_column, 'MM/DD/YY') >= '$date' and TO_CHAR(date_column, 'MM/DD/YY') <= <Month end date>;

commit;
spool off
I want to loop it in such a way that date variable will take start date from list.txt file and then it needs to delete till month end date. Please suggest how to do this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass MySQL user/pass securely in shell script? digity Linux - Newbie 5 01-07-2010 05:48 AM
Need help writing Unix Shell script to pass file name,path,creation date ! windjashi Programming 4 10-08-2009 12:59 AM
pass arguments and return values from a function in UNIX gaynut Programming 4 07-10-2008 01:56 AM
Planning to change root pass and oracle system pass sathyguy Red Hat 1 12-20-2005 09:53 PM
SQLplus command editor under UNIX - how?? stephstellar Programming 5 05-27-2003 08:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration