当前位置:网站首页>Mixed use of Oracle column row conversion and comma truncated string
Mixed use of Oracle column row conversion and comma truncated string
2022-04-23 21:25:00 【Plant a sweet smell】
oracle The mixed use of column to row conversion and string truncation with commas
lately , When writing a stored procedure to return a value to the front end , The mixed use of row to column and intercepted string is used
Data to be converted

Data you want to achieve

Realization SQL
```sql
select OLD_REEL,OLD_QTY,substr(REEL,0,decode(instr(REEL, ','),0,length(REEL),instr(REEL, ',') - 1)) as newreel1,
substr(qty1,0,decode(instr(qty1, ','),0,length(qty1),instr(qty1, ',') - 1)) as reelqty1,
substr(REEL,decode(instr(REEL, ','),0,length(REEL),instr(REEL, ',') + 1)) as newreel2,
substr(qty1,decode(instr(qty1, ','),0,length(qty1),instr(qty1, ',') + 1)) as reelqty2 from (select OLD_REEL,
OLD_QTY,
listagg(NEW_REEL,',') within GROUP (order by NEW_REEL) over (partition by OLD_REEL) REEL,
listagg(qty,',') within GROUP (order by qty) over (partition by OLD_QTY) qty1
from WMS_REEL_IQC where OLD_REEL='551R17083000056') t where rownum=1;
##### explain :1.
`select OLD_REEL,
OLD_QTY,
listagg(NEW_REEL,',') within GROUP (order by NEW_REEL) over (partition by OLD_REEL) REEL,
listagg(qty,',') within GROUP (order by qty) over (partition by OLD_QTY) qty1
from WMS_REEL_IQC where OLD_REEL='551R17083000056'` this SQL Realize row to column conversion , The function used listagg
2.`select OLD_REEL,OLD_QTY,substr(REEL,0,decode(instr(REEL, ','),0,length(REEL),instr(REEL, ',') - 1)) as newreel1,
substr(qty1,0,decode(instr(qty1, ','),0,length(qty1),instr(qty1, ',') - 1)) as reelqty1,
substr(REEL,decode(instr(REEL, ','),0,length(REEL),instr(REEL, ',') + 1)) as newreel2,
substr(qty1,decode(instr(qty1, ','),0,length(qty1),instr(qty1, ',') + 1)) as reelqty2` this SQL Implementation with comma ‘,’ Intercepting string , If you want to intercept other strings , Replace the comma with the character you want .
版权声明
本文为[Plant a sweet smell]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200619557390.html
边栏推荐
- Another data analysis artifact: Polaris is really powerful
- Centralized record of experimental problems
- Sklearn function: Train_ Test_ Split (split training set and test set)
- Pytorch: runtimeerror: an attempt has been made to start a new process Error reporting (resolved)
- Tensorflow1. X and 2 How does x read those parameters saved in CKPT
- [leetcode refers to offer 52. The first common node of two linked lists (simple)]
- Awk example skills
- Common commands of MySQL in Linux
- Pytorch selects the first k maximum (minimum) values and their indexes in the data
- Deep understanding of modern mobile GPU (continuously updating)
猜你喜欢

What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer

Xiaomi mobile phone has abandoned the "Mi" brand all over the world and switched to the full name brand of "Xiaomi"

Question brushing plan -- backtracking method (I)

C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序

阿里又一个“逆天”容器框架!这本Kubernetes进阶手册简直太全了
![[leetcode refers to the substructure of offer 26. Tree (medium)]](/img/53/b34ed5f46706f80bc1a9fcdb1481ae.png)
[leetcode refers to the substructure of offer 26. Tree (medium)]

Subcontracting of wechat applet based on uni app

管道和xargs

Opencv application -- jigsaw puzzle

Is rust more suitable for less experienced programmers?
随机推荐
Preliminary analysis of Airbase
引入结构化并发,Swift 5.5 发布!
Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
Ubutnu20 installer centernet
Detailed explanation of basic assembly instructions of x86 architecture
Detectron2 usage model
Graph traversal - BFS, DFS
Lunch on the 23rd day at home
Normalized transforms in pytorch The real calculation process of normalize
Resolve the "chromedriver executable needs to be in path" error
Is rust more suitable for less experienced programmers?
South Korea may ban apple and Google from offering commission to developers, the first in the world
Plato Farm元宇宙IEO上线四大,链上交易颇高
[※ leetcode refers to offer 32 - II. Print binary tree II from top to bottom (simple)]
Addition, deletion, modification and query of MySQL advanced table
Question brushing plan - depth first search (II)
Thinking after learning to type
Rust更适合经验较少的程序员?
如何发挥测试策略的指导性作用
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer