Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Question involving using expressions and aliases in FROM clause

783956Jul 14 2010 — edited Jul 15 2010
Hello,

I have the following query
 select substr(e.ename, iter.pos, 1) as C
   from (select 'KING' as ename from dual) e,
        (select rownum as pos from dictionary where rownum <= 100) iter
  where iter.pos <= length(e.ename);
which outputs (as desired):
C
-
K
I
N
G
Hardcoding "KING" was done for testing purposes, IRL it would be a column from some table. The other piece that is hardcoded is "where rownum <= 100" and that is the one I'd like to find a way to remove.

I tried the following:
 select substr(e.ename, iter.pos, 1) as C
   from (select 'KING' as ename from dual) e,
        (select rownum as pos from dictionary where rownum <= length(e.ename)) iter
  where iter.pos <= length(e.ename);
unfortunately that doesn't work because the SQL parser has not parsed enough of the FROM clause to be aware of e.ename causing the expression length(e.ename) to return an unknown identifier message.

I've been trying to restructure the above query to make the SQL parser aware of e.ename early enough and thus accept it. My efforts have failed.

I'd like to know if there is a way to restructure the statement so length(e.ename) can be used instead of hardcoding an artificial upper limit (such as 100 as in the first statement).

Thank you,

John.
This post has been answered by Hoek on Jul 14 2010
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 11 2010
Added on Jul 14 2010
15 comments
2,005 views