1.多行转一行
(多行转一列)
(多列转一列)
(某列值合并成一行)
使用 'LISTAGG' 函数
https://blog.csdn.net/weixin_45422361/article/details/118768731
2.行转列\列转行
1.decode
2.case when
3.pivot函数
4.unpivot函数
https://blog.csdn.net/weixin_45422361/article/details/118768731
3.一列转多行
regexp_substr函数
REGEXP_SUBSTR函数格式如下:
function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)
__srcstr :需要进行正则处理的字符串
__pattern :进行匹配的正则表达式
__position :起始位置,从第几个字符开始正则表达式匹配(默认为1)
__occurrence :标识第几个匹配组,默认为1
__modifier :模式(’i’不区分大小写进行检索;’c’区分大小写进行检索。默认为’c’。)
4.多列转一列
1. 使用 || 拼接
若合并的数据只是简单的将字符串拼接的话,就要看即将合并的两列是不是varchar2格式 ,如不是,sql必须条用cast函数
例子: select IP||':'||cast(port as varchar2(10)) as ipport from IPPORT;