【问题标题】:Seprate string to rows将字符串分隔到行
【发布时间】:2021-03-24 16:38:21
【问题描述】:

嘿,伙计们,我正在使用 11g ...我有如下数据

col1
email@id 

我的输出应该是这样的

col1
e
m
a
i
l
@
i
d

【问题讨论】:

  • 用您正在使用的数据库标记您的问题。
  • 您可以使用 numbers/digits/tally 表和substring() 轻松实现

标签: sql oracle11g


【解决方案1】:

以示例表的内容为

SQL> select * from table1;

COL1
--------------------------------------------------------------------------------
email@id
LittleFoot

你会

SQL> select substr(col1, column_value, 1) val
  2  from table1 cross join
  3    table(cast(multiset(select level from dual
  4                        connect by level <= length(col1)
  5                       ) as sys.odcinumberlist))
  6  order by col1, column_value;

VAL
----
e
m
a
i
l
@
i
d
L
i
t
t
l
e
F
o
o
t

18 rows selected.

SQL>

【讨论】:

    【解决方案2】:

    您可以使用 connect by 来达到您想要的结果:

    架构:

             create table table1 (col1 varchar2(100));   
             insert into table1 values('email@id');
         
    

    查询:

             select  substr(col1, level, 1) col1
             from table1
             connect by level <= length(col1) ;
         
    

    输出:

         | COL1 |
         |------|
         | e    |
         | m    |
         | a    |
         | i    |
         | l    |
         | @    |
         | i    |
         | d    |
    
        
    

    dbhere

    【讨论】:

    • 运行insert into table1 values('another_email@id');,然后再次运行您的查询。会发生什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2013-04-18
    • 2017-05-05
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    相关资源
    最近更新 更多