问题
I am learning SQL using ORACLE 11g. How to print a string(comes from a SELECT query), character by character in ORACLE SQL, without using dual and also without using PLSQL? Here is the sample string:
'MANOJ'
and the output should be like this:
M
A
N
O
J
I tried using LEVEL,CONNECT BY but they are not working in isqlplus. Please help!
回答1:
It is a simple use of SUBSTR and CONNECT BY LEVEL. Have a look at How to split string into rows.
For example,
SQL> SELECT SUBSTR('MANOJ', level, 1) str
2 FROM dual
3 CONNECT BY LEVEL <= LENGTH('MANOJ')
4 /
S
-
M
A
N
O
J
SQL>
Not sure what you mean by "not using DUAL table", but the dual table above is just used to create the sample data for demonstration. In your case, you could use the column name instead of hard-coding the value, and you could use a sub-query in place of the dual table if your value is a result of a sub-query.
来源:https://stackoverflow.com/questions/32120267/printing-characters-one-by-one-from-a-stringvarchar2-oracle-sql-without-using