How to use “regular expression” to separate specific strings in OracleRegular expression problemRegular Expression DifficultyHow to use SUBSTRING using REGEXP in MySQLRegular expression in a SQL case statementHow to Apply a Title-Case RegEx Condition for Object Names with Policy Based ManagementData Warehouse Design and Double DippingHow to port LTRIM from Oracle to SQL Server?Select Statement with RegEx Replace - DB2 9.7How to make a backup of an Oracle database that does not mess up the regular backup cycle?Compare The length of two string variables inside an Expression task in SSIS
Is there a way to shorten this while condition?
Is it better to merge "often" or only after completion do a big merge of feature branches?
Can GPL and BSD licensed applications be used for government work?
Is the apartment I want to rent a scam?
What does a black-and-white Puerto Rican flag signify?
How does mathematics work?
What kind of vegetable has pink and white concentric rings?
How can I indicate that what I'm saying is not sarcastic online?
Why can't a country print its own money to spend it only abroad?
Are stackless C++20 coroutines a problem?
What is a "staved" town, like in "Staverton"?
5V/12V load balance of 3.5'' HDD?
What kind of anatomy does a centaur have?
What does the following chess proverb mean: "Chess is a sea where a gnat may drink from and an elephant may bathe in."
Can I pay with HKD in Macau or Shenzhen?
How can I deal with someone that wants to kill something that isn't supposed to be killed?
Why is the UH-60 tail rotor canted?
Are there any English words pronounced with sounds/syllables that aren't part of the spelling?
Impact of throwing away fruit waste on a peak > 3200 m above a glacier
How can I print a 1 cm overhang with minimal supports?
Can an infinite group have a finite number of elements with order k?
If I have the Armor of Shadows Eldritch Invocation do I know the Mage Armor spell?
Other than a swing wing, what types of variable geometry have flown?
Why did computer video outputs go from digital to analog, then back to digital?
How to use “regular expression” to separate specific strings in Oracle
Regular expression problemRegular Expression DifficultyHow to use SUBSTRING using REGEXP in MySQLRegular expression in a SQL case statementHow to Apply a Title-Case RegEx Condition for Object Names with Policy Based ManagementData Warehouse Design and Double DippingHow to port LTRIM from Oracle to SQL Server?Select Statement with RegEx Replace - DB2 9.7How to make a backup of an Oracle database that does not mess up the regular backup cycle?Compare The length of two string variables inside an Expression task in SSIS
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a string '(1:30,2:4,52:0,8:1)'
, and I need to use a regular expression to have this output:
field1 field2 level
1 30 1
2 4 2
52 0 3
8 1 4
The query I've wrote so far is:
select distinct trim(regexp_substr('1:30,2:4,52:0,8:1','[^:,]+',1,level)) repfield,level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1', '[^:,]+', 1, level) is not null
order by lvl
oracle oracle-11g plsql regular-expression split
add a comment |
I have a string '(1:30,2:4,52:0,8:1)'
, and I need to use a regular expression to have this output:
field1 field2 level
1 30 1
2 4 2
52 0 3
8 1 4
The query I've wrote so far is:
select distinct trim(regexp_substr('1:30,2:4,52:0,8:1','[^:,]+',1,level)) repfield,level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1', '[^:,]+', 1, level) is not null
order by lvl
oracle oracle-11g plsql regular-expression split
1
If you don't mind me asking, what does thelevel
column mean? Is it anid
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?
– LogicalBranch
Jul 14 at 18:54
2
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
1
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46
add a comment |
I have a string '(1:30,2:4,52:0,8:1)'
, and I need to use a regular expression to have this output:
field1 field2 level
1 30 1
2 4 2
52 0 3
8 1 4
The query I've wrote so far is:
select distinct trim(regexp_substr('1:30,2:4,52:0,8:1','[^:,]+',1,level)) repfield,level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1', '[^:,]+', 1, level) is not null
order by lvl
oracle oracle-11g plsql regular-expression split
I have a string '(1:30,2:4,52:0,8:1)'
, and I need to use a regular expression to have this output:
field1 field2 level
1 30 1
2 4 2
52 0 3
8 1 4
The query I've wrote so far is:
select distinct trim(regexp_substr('1:30,2:4,52:0,8:1','[^:,]+',1,level)) repfield,level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1', '[^:,]+', 1, level) is not null
order by lvl
oracle oracle-11g plsql regular-expression split
oracle oracle-11g plsql regular-expression split
edited Jul 14 at 20:47
dezso
23.1k11 gold badges61 silver badges100 bronze badges
23.1k11 gold badges61 silver badges100 bronze badges
asked Jul 14 at 5:32
Pantea TourangPantea Tourang
54816 bronze badges
54816 bronze badges
1
If you don't mind me asking, what does thelevel
column mean? Is it anid
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?
– LogicalBranch
Jul 14 at 18:54
2
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
1
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46
add a comment |
1
If you don't mind me asking, what does thelevel
column mean? Is it anid
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?
– LogicalBranch
Jul 14 at 18:54
2
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
1
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46
1
1
If you don't mind me asking, what does the
level
column mean? Is it an id
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?– LogicalBranch
Jul 14 at 18:54
If you don't mind me asking, what does the
level
column mean? Is it an id
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?– LogicalBranch
Jul 14 at 18:54
2
2
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
1
1
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46
add a comment |
2 Answers
2
active
oldest
votes
Simple method:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 1) field1,
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 2 3
8 1 4
Or with fewer regexp_substr
calls:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(:B1, '[^:,]+', 1, level*2 - 1 ) field1,
regexp_substr(:B1, '[^:,]+', 1, level*2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 0 3
8 1 4
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
add a comment |
with cte as
( select distinct trim(regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level)) repfield,
level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level) is not null
order by lvl)
select
SUBSTR(repfield,1,instr(repfield , ':')-1) AS Field1,
SUBSTR(repfield,instr(repfield,':')+1,length(repfield)) as field2,
lvl
from cte
Thanks for you're answer. I came to another way to solve this. I could not use regular expressions (I did not have enough information) so i used SUBSTR
and INSTR
instead
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "182"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f242819%2fhow-to-use-regular-expression-to-separate-specific-strings-in-oracle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simple method:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 1) field1,
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 2 3
8 1 4
Or with fewer regexp_substr
calls:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(:B1, '[^:,]+', 1, level*2 - 1 ) field1,
regexp_substr(:B1, '[^:,]+', 1, level*2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 0 3
8 1 4
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
add a comment |
Simple method:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 1) field1,
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 2 3
8 1 4
Or with fewer regexp_substr
calls:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(:B1, '[^:,]+', 1, level*2 - 1 ) field1,
regexp_substr(:B1, '[^:,]+', 1, level*2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 0 3
8 1 4
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
add a comment |
Simple method:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 1) field1,
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 2 3
8 1 4
Or with fewer regexp_substr
calls:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(:B1, '[^:,]+', 1, level*2 - 1 ) field1,
regexp_substr(:B1, '[^:,]+', 1, level*2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 0 3
8 1 4
Simple method:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 1) field1,
regexp_substr(regexp_substr(:B1, '[^,]+', 1, level), '[^:]+', 2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 2 3
8 1 4
Or with fewer regexp_substr
calls:
col field1 format a6
col field2 format a6
col lvl format a3
variable B1 varchar2(32);
exec :B1 := '1:30,2:4,52:0,8:1';
select
regexp_substr(:B1, '[^:,]+', 1, level*2 - 1 ) field1,
regexp_substr(:B1, '[^:,]+', 1, level*2) field2,
level lvl from dual
connect by regexp_substr(:B1, '[^,]+', 1, level) is not null;
FIELD1 FIELD2 LVL
------ ------ ---
1 30 1
2 4 2
52 0 3
8 1 4
answered Jul 14 at 8:49
Balazs PappBalazs Papp
28.4k2 gold badges10 silver badges32 bronze badges
28.4k2 gold badges10 silver badges32 bronze badges
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
add a comment |
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
1
1
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
I'm using Oracle 11-g and it gives me this error : Invalid sql statement . Would you mind editing your answer please?
– Pantea Tourang
Jul 14 at 10:07
2
2
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
@PanteaTourang There is nothing to edit. The above works fine in 11g as well. The error is thrown most likely by your client handling the statements differently. Use SQL*Plus and Oracle SQL Developer. Anything else is suboptimal. The above is from SQL Developer 19.1.
– Balazs Papp
Jul 14 at 10:40
add a comment |
with cte as
( select distinct trim(regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level)) repfield,
level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level) is not null
order by lvl)
select
SUBSTR(repfield,1,instr(repfield , ':')-1) AS Field1,
SUBSTR(repfield,instr(repfield,':')+1,length(repfield)) as field2,
lvl
from cte
Thanks for you're answer. I came to another way to solve this. I could not use regular expressions (I did not have enough information) so i used SUBSTR
and INSTR
instead
add a comment |
with cte as
( select distinct trim(regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level)) repfield,
level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level) is not null
order by lvl)
select
SUBSTR(repfield,1,instr(repfield , ':')-1) AS Field1,
SUBSTR(repfield,instr(repfield,':')+1,length(repfield)) as field2,
lvl
from cte
Thanks for you're answer. I came to another way to solve this. I could not use regular expressions (I did not have enough information) so i used SUBSTR
and INSTR
instead
add a comment |
with cte as
( select distinct trim(regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level)) repfield,
level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level) is not null
order by lvl)
select
SUBSTR(repfield,1,instr(repfield , ':')-1) AS Field1,
SUBSTR(repfield,instr(repfield,':')+1,length(repfield)) as field2,
lvl
from cte
Thanks for you're answer. I came to another way to solve this. I could not use regular expressions (I did not have enough information) so i used SUBSTR
and INSTR
instead
with cte as
( select distinct trim(regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level)) repfield,
level lvl
from dual
connect by regexp_substr('1:30,2:4,52:0,8:1,90:54', '[^,]+', 1, level) is not null
order by lvl)
select
SUBSTR(repfield,1,instr(repfield , ':')-1) AS Field1,
SUBSTR(repfield,instr(repfield,':')+1,length(repfield)) as field2,
lvl
from cte
Thanks for you're answer. I came to another way to solve this. I could not use regular expressions (I did not have enough information) so i used SUBSTR
and INSTR
instead
answered Jul 14 at 10:03
Pantea TourangPantea Tourang
54816 bronze badges
54816 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f242819%2fhow-to-use-regular-expression-to-separate-specific-strings-in-oracle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you don't mind me asking, what does the
level
column mean? Is it anid
? E.G: row 1 = level 1, row 2 = level 2, row n = level n?– LogicalBranch
Jul 14 at 18:54
2
Isn't there a convention of using upper case for the SQL keywords (SELECT, FROM, WHERE, etc.)?
– Peter Mortensen
Jul 14 at 20:37
1
@LogicalBranch Yes. It's kind of like an id . you're right.
– Pantea Tourang
Jul 15 at 4:46