Easy Question: How to split concatenated string into multiple rows?
Hi folks,
this might be an easy question.
How can I split a concatenated string into multiple rows using SQL query?
INPUT:
select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
Expected output:
data
AAA
BBB
CCC
DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
Thanks,
Tomas
Here is the SUBSTR/INSTR version of the solution:
SQL> WITH test_data AS
2 (
3 SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
4 )
5 SELECT SUBSTR
6 (
7 DATA
8 , INSTR
9 (
10 DATA
11 , ','
12 , 1
13 , LEVEL
14 ) + 1
15 , INSTR
16 (
17 DATA
18 , ','
19 , 1
20 , LEVEL + 1
21 ) -
22 INSTR
23 (
24 DATA
25 , ','
26 , 1
27 , LEVEL
28 ) - 1
29 ) AS NEW_STRING
30 FROM test_data
31 CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
32 /
NEW_STRING
AAA
BBB
CC
DDDD
Similar Messages
-
How to split this string into 4 sections to a max 35 characters
Hello,
Does anyone have an idea how I can acheive this please.
I have this string
Expense_Inv_8- ExpenseInv_7- Exp001- Expense_Inv_6- Expense_Inv_5- Expense_Inv_4- Expense_Inv_3- Expense_Inv_2- Expense_inv1
and I need to display them in sections seperated by ';' as explained below
Section 1 Section 2 Section 3 Section 4
Expense_Inv_8- ExpenseInv_7- Exp001;Expense_Inv_6- Expense_Inv_5;Expense_Inv_4- Expense_Inv_3;Expense_Inv_2;
need to split this string into 4 sections seperated by ';' and each section should be of no more than 35 characters, if null should end ;;;
Section 1, 35 Character ended by;
Section 2, broken off after Expense_Inv_5 because Expense_Inv_4 will take it over 35 chracters)
Section 3, should only take Expense_Inv_4- Expense_Inv_3, because adding Expense_Inv_2 will take it over 35
characters, each record in the string is seperated by '-'
Section 4, dispays the reminder of the string
regards
AdeHi,
Welcome to the forum!
Whenever you ask a question, it helps if you post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) and the results you want from that data.
I think I understand the problemk well enough to attempt a solution, but if the query below isn't right, please post that information.
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= ( SELECT MAX (LENGTH (txt))
FROM table_x
, got_best_path AS
SELECT id
, txt
, MAX ( SYS_CONNECT_BY_PATH ( TO_CHAR (c.n, '99')
) AS best_path
FROM cntr c
JOIN table_x x ON c.n <= LENGTH (x.txt)
START WITH c.n = 1
CONNECT BY c.n - PRIOR c.n BETWEEN 1
AND :section_length
AND x.id = PRIOR x.id
AND SUBSTR ( x.txt
, c.n
, 1
) = '-'
AND LEVEL <= :section_cnt
GROUP BY id
, txt
, got_pos AS
SELECT id
, REPLACE ( txt
) || ';' AS txt
, best_path
, TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 2)) AS pos_2
, TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 3)) AS pos_3
, TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 4)) AS pos_4
FROM got_best_path
SELECT id
, SUBSTR (txt, 1 , NVL ( pos_2 , :section_length)) AS section_1
, SUBSTR (txt, pos_2 + 1, NVL ((pos_3 - pos_2), :section_length)) AS section_2
, SUBSTR (txt, pos_3 + 1, NVL ((pos_4 - pos_3), :section_length)) AS section_3
, SUBSTR (txt, pos_4 + 1, :section_length ) AS section_4
FROM got_pos
;As written, this requires SQL*Plus 9 (or higher). You can have multiple versions or SQL*Plus on the same client, if you really need to keep the older version.
:section_length is the maximum length of each section (35, as you stated the problem).
:section_cnt is the number of sections. In the query above, this is 4. If you change it, you not only have to change the bind variable, but you have to change the hard-coded SELECT clauses of the main query and the last sub-query (that is, got_pos).
MODEL or PL/SQL would probably be better ways to solve this problem. -
How to split a string into tokens and iterate through the tokens
Guys,
I want to split a string like 'Value1#Value2' using the delimiter #.
I want the tokens to be populated in a array-like (or any other convenient structure) so that I can iterate through them in a stored procedure. (and not just print them out)
I got a function on this link,
http://www.orafaq.com/forum/t/11692/0/
which returns a VARRAY. Can anybody help me how to iterate over the VARRAY, or suggest a different alternative to the split please ?
Thanks.RTFM: http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#sthref1146
or
http://www.oracle-base.com/articles/8i/Collections8i.php -
How to Split 1 Order into Multiple Deliveries based on Partner Function ?
Hello,
How can I split one Sales Order into multiple deliveries, based on the partner function "managed by" ?
The requirement is that one order will be created for different "managed by".
If partner function "managed by" is same at line item level in order, than the items having same "managed by" can be combined in one delivery, else delivery will split and multiple deliveries will be created from 1 Order.
Jatin MistryHi,
You need to create a new requirement in tcode VOFM for that, together with your ABAP consultant. This requirement will be used in copy contol.
http://saptechsolutions.com/pdf/VOFMCopyRequirementRoutines.pdf
MdZ -
Splitting a string into multiple parts from particular position (string has no delimiter )
Hello Gurus,
I need to make string of having length 1000 into multiple parts from a particular position which has some text without any delimiter and i want to populate each part into an internal table which has one filed...
eg : string = 'sap abap sap abap sap abap sap abap sap abap sap abap sap abap sap sap sap abap sap abap'
suppose i want to start splitting from 40th position...assume that i have 3 parts
and these 3 parts i have put into an internal table..
lt_itab = [sap abap sap abap sap abap sap abap,
sap abap sap abap sap abap sap abap,
sap abap sap sap sap abap sap abap]
plese help!
any help would be Appreciated ...thank youHi,
Try this code.
TYPES: BEGIN OF ty,
b TYPE string,
END OF ty,
tt TYPE STANDARD TABLE OF ty.
DATA: a TYPE string VALUE 'aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll',
tb TYPE tt,
wa TYPE ty,
off TYPE i,
len TYPE i,
count TYPE i,
count1 TYPE i,
temp TYPE i.
len = 8. "Position
off = 0.
count = strlen( a ).
count1 = count / 8.
temp = len - 1.
DO count1 times.
temp = off + len.
IF temp > count.
wa-b = a+off.
ELSE.
wa-b = a+off(len).
ENDIF.
off = off + len.
SHIFT wa-b LEFT DELETING LEADING space.
APPEND wa to tb.
ENDDO.
LOOP AT tb INTO wa.
write: / wa-b.
ENDLOOP. -
Split a string into multiple internal tables
Hi all,
I need to split a string based internal table into multiple internal tables based on some sub strings in that string based internal table...
High priority help me out...
eg...
a | jhkhjk | kljdskj |lkjdlj |
b | kjhdkjh | kldjkj |
c | jndojkok |
d |
this data which is in the application server file is brought into a internal table as a text. Now i need to send 'a' to one internal table, 'b' to one internal table, so on... help me
<Priority downgraded>
Edited by: Suhas Saha on Oct 12, 2011 12:24 PMHi pradeep,
eg...
a | jhkhjk | kljdskj |lkjdlj |
b | kjhdkjh | kldjkj |
c | jndojkok |
d |
As per your statement "Now i need to send 'a' to one internal table, 'b' to one internal table"
Do you want only a to one internal table and b to one internal table
OR
Do you want the whole row of the internal table i mean
a | jhkhjk | kljdskj |lkjdlj | to 1 internal table
Having the case of an internal table which is of type string,
1) Loop through the internal table. LOOP AT lt_tab INTO lwa_tab.
2) Ge the work area contents and get the first char wa_tab-string+0(1)
3) FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.
w_tabname = p_table.
CREATE DATA w_dref TYPE TABLE OF (w_tabname).
ASSIGN w_dref->* TO <t_itab>.
Follow the link
http://www.sap-img.com/ab030.htm
http://www.sapdev.co.uk/tips/dynamic-structure.htm
and then based on the sy-tabix values you will get that many number of internal table
<FS> = wa_tab-string+0(1)
append <FS>
OR
USE SPLIT statement at the relevant seperator
revert for further clarification
Thanks
Sri
Edited by: SRIKANTH P on Oct 12, 2011 12:36 PM -
How to split a string into alfa-numerics and numerics ?
Thru I/O Assistant.vi I queried a GPIB frequency synthesizer and get a string " FRq99999.999999Hz " ( this is a micro Herz synthesizer and the query shows the correct value ).
The "9"'s are alfanumerics as well as the " FRq " and the " Hz ".
Thru a string indicator I can see this complete value on the front panel.
So far so good.
But now :
1.
How could I separate the numerics ( in string format ) out of this string and convert them into numerics in order to have them displayed in some numerics graph form ?
2.
How could I delete the " FRq " and the " Hz " out of the string, so that the " 9 " 's remain and could be converted into numerics ?
This result wil be the same as my question #1 but now ther
e will be no A/N remainder.
Thanks for any help.reteb wrote:
> Thru I/O Assistant.vi I queried a GPIB frequency synthesizer and get a
> string " FRq99999.999999Hz " ( this is a micro Herz synthesizer and
> the query shows the correct value ).
> The "9"'s are alfanumerics as well as the " FRq " and the " Hz ".
>
> 2.
> How could I delete the " FRq " and the " Hz " out of the string, so
> that the " 9 " 's remain and could be converted into numerics ?
> This result wil be the same as my question #1 but now there will be no
> A/N remainder.
Scan From String with a format string of "%.;%[^0-9]%f"
Explanation:
%.; : use point as decimal comma
%[0-9] : scan all characters not equal to 0 up to 9
%f : scan for floating point number using the decimal comma
indicated at the beginning.
Rolf Kal
bermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
How to split a string into columns
Hello to all ,
Having a strings like this, where pipe(|) is his delimiter
10:00 | x1 | 2 | RO | P | Con ausilio | y1
10:10 | x2 | 1 | RO | | | y2
10:20 |x3 | 3 | | | | y3
10:30 |x4 | 3 | RO | N | Con aiuto | y4
10:40 |x5 | 1 | RO | | | y5
how can I break it up into columns, for example, the first char(before first pipe) insert in first variable,
then, after first pipe, second characters in a other column ans so on
col1 := '10:00';
col2 := 'x1';
col3 := '2';
col4:= 'RO';
col5 := 'P';
col6 := ' Con ausilio ';
col7 := 'y1';
col1 := '10:10';
col2 := 'x2';
.. and so on
thanks in advanceHi,
check this:
WITH mydata(txt) AS
SELECT '10:00 | x1 | 2 | RO | P | Con ausilio | y1' FROM DUAL UNION ALL
SELECT '10:10 | x2 | 1 | RO | | | y2' FROM DUAL UNION ALL
SELECT '10:20 |x3 | 3 | | | | y3' FROM DUAL UNION ALL
SELECT '10:30 |x4 | 3 | RO | N | Con aiuto | y4' FROM DUAL UNION ALL
SELECT '10:40 |x5 | 1 | RO | | | y5' FROM DUAL
SELECT TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,1)) col1
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,2)) col2
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,3)) col3
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,4)) col4
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,5)) col5
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,6)) col6
, TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,7)) col7
FROM mydata;
COL1 COL2 COL3 COL4 COL5 COL6 COL7
10:00 x1 2 RO P Con ausilio y1
10:10 x2 1 RO y2
10:20 x3 3 y3
10:30 x4 3 RO N Con aiuto y4
10:40 x5 1 RO y5 Regards.
Al -
How to split Large file into Multiple small files..
Hi,
My source file is simple XML structure...and target side also i need to send in XML files .. but in the source file I'm getting all the data at a time.. so source file is more than 1000 records.. but i want to process 50 records at a time...
bu using FCC (RecordSet per Message) we can solve this.. but I dont want to do any File conversion.. i want to send in XML file only...
for this.. how we can handle....
Regards
JainJain,
Please see the below screenshots.
http://www.flickr.com/photos/23855877@N07/2991137391/sizes/o/
http://www.flickr.com/photos/23855877@N07/2991137441/sizes/o/
http://www.flickr.com/photos/23855877@N07/2991988028/sizes/o/
http://www.flickr.com/photos/23855877@N07/2991988084/sizes/o/
For No, Name, City Map Directly.
In the example, I've given 5 records to split. If you want 50 records to split, then instead of 5 give 50 in the constant.
raj. -
How to split file dynamically into multiple files according to row result
Hello, I want to split and create new document after specific data by using BI Publisher. Can anyone help me.
For e.g. I am running a report and it is giving 5 result rows and it is generating one file with all the 5 result rows but is it possible to generate new document or file for each row. So at last I will have 5 documents/files with me.
Edited by: user10512424 on Aug 19, 2010 4:11 AMHi ,
I think bursting of the report will help you.
Look the link below.
http://www.strsoftware.com/blogs/oracle/2009/12/how-to-burst-and-deliver-documents-from-bi-publisher-enterprise/
Thanks. -
How to Split Master File into Multiple Small Files?
Sorry if this has been addressed - I'm having a hard time finding the answer.
I'm using FCE 4.0. I taped 4 hours of material and need to deliver the footage to someone in discrete chunks. I tried to do in/out capture but for some reason that wasn't working - something to do with the timecode. So I did full tape dumps.
So now I have 4 huge files (4 miniDV tapes) that are too big to deliver as-is. I used DV Start/Stop Detect to set markers, then used that to create sub-clips. But of course this doesn't actually affect the master scratch files.
What's the best way to convert these sub-clips to individual mov files? If I do an export of each file ("Using QuickTime Conversion..."), don't I risk losing information or possibly quality? Isn't there some way to highlight all my sub-clips in the bin and say "Mega-Chop Activate!" or something?
Or, taking a step or two back, if there's another way I should've approached this, please let me know. There'll be more. Plenty more.
Thank you.I'm burning mov source to DVD for FC editing by someone else.
Your second set of questions actually gives me some ideas - that's exactly what I'm trying to figure out.
As an example, let's say 1 tape, i.e. 1 master file, holds 5 interviews. I want to deliver 5 individual files/clips, say 3 on DVD A, 2 on DVD B. (Assume for the sake of argument that the math works out and there's no other way to deliver this.)
- Does creating a different project for each "chunk" result in a different file in the scratch folder that can be burned to DVD?
- Does "Print to Video" create QT files? I thought this output back onto tape.
- By "Export to QuickTime" are you referring to Export->QuickTime Movie (as opposed to Export->Using QuickTime Conversion)?
- Does Export->QuickTime Movie result in lossy conversion or does it automatically retain the original capture quality?
- Is there a way to do all 5 exports at once or must they be done individually?
Thanks for the fast response! -
Split the data into multiple rows in table
Hello,
I am using Oracle 10g apex 3.2.
I have a requirement like this.
I have a table like TableA
Col1 Col2
90 1
91 1:2:3
92 3
I want the data like
Col1 Col2
90 1
91 1
91 2
91 3
92 3
How to do this?
Thanks
Edited by: user13305573 on Aug 3, 2010 8:16 PMwith
your_data as
select 90 as col1, '1' as col2 from dual union all
select 91, '1:2:3' from dual union all
select 92, '3' from dual
select
y.col1,
regexp_substr(y.col2, '[^:]+', 1, t1.column_value) as col2
from
your_data y,
13 table(cast(multiset(select level from dual connect by level <= length (regexp_replace(y.col2, '[^:]+')) + 1) as sys.OdciNumberList)) t1
14 /
COL1 COL2
90 1
91 1
91 2
91 3
92 3
5 rows selected.
Elapsed: 00:00:00.05
ME_XE?select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
5 rows selected.
Elapsed: 00:00:00.03
ME_XE? -
Convert comma separated to string into multiple row
Hi,
I have SQL query which will fetch the data like below.
{code}
ID NAME CODE
1 A,B 5,2
2 X 10
3 Z 4
{code}
So now i have to split the data like below
{code}
ID NAME CODE
1 A 5
1 B 2
2 X 10
3 Z 4
{code}https://forums.oracle.com/thread/2549548
-
Splitting a concatenated string to multiple cells in a row in BIP Reports
Hello Experts,
Let me how to split a concatenated string into multiple cells in BIP reports rtf.
Ex:
string: acg;ghdf;tesrlkjj;hvfffda
has to placed in multiple cells like
string1: acg
string2: ghdf
string3: tesrlkjj
string4: hvfffda
Appreciate your quick reply.
Please drop in the pseudo code.
Thanks & Regards
SyedThe report is based on a standard sql query such as
select item1, item2, item3, item4, item5, item6, item7
from mytable
order by item1Wanted to put that in as I am not using an interactive report.
Thanks
Wally -
Crystal report - how to split a field into more fields
Hello,
I`m new to Crystal reports and I`ve got a trouble. I have field which contains an address - street, city, zip code. The example is:
STEHLIKOVA 977 165 00 PRAHA 620 - SUCHDOL 165 00.
What I need to achieve is to split this string into three separated fields. I`ve trouhg a couple of forums but haven`t been able to find a proper answer. The problem is that the addresses differ so I can`t use an absolute defining of a start position. Looking at the DB (HEXA code) the parts in the string are divided by two dots:
STEHLIKOVA 977..165 00 PRAHA 620 - SUCHDOL..165 00
I`ve been able to work out this solution:
stringVar array x := split({cparty.STREET_ADD},"..");
Local numberVar i;
Local stringVar outputString := "";
For i:=1 to Count(x) do
outputString := outputString + x[i] + Chr(10)
outputString;
It splits the string into three rows:
STEHLIKOVA 977
165 00 PRAHA 620 - SUCHDOL
165 00
And I don`t know how to find the end of each row so to be able to separate the strings and report them as three different fields.
Would be anyone so kind and help me out with this?
Thank you.
PetrHi
Actually using a for loop is not necessary here. All you need to do is to add several formula fields: one for street, one for city and one for zipcode. In @street field you add formula:
stringVar array x := split({cparty.STREET_ADD},Chr(13));
x[1];
Then you drag such formula field to details section of your report and watch preview to check if everything looks alright. Repeat for every formula field that you'd like see in your report.
In @city you add almost identical formula but you change index, i. e. instead of x[1] you need to use x[2]. Then for @zip x[3].
You may need to check if your address has all three parts - for example if you want to use formula in the second part of your address field you may need check first if there are at least two parts after split:
stringVar array := split({cparty.STREET_ADD},Chr(13));
numbervar c;
c := count(x);
if 2 <= c then
x[c];
Var 'c' is used to store the number of elements in array after split. Then I'd like to check if the part (second) actually exists. So I try to check if number of part that I want to refer to is not bigger than the number of elements in array after split (here stored in var 'c').
Actually the code presented above is not enough since you have no guarantee that you'll always get address structured in the very same way. For example in demo PL database I have zip code and city in the same row after split with Chr(13) as delimiter.
You'll need to experiment or ask someone to prepare correctly structured data coming from B1 to your report.
Kind regards,
Radek
Maybe you are looking for
-
Photoshop elements 4.0 日本語版mac用 ユーザー登録できない件
現在Photoshop elements 4.0 日本語版mac用 を使っています. 購入後にユーザー登録忘れていたので. 昨日 Adobe ID Webページからユーザー登録しようとしたら. シリアル番号(10570208769231063245****)が存在しないと言われました. 何が原因でしょうか?
-
Unable to get yahoo mail working after upgrading to ios5
I updated my IPhone 4G at the same time & have no problems with the phone. I get the message of server is unavailable. I have deleted the mail account & reentered it & continue to get the same problem.
-
I am having trouble on printing a pdf file. how can i fix it.
How can I print PDF files with Microsoft Vista?
-
Printer setup when SMARTFORM is printing
Hello guys. I have a problem with smartform printing, when I make it, there is screen with printing input parameters like OutputDevice, Copies, Page selection, Print immediatelly etc. All of this parameters are stored in SSFCOMPOP structure, but ther
-
How to delete old question forums?
How do I delete old forums on here that my questions were answered and no longer need to post up?