Oracle Loop question


 
Thread Tools Search this Thread
Top Forums Programming Oracle Loop question
# 1  
Old 12-11-2012
Oracle Loop question

HI ,
Please guide to
get the PL/SQL logic to retrieve parameter VALUES passed IN variable seperated with comma(,)
Code:
 
Say items =(MTH,WKL,DLY,QTR)

It should send above parameters seperatly USINGLOOP condition IN the below IN clause

Code:
 
SELECT * FROM tb_data_storage
WHERE items IN ('MTH');


Please guide
.
# 2  
Old 12-11-2012
Why do you want to use it separately in loop? Use regexp_replace like I mentioned earlier in this thread
# 3  
Old 12-11-2012
Hi Bipi,

Yes i used that logic which you posted earlier .Its working fine .

But for this request , i want it with loop as different conditions are set in where clause which need to run seperatly(included only few) .

it should loop like

Code:
 
SELECT * FROM tb_data_storage
WHERE items IN ('MTH')
and value in ('ABC','GHN');

Code:
 
SELECT * FROM tb_data_storage
WHERE items IN ('WKL');
and value in ('XXX','YYY');
etc

Finally i want all the outputs placed in OR condition .
Code:
 
ITEMS IN  ('MTH') AND  value in ('ABC','GHN')
OR
ITEMS IN ('WKL') AND  value in  ('XXX','YYY')
OR 
etc

Please guide
...
# 4  
Old 12-11-2012
Lets say If you have values in a variable: items, then you can code something like below:-
Code:
items='MTH,WKL,DLY,QTR'

echo $items | tr ',' '\n' | while read item
do
   sqlplus -s ${user}/${pass}@${inst} << EOF
   --use the variable item in SQL here--
   EOF
done

BTW If you have round brackets in your variable value, use sed to remove it:-
Code:
items='(MTH,WKL,DLY,QTR)'
echo $items | sed 's/(//g; s/)//g'

# 5  
Old 12-12-2012
HI Bipi ,

yes this code can be used and called in UNIX/AIX environments .
BUt i want logic to be called in some procedure.How it can be done.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create a for loop statement for removing files listed in Oracle table?

Hello Frens, I am a newbie to shell scripting. I need a help on creating a for loop script (shell script) for removing files. I have a table called a_table with column name fil_name which contains all the files that need to be removed. Thank you in advance (6 Replies)
Discussion started by: manisha_singh
6 Replies

2. UNIX for Advanced & Expert Users

Question related to UNIX and Oracle DB

I have one application server, which is Solaris non global zone (dsapid02-dt3d02 - 10.63.76.96) and a database server, which is Linux (db1-serv26 - 10.63.36.117 & 10.63.36.118). Whenever database admin is starting listener, it starts filling listener log file. Within minutes, it will make file in... (6 Replies)
Discussion started by: solaris_1977
6 Replies

3. Programming

Oracle TRICk Question

HI Guys , Below are the two columns ITEMS and STATE of table . ITEMS STATE '2345','ggdh','k5tg','dgyt','hFF' DF '1234','ghyt','DDD','GHTD','ABF' PQ Can we get output in PL/SQL in below way ?... (7 Replies)
Discussion started by: Perlbaby
7 Replies

4. Hardware

Sun/Oracle M5000 Question

I have an M5K with disk issues I'm trying to troubleshoot, and it's causing me some confusion. I know the host has four on-board HDDs, but the format command's output shows c0t0d0, c0t1d0, c3t0d0, and c3t1d0. cfgadm -al shows c0t3d0 as the DVD-ROM drive, and c1 and c2 as SAN disks. Confused yet? ... (2 Replies)
Discussion started by: desertdenizen
2 Replies

5. Shell Programming and Scripting

PERL and Oracle 11.2 question

Hi, we have PERL 64-bit build with Oracle 10g DBD . PERL database connection are working fine. Database upgraded to 11.2 and in PERL documents it says still use 10g DBD to connect to 11.2. when I try some test connections, I am getting this error . Did anyone see this error before . I set the... (2 Replies)
Discussion started by: talashil
2 Replies

6. UNIX and Linux Applications

Oracle DB Question

Hi, Where do i post Oracle DB related questions?? I basically have 2 questions - 1. What is pmon and smon? Difference between them? If either or both process fail then how can we monitor them? 2. Is lsnrctl same as tnslsnr? if i want to check for listener status then how would i do... (2 Replies)
Discussion started by: Mr. Zer0
2 Replies

7. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

8. Shell Programming and Scripting

Error connecting oracle from inside while loop

Hi, I m trying to connect oracle database from inside while loop. I m trying to put the output of sql query in a flat file. Anyone please help me out. cat $FILE_NAME | \ while read da_name do $ORACLE_HOME/bin/sqlplus -s user_name/password@instance << EOF >> $OUTPUT_FILE select... (3 Replies)
Discussion started by: Devesh5683
3 Replies

9. Shell Programming and Scripting

Ps -ef | grep oracle question

Hi All, I have issued ps -ef | grep oracle command and i got these result oracle 356394 1 0 09:32:06 - 0:03 oracleCMS (LOCAL=NO) Now I can see user from here but I can not from which machine they are running this process. How can I see that? Thanks, Vishal (5 Replies)
Discussion started by: vishalpatel03
5 Replies

10. UNIX for Dummies Questions & Answers

oracle and loop question

Hi All, I have a 2 questions; 1 is oracle and another is korn shell say TIME=20060928 desired output: 20060927 say TIME=20061001 DESIRED output: 20060930 If i substract one day from 'TIME' i am looking for previous day. can anyone please suggest me how do i do this is SQL. i... (4 Replies)
Discussion started by: pavan_test
4 Replies
Login or Register to Ask a Question