当前位置:网站首页>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
边栏推荐
- Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
- thinkphp5+数据大屏展示效果
- [leetcode refers to the substructure of offer 26. Tree (medium)]
- [※ leetcode refers to offer 46. Translate numbers into strings (medium)]
- 2. Finishing huazi Mianjing -- 2
- Rust更适合经验较少的程序员?
- [leetcode refers to offer 21. Adjust the array order so that odd numbers precede even numbers (simple)]
- Question brushing plan - depth first search (II)
- Lunch on the 23rd day at home
- DW basic tutorial (I)
猜你喜欢
flomo软件推荐
Deep analysis of C language function
Chrome 94 引入具有争议的 Idle Detection API,苹果和Mozilla反对
Problem brushing plan -- dynamic programming (III)
Deep analysis of C language pointer (Part I)
Addition, deletion, modification and query of advanced MySQL data (DML)
Addition, deletion, modification and query of MySQL advanced table
Deno 1.13.2 发布
Based on jsplumb JS to achieve multi list one to many connection effect
[leetcode refers to offer 32 - III. print binary tree III from top to bottom (medium)]
随机推荐
go reflect
[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
[SDU chart team - core] enumeration of SVG attribute class design
Graph traversal - BFS, DFS
Win 11K in 100 days, super complete learning guide for job transfer test
[leetcode refers to the substructure of offer 26. Tree (medium)]
Is rust more suitable for less experienced programmers?
Pytorch: runtimeerror: an attempt has been made to start a new process Error reporting (resolved)
[※ leetcode refers to offer 32 - II. Print binary tree II from top to bottom (simple)]
3-5 obtaining cookies through XSS and the use of XSS background management system
[leetcode sword finger offer 58 - I. flip word order (simple)]
How Axure installs a catalog
危机即机遇,远程办公效率为何会提升?
How to make Jenkins job run automatically after startup
一文解决浏览器跨域问题
DW basic course (II)
Opencv application -- jigsaw puzzle
airbase 初步分析
The computer is out of power. How did I pass the terrible interview of Tencent cloud?