Home » SQL & PL/SQL » SQL & PL/SQL » Loop Through String Variable (PL/SQL 8iDB)
Loop Through String Variable [message #338386] Mon, 04 August 2008 16:58 Go to next message
adminme
Messages: 31
Registered: May 2006
Member
I need to loop through a varchar2(25) value within a cursor.
Any straightforward suggestions needed.

thanks
Re: Loop Through String Variable [message #338387 is a reply to message #338386] Mon, 04 August 2008 17:02 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please read & follow posting guidelines as stated in URL above


FOR ......... LOOP
.
.
.
.
.
END LOOP;
Re: Loop Through String Variable [message #338389 is a reply to message #338386] Mon, 04 August 2008 17:10 Go to previous messageGo to next message
adminme
Messages: 31
Registered: May 2006
Member
Sorry but I don't get your point on the posting guidelines.
I don't have working code- I'm looking for a concept.
I know what loop syntax is. What should I provide?
Re: Loop Through String Variable [message #338401 is a reply to message #338386] Mon, 04 August 2008 18:15 Go to previous messageGo to next message
adminme
Messages: 31
Registered: May 2006
Member
Let me elaborate...

Oracle Enterprise 8i on HP-UX 11.11

I want to evaluate each character of a column value. Depending on the value of the character it will be set to something else.
Any one of the 25 characters can be null. I want to do this for each row the cursor fetches.

I don't believe defining 25 variables for each position in the string is the most effective way to do this. I'm not familiar with arrays. Is an array required?

Any help to get me going in the right direction is really appreciated. Thanks
Re: Loop Through String Variable [message #338402 is a reply to message #338386] Mon, 04 August 2008 18:30 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Any one of the 25 characters can be null
What does this mean?
How do you programatically "identify" or recognize a null character?
Re: Loop Through String Variable [message #338403 is a reply to message #338402] Mon, 04 August 2008 18:36 Go to previous messageGo to next message
adminme
Messages: 31
Registered: May 2006
Member
Well if i capture 1 of ther chatrs in a variable it would be null- right? Some rows contain 25 chars and some don't. The position and value of the character determines what i'm setting the new value to.
Re: Loop Through String Variable [message #338405 is a reply to message #338386] Mon, 04 August 2008 18:51 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Some rows contain 25 chars and some don't.
OK. say a row exists with only 24 characters.
How do you determine which position is supposed to contain the "missing" character?
If a row contains only 1 character, how do you know in which position it resides?

[Updated on: Mon, 04 August 2008 18:53] by Moderator

Report message to a moderator

Re: Loop Through String Variable [message #338407 is a reply to message #338405] Mon, 04 August 2008 19:45 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Sounds like you might like to look at translate(). You need to be careful to cater for all possible characters though.

SQL> select translate('ABC',
  2  'ABCDEFGHIJKLMN',
  3  'xyz1234567890#')
  4   from dual;

TRA
---
xyz

SQL>


Also see
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2612348048


Re: Loop Through String Variable [message #338409 is a reply to message #338386] Mon, 04 August 2008 21:12 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
in which position is the NULL character?

SQL> select 'A'||NULL||'CD' from dual;

'A'
---
ACD

SQL> select 'AC'||NULL||'D' FROM DUAL;

'AC
---
ACD

SQL> select 'ACD'||NULL FROM DUAL;

'AC
---
ACD

SQL> SELECT NULL||'ACD' FROM DUAL;

NUL
---
ACD


Have you asked the teacher to clarify this homework assignment?
Previous Topic: LEFT JOIN
Next Topic: help code required
Goto Forum:
  


Current Time: Thu Feb 13 12:52:03 CST 2025