How To turn a string with "pipe-separated" values into individual rows in Oracle PL/SQL
0
votes
1
answer
1470
views
I have a table with below structure :
create table student_info
(
item_number number,
st_firstname varchar2(50),
st_lastname varchar2(50),
st_score varchar2(50)
)
Here is a sample data of the table :
item_number | st_firstname | st_lastname | st_score
----------------------------------------------------------------------------
1 Ali|Reza|Pantea Hashemi|Nosrati|Yaghobi 10|20|20
2 Maryam|Ahmad Moghise|Majlesi 20|20
I need to have the below output:
item_number | st_firstname | st_lastname | st_score
----------------------------------------------------------------------------
1 Ali Hashemi 10
1 Reza Nosrati 20
1 Pantea Yaghobi 20
2 Maryam Moghise 20
2 Ahmad Majlesi 20
I've found that with below query, I can do what I want with one of the columns (Which is
st_firstname
):
select distinct t.item_number,
trim(regexp_substr(t.st_firstname, '[^|]+', 1, level)) str
from student_info t
connect by instr(st_firstname, '|', 1, level - 1) > 0
order by t.item_number
The problem is that I don't know how to add other columns(st_lastname , st_lastname) to above query. I was wondering if you could help me here.
Thanks in advance
Asked by Pantea
(1510 rep)
Mar 1, 2023, 01:02 PM
Last activity: Mar 1, 2023, 02:43 PM
Last activity: Mar 1, 2023, 02:43 PM