当前位置:网站首页>Oracle column to row -- a field is converted to multiple rows according to the specified separator

Oracle column to row -- a field is converted to multiple rows according to the specified separator

2022-07-06 07:15:00 Game programming

In the data storage database , There is often information to Special symbols The separated form is stored in a field
When copying code for use , The table name needs to be changed 、 Field name 、 Separator characters, etc ( notes : When you use it, you need to put N Replace with Separator The length of , Such as separator “,”, Length bit 1, Will N Replace bit 1, altogether 4 It's about ).

SELECT id,substr(a.city, instr(a.city, '、', 1, levels.lvl) + N, instr(a.city, '、', 1, levels.lvl + 1) -(instr(a.city, '、', 1, levels.lvl) + 1)-(N-1)) as city,usernameFROM(SELECT id,'、' || city || '、' AS city,username,(length(city || '、') - nvl(length(REPLACE(city, '、')), 0))/N AS cntFROM userinfomation) a,(SELECT rownum AS lvlFROM (SELECT (MAX(length(city || '、') - nvl(length(REPLACE(city, '、')), 0)))/N max_len FROM userinfomation)CONNECT BY LEVEL <= max_len) levelsWHERE levels.lvl <= a.cntORDER BY id,levels.lvl;
ORACLE Column turned -- A field is converted to multiple lines by the specified separator - The first 1 Zhang

author :LW_dcwange

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .

原网站

版权声明
本文为[Game programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060711249772.html