Split a string using regexp_substr with consecutive delimiter
I split a string with tubes as a delimiter. A string like this for example:
"THIS |" EAST | ONE | EXAMPLE '
If I do something like this:
SELECT REGEXP_SUBSTR('THIS|IS|AN|EXAMPLE', '[^|]+', 1, 4) FROM DUAL
I would get the word EXAMPLE
But if the string is like this:
"THIS |" EAST | ONE | EXAMPLE '
With the above query, I always get EXAMPLE, but the word should be in the next position (5) because after IS, there should be an empty element
Is it possible to change the regular expression to also get the empty element?
Thanks in advance
Well, the way I understand it, you get this behavior, because there is 'nothing' between the delimiters. so there is a field, so it does not display it don't think the regular expression.
Try it with a space between the delimiters - works fine.
So, with this in mind, the simplest solution might be something like that?
regexp_substr (replace(c,'||','| |'), "[^ |]") +' 1, 4)
[edited to avoid having a partial answer marked "correct"]
As mentioned below by a few others, there are other solutions using regular expressions.
The solution above does not work if more than 2 consecutive fields are empty, or if the first or last is empty.
A simple tweak to the logic would help with this:
RTrim (regexp_substr (replace (c,'|))) ',' |'), ' [^ |] +', 1, level))
However, even if it has still some limitations compared to the solution of the full regular expression mentioned by Frank, below.
[/ Edit]
Tags: Database
Similar Questions
-
split a string using any delimiter and display a table
Hello
I'm trying to split a delimited string and an array of the output results.
I come from a background of .net and c# code I would use would be
Dim myString As String = "mystring\r\nto\r\nsplit";
String [] myString = mystring. Split (newchar [] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
The code above have a line of muli on the input string (where the \r\n) and the output of a table with the following content
'mystring '.
« à »
'split '.
In addition, I would like to also support comma-delimited files.
I used the string function
"Spreadsheet String To Array" that works well enough for the lines of delimited by commas, but not when the delimiter is something funky like '\r\n '.
vi.llb in the advanced channel folder there are some goodies that do not surrender to the Kroatiens
-
Chain of Split which begins with a delimiter
Hi all
I am trying to split a string using "-" as a separator and store values (strings) in a list. The problem is that, because the string begins with the delimiter, I get an empty (as my first item) element in my list. I would appreciate your help to solve this problem.
My code is:
The output should bepublic class SplitString { public static void main(String[] args) { String str = "-Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy" + "-Djava.awt.headless=true -Dhttp.webdir.enable=false"; SplitAndStoreAsList(str); } public static void SplitAndStoreAsList(String str){ List<String> list = Arrays.asList(str.split("-")); for (int i = 0; i<list.size(); i++){ System.out.println(i + ": " + "-" + list.get(i)); } } }
But it is0: -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy 1: -Djava.awt.headless=true 2: -Dhttp.webdir.enable=false
0: - 1: -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy 2: -Djava.awt.headless=true 3: -Dhttp.webdir.enable=false
Why not just change the regular expression that is
List
list = Arrays.asList(str.split("(? -
How to split a string into several substrings parent using a delimiter
Hello
I am forced to split a string into several substrings parent using a delimiter.
And insert these substrings in variuou of the columns of a table in a row.
For example. The sting is: ABC * DEF * GHI * JKH *.
where ' *' is the separator.
Desired output:
Col1 Col2 Col3 Col4 Col5
------- -------- -------- ------- ---------
JKH GHI ABC DEF (null)
Could you please guide me how can I achieve this.
Thank you
Bogoss
Hello Salim,
Leave the thread for reference... got this excerpt:
with t as
(
Select "c: its: hgfd:1:23" Str
)
Select
REGEXP_SUBSTR (str, ' ([^:] *)(:|$)', 1, 1, null, 1) col1
, REGEXP_SUBSTR (str, ' ([^:] *)(:|$)', 1, 2, null, 1) col2
, REGEXP_SUBSTR (str, ' ([^:] *)(:|$)', 1, 3, null, 1) col3
, REGEXP_SUBSTR (str, ' ([^:] *)(:|$)', 1, 4, null, 1) col4
, REGEXP_SUBSTR (str, ' ([^:] *)(:|$)', 1, 5, null, 1) col5
t;
This code snippet works well, but for the fixed columns. Here are 5 predefined columns.
But I need to have a logic that I can browse the string any No.. sometimes.
For example. If I get 3 secondary channels of the parent chain... I need to insert into 3 columns.
And if I get 6 strings under... I need to insert into 6 columns.
Could you please help me develop a logic like that.
I use Oracle database 10g.
And the data are currently being collected on external table... but I can store in a variable or a column of a database table.
Thank you
Bogoss
-
How to search for a string with various occurrences using regexp_substr
Hi all.
My cenario's
'.... 456re0, 50kg 400, 500rfabs43qre30, 25kg 150, 354rf658... »
It is possible, using regexp_substr or another way to get the values, 0,50 and 400 500 and 30.25 150 354?
I am using [^ d] + [$kg] and the string comes, but only the first occurrence...
TKS.claudioaragao wrote:
I need the results of...with sample_table as ( select '....456re0,50kg400,500rfabs43qre30,25kg150,354rf658....' str from dual ) select regexp_substr(str,'re.*?rf',1,column_value) sub_str from sample_table, table( cast( multiset( select level from dual connect by regexp_substr(str,'re.*?rf',1,level) is not null ) as sys.OdciNumberList ) ) / SUB_STR ------------------- re0,50kg400,500rf re30,25kg150,354rf SQL>
SY.
-
Chips with 3 delimiter characters using regular expressions
Hello world
I have a function that is able to mark the input in a collection string using regular expressions.
In case the input string is a character such as the comma or semicolon delimiter,
We can just get the result we want like the example below.
SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for 64-bit Windows: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
SQL> with tab1 as ( 2 select 'abc,dfg,h,,1234' as col1 from dual 3 ) 4 select regexp_substr(col1, '([^,]*)(,|$)', 1, level, 'i', 1) as result 5 from tab1 6 connect by level <= regexp_count(col1, ',')+1; RESULT --------------- abc dfg h 1234
But in the case where the channel of entry has 2 types of delimiter and each delimiter consists of 3 characters as below
I wonder if it is possible to get the result as below.
The input string: 01| ^ | ABCD| ^ | 111| * | 02| ^ | efgh| ^ | 222
Separators: | * | is divided into lines, | ^ | is divided into columns
Expected result:
col1 col2 col3
Row1 - > 01 abcd 111
row2-> efgh 02 222
Simply put, take a next
The input string: 01| ^ | ABCD |^| 111 |*| 02 |^| efgh |^| 222
Separator: | * |
Result:
01. ^ | ABCD | ^ | 111
02. ^ | efgh | ^ | 222
How can I achieve this using regular expressions?
Kind regards
Euntaek
You need to know the number of the column from the outset:
with tab1 as)
Select ' 01 | ^ | ABCD | ^ | 111. * | 02. ^ | efgh | ^ | 222' as double col1
)
Select rownum,
regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 1, null, 1) col1,.
regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 2, null, 1) col2.
regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 3, null, 1) col3
of tab1
connect by level<= regexp_count(col1,'\|\*\|')="" +="">=>
/
ROWNUM COL1 COL2 COL3
---------- ----- ----- -----
1 01 abcd 111
2 efgh 02 222
SQL >
SY.
-
After you rename a folder full of .dng and. MOV files using LR CC, I now have two of each file DNG image with consecutive numbers providing unique names. . MOV files are not affected. Activated with "Bridge" and found it said one is one Mac Application, either in the form of windows. I have Lightroom on Mac and Windows PC with local catalogues which are clouds synchronized (but never on at the same time). Could be the cause of this problem? It is possible that differ from the Mac and Windows version catalogs and their creative together via the Cloud technology synchronization can cause this duplication is obvious when all files are renamed by using a number of automatic sequence?
Yes, my default sort criteria is by file name as my beginning of file names with a reverse date followed by a sequence number. I think at some stage I must have reproduced all the files on the Windows PC and saved with a different range of sequence numbers after the element of date filenames outside of LR. Sometime later I have imported in the Lightroom. When I decided to rename all of them using this naming convention, I discovered the duplication hiding behind different file names. This turns out to be a lesson on the practices of workflow systems.
-
splits the string into 3 parts
Hello
I have a requirement to split the string into 3 different room example inf.ethz.ch should be subdivided into inf ethz ch in 3 different column
We have table called email within this column contains all identification of email we need to divide email with dot (.) in different columns and display please suggest how to implement in the query
Thank you
Sudhir
Use REGEXP_SUBSTR:
SQL > with t as (select ' inf.ethz.ch' double txt)
2 Select regexp_substr (txt,'[^.] +') part_1,.
3 regexp_substr (txt,'[^.] +', 1, 2) part_2,.
4 regexp_substr (txt,'[^.] +' 1, 3) part_3
5 t
6.BY PARTY PA
--- ---- --
INF ethz chSQL >
Or you can use SUBSTR + Instr.
SY.
-
splits the string into documents
Hello
I did a query (see regexp) that split a string into records. The problem with the query is the separate in the subquery. Otherwise, it returns millions of records where I expect less than a thousand.
Meanwhile, I found an other solution (see xmlsequence), but this statement returns the message "ORA-03113: end of file on the communication channel.
Please advice.
regexp:
xmlsequence:SELECT smp.sample_id FROM ( SELECT sa.sample_id, sau.u_box_code, sau.u_box_position FROM lims_sys.sdg sd, lims_sys.sdg_user sdu, lims_sys.sample sa, lims_sys.sample_user sau WHERE sd.sdg_id = sdu.sdg_id AND sd.sdg_id = sa.sdg_id AND sa.sample_id = sau.sample_id AND sau.u_padded_out = 'F' AND sdu.u_client_type = decode('#Client#','-1',sdu.u_client_type,'#Client#') AND sdu.u_crop_group = decode('#Crop#','-1',sdu.u_crop_group,'#Crop#') AND sdu.u_year_of_sample_delivery = decode('#Year#',-1,sdu.u_year_of_sample_delivery,'#Year#') AND sdu.u_week_of_processing = decode('#Week#',-1,sdu.u_week_of_processing,'#Week#') AND sd.status IN ('V','P','C') ) smp, ( SELECT distinct box_code, regexp_substr(box_pos,'[^,]+',1,level) box_pos FROM ( SELECT p.name box_code, substr(p.description,instr(p.description, 'NP=') + 3) box_pos FROM lims_sys.plate_template pt, lims_sys.plate p, lims_sys.plate_user pu WHERE pt.plate_template_id = p.plate_template_id AND p.plate_id = pu.plate_id AND pt.name = 'Box96' AND p.status IN ('V','P','C') AND p.description like '%NP=%' AND pu.u_client_type = decode('#Client#','-1',pu.u_client_type,'#Client#') AND pu.u_crop_group = decode('#Crop#','-1',pu.u_crop_group,'#Crop#') AND pu.u_year = decode('#Year#',-1,pu.u_year,'#Year#') AND pu.u_week = decode('#Week#',-1,pu.u_week,'#Week#') ) connect by level <= length(box_pos) - length(replace(box_pos,',')) + 1 ) box WHERE smp.u_box_code = box.box_code AND smp.u_box_position = box.box_pos
SELECT smp.sample_id FROM ( SELECT sa.sample_id, sau.u_box_code, sau.u_box_position FROM lims_sys.sdg sd, lims_sys.sdg_user sdu, lims_sys.sample sa, lims_sys.sample_user sau WHERE sd.sdg_id = sdu.sdg_id AND sd.sdg_id = sa.sdg_id AND sa.sample_id = sau.sample_id AND sau.u_padded_out = 'F' AND sdu.u_client_type = decode('#Client#','-1',sdu.u_client_type,'#Client#') AND sdu.u_crop_group = decode('#Crop#','-1',sdu.u_crop_group,'#Crop#') AND sdu.u_year_of_sample_delivery = decode('#Year#',-1,sdu.u_year_of_sample_delivery,'#Year#') AND sdu.u_week_of_processing = decode('#Week#',-1,sdu.u_week_of_processing,'#Week#') AND sd.status IN ('V','P','C') ) smp, ( SELECT box_code, trim(x.column_value.extract('e/text()')) box_pos FROM ( SELECT p.name box_code, substr(p.description,instr(p.description, 'NP=') + 3) box_pos FROM lims_sys.plate_template pt, lims_sys.plate p, lims_sys.plate_user pu WHERE pt.plate_template_id = p.plate_template_id AND p.plate_id = pu.plate_id AND pt.name = 'Box96' AND p.status IN ('V','P','C') AND p.description like '%NP=%' AND pu.u_client_type = decode('#Client#','-1',pu.u_client_type,'#Client#') AND pu.u_crop_group = decode('#Crop#','-1',pu.u_crop_group,'#Crop#') AND pu.u_year = decode('#Year#',-1,pu.u_year,'#Year#') AND pu.u_week = decode('#Week#',-1,pu.u_week,'#Week#') ) t, table (xmlsequence(xmltype('<e><e>' || replace(t.box_pos,',','</e><e>')|| '</e></e>').extract('e/e'))) x ) box WHERE smp.u_box_code = box.box_code
Hello
When 'LEVEL '.<= x"="" is="" the="" only="" connect="" by="" condition,="" then="" you="" should="" be="" using="" a="" table="" that="" has="" only="" one="" row,="" like="">=>
You can generate a Table of counters (a result set, in fact) who has all the integers that you need and then join one.
The next thread is an example:
I don't don't want to mark in plsql -
SQL / PLSQL to split the string into pieces
Hi all
I have a problem of data conversion from the name of one table to another structure.
for example
SQL > desc names
Name Null? Type
----------------------------------------- -------- ----------------------------
TITLE VARCHAR2 (5)
FNAME VARCHAR2 (20)
LNAME VARCHAR2 (20)
SQL > Data desc
Name Null? Type
----------------------------------------- -------- ----------------------------
FULLNAME VARCHAR2 (50)
Insert in data values ("SIR I HAVE ONE NAME PARTICULARLY LONG INDEED");
Insert in the data values ("MINE IS EVEN MORE, ENOUGH RIDICULEMENT so IN FACT");
Essentially, I need to divide these names long, stored in the 1 field, in the above 3 fields. The trickiest part is however I want to do it in such a way so that if the 1st part of the name fits the 1 5 char field I want to do, otherwise I would divide between 2 fields - once again without splitting a string. The reason behind this is that application will automatically put a space between each field when they appear and I would avoid gaps in the names if possible.
This baffled me a little if any help would be seriously great... it might not even be a go-er, as it might be too uneconomic with the amount of available space, but I would give it a shot.
Thank you!
AdamHi, Adam.
Use regular expressions:
INSERT INTO names (title, fname, lname) SELECT RTRIM (REGEXP_SUBSTR ( fullname , '^.{1,5} ' ) ) , REGEXP_REPLACE ( fullname , '(^.{1,5} )?' || -- \1 = optional 1-5-letter word(s) '(.{1,20})' || -- \2 = 1-20 letters '(( .*)|$)' -- \3-\4 = space (plus anything) or end , '\2' ) , REGEXP_REPLACE ( fullname , '(^.{1,5} )?' || -- \1 = optional 1-5-letter word(s) '(.{1,20}( |$))' || -- \2-\3 = 1-20 letters and space or end '(.{1,20})?' || -- \4 = 0-20 letters '(( .*)|$)' -- \5 = space (plus anything) or end , '\4' ) FROM data_table -- data is not a good name ;
Published by: Frank Kulash, August 18, 2009 11:13
Revised to manage long single word fullname -
How to split a string variable in BPEL
Hello
I have a variable which I fetch it database with a delimiter. Need to separate this variable to obtain all the values in the BPEL.
For example, I get a column that contains data from a, b, c end,
I need all these values separately in the BPEL process as 'a' 'b' 'c' and 'end '.
In java, we can do this by using the below lines...
= String values "a, b, c, end;
String [] array array1 = values.split(",");
I don't find a split function in BPEL string functions. Could someone show some light on this please.
Kind regards
PSNo, there is not such a generation - in function for this. You could do:
-Create a Java class to do this. Wrap the Java class as a Web service, deploy it and call it from BPEL.
-Create a PL/SQL function to do this. Access the function from PL/SQL to the DB adapter.Marc
http://orasoa.blogspot.com -
Oracle regular expressions - splits the string into words for
Hello
Nice day!
My requirement is to split the string into words.
So I need to identify the new line character and the semicolon (;), comma and space like terminator for string entry.
Please note that I am currently embedded blank and the comma as separator, as shown below.
Select regexp_substr('test)
TO
string in words, "([^, [: blanc:]] +) (', 1, 1) double;"How to integrate the semicolons and line break characters in regular expression Oracle?
Please notify.
Thanks and greetings
Sree
This has nothing to do with REGEXP. Is SQL * more parser does not not a semicolon at the end of the line:
SQL > select ' testto, mm\;
ERROR:
ORA-01756: city not properly finished chainSQL >
Just break the chain:
SQL > select regexp_substr ('testto, mm\;' |) '
2 string into words
3 \w+',1,level ',') of double
4. connect by level<= regexp_count('testto,mm\;'="" ||="">=>
5 string in words
6 ','\w+')
7.REGEXP_SUBSTR ('TESTTO, MM\;' |') STRINGIN
--------------------------------------
Testto
mm
string
in
WordsSQL >
Or modify SQL * more the character of endpoints:
SQL > set sqlterm.
SQL > select regexp_substr ('testto, mm\;)
2 string into words
3 \w+',1,level ',') of double
4. connect by level<=>=>
5 string in words
6 ','\w+')
7.REGEXP_SUBSTR ('TESTTO, MM\;) STRINGINTOWO
--------------------------------------
Testto
mm
string
in
WordsSQL >
SY.
-
How to split a string into columns
Hi all
Have a strings like this, where the delimiter is
Thanks in advance10: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
Hello
If you want to split the string str into 7 columns :
SELECT TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 1)) AS col1 , TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 2)) AS col2 , TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 3)) AS col3 ... , TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 7)) AS col7 FROM table_x ;
If you want to split it inot 7 variables :
col1 := TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 1)); col2 := TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 2)); col3 := TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 3)); ... col7 := TRIM (BOTH FROM REGEXP_SUBSTR (str, '[^|]+', 1, 7));
-
split a string into pl/sql
Hello
How to split a string and store in an associative array in pl/sql.function
My string like this
'1102,1101,1012,1011,1010,1009,1008,1007,1006,10005,1004,1003,1002,1001'
and assign it to the array list. According to
can someone please help
concerning
rYou can try the following. Although I recommend, it would be better to write the function code php as a java stored procedure parser and use the result. We have a class defined in Java String Tokenizer.
-- Define function to split string into tokens FUNCTION get_token( p_input_string IN VARCHAR2, -- input string p_token_number IN PLS_INTEGER, -- token number p_delimiter IN VARCHAR2 DEFAULT ',' -- separator character ) RETURN VARCHAR2 IS v_temp_string VARCHAR2(32767) := p_delimiter || p_input_string ; v_pos1 PLS_INTEGER ; v_pos2 PLS_INTEGER ; BEGIN v_pos1 := INSTR( v_temp_string, p_delimiter, 1, p_token_number ) ; IF v_pos1 > 0 THEN v_pos2 := INSTR( v_temp_string, p_delimiter, 1, p_token_number + 1) ; IF v_pos2 = 0 THEN v_pos2 := LENGTH( v_temp_string ) + 1 ; END IF ; RETURN( SUBSTR( v_temp_string, v_pos1+1, v_pos2 - v_pos1-1 ) ) ; ELSE RETURN NULL ; END IF ; EXCEPTION WHEN OTHERS THEN RAISE; END get_token; -- Call the above function in loop for a string with N tokens DECLARE TYPE assoc_arr_str_typ IS TABLE OF VARCHAR2(100) INDEX BY PLS_INTEGER; str_arr assoc_arr_str_typ; v_str VARCHAR2(200) := '1102,1101,1012,1011,1010,1009,1008,1007,1006,10005,1004,1003,1002,1001' ; v_token VARCHAR2(4) ; i PLS_INTEGER := 1 ; BEGIN LOOP v_token := get_token( v_str, i , ',') ; EXIT WHEN v_token IS NULL ; dbms_output.put_line( v_token ) ; str_arr(i) := v_token; i := i + 1 ; END LOOP ; END ; /
Published by: GG 24 March 2011 09:51
-
validation of the email does not take exception to emailID with consecutive.
I use javax.mail.jar 1.5.2
Validation of the email does not throw AddressException for e-mail with consecutive. as [email protected] which, according to RFC822, should generate exceptions.
Is there any solution for this?
Kind regards
Naveen
N °
It would be nice if JavaMail did a more complete job of checking the syntax of an e-mail address, at least in 'strict', but 'invalid' mode addresses meet quite frequently, and syntax checking does not tell you if the address is actually valid, so JavaMail he leaves to the mail server to make the actual validation.
Maybe you are looking for
-
MacBook Pro 5.2 die slowly...! What can I do?
I got lucky to have had the use of a MacBook Pro 5.2 for recent years. I had the chance to receive on the basis of a long-term loan, but it seems now it begins to die. During most of the last year or so it has not lit immediately on the power button
-
Satellite A200-1vp with Vista - code 39 of the CD/DVD drive failure
Hello I was burning and watch DVDs on my Satellite A200 - 1 VP, with vista, since February, the last time I burned anything was a couple of weeks. Suddenly, there is a problem, no response when I insert a disc and my divx player says me no recorder f
-
With the help of 2 generators of signals on a FIFO shared
I have the device of the series M (NI USB-6259) and would create 2 tasks, DO1 and DO2, using subsets of lines on Port 0. The two waveforms will be sinosoidales, that I will store on FIFO of the device. Both tasks will have different examples of two l
-
Add Wizard hardware detects new hardware when I don't have any new material
Recently and all of a sudden, the Hardware Wizard detects new hardware. I don't have all new equipment installed. What is the solution?
-
Registered home page will not play dvd
Home recorded DVD won't play in Windows Media or Total Media. Store bought ones will play - but without the sound! the clues out there please