Printing characters one by one from a string(VARCHAR2) oracle sql without using plsql and also without using dual

六月ゝ 毕业季﹏ 提交于 2020-01-04 14:09:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!