REGEXP_SUBSTR output
Hi all, I have a query with the sample data provided. I have to remove the first 5 characters of data, including the hyphen. But little coulmns has no hyphen and little a hyphen in the middle of something. The first 5 characters can be alphanumeric.
WITH t AS ( SELECT '01667-MICRO ENTERPRISES ( P/ARR)' DATA FROM dual UNION ALL SELECT '02E60-SOROS ECONOMIC DEV. FUND LN' FROM dual UNION ALL SELECT '02X90-COMP.SUSP. -GEN. LEDGER(CR)' FROM dual UNION ALL SELECT 'MSAMARIA LOANS OVER 1 M / P/ARREARS' FROM dual UNION ALL SELECT 'EX STAFF / DIRECTORS LN -HOUSE (P/ARR)' FROM dual ) select regexp_substr(data,'[^-]+',1,2) from t And this gives me O/P MICRO ENTERPRISES ( P/ARR) SOROS ECONOMIC DEV. FUND LN COMP.SUSP. HOUSE (P/ARR)
And my results should be
MICRO (P/ARR)
LN OF FUND SOROS ECONOMIC DEV.
COMP. SUSP. -GEN LEDGER (CR)
MSAMARIA LOANS TO MORE THAN 1 M/P/ARREARS
EX STAFF / ADMINISTRATION LN-ASSEMBLY (P/ARR)
MSAMARIA LOANS TO MORE THAN 1 M/P/ARREARS
The problem is with 3,4, 5th line.
Could you please tell me how to write a good RE?
SID.
WITH t (DATA) AS
(
SELECT "01667-MICRO BUSINESSES (P/ARR)" dual UNION ALL "
SELECT '02E60-SOROS ECONOMIC DEV. FUND LN"double UNION ALL
SELECT ' 02 X 90-COMP. SUSP. -GEN LEDGER (CR)' FROM dual UNION ALL
SELECT ' MSAMARIA LOANS MORE than 1 M/P/ARREARS double UNION ALL
SELECT ' EX STAFF / ADMINISTRATION LN-ASSEMBLY (P/ARR)' FROM dual
)
SELECT REGEXP_REPLACE(data,'^[[:alnum:]]+-') IN t;
OUTPUT:
MICRO (P/ARR)
LN OF FUND SOROS ECONOMIC DEV.
COMP. SUSP. -GEN LEDGER (CR)
MSAMARIA LOANS TO MORE THAN 1 M/P/ARREARS
EX STAFF / ADMINISTRATION LN-ASSEMBLY (P/ARR)
Tags: Database
Similar Questions
-
How to get the output below using regexp_substr
with t as( select 'APP_CONTACT_INFO' s from dual union select 'APP_CONTACT' from dual union select 'APP_CONTACT_TYPE_100200' from dual ) select s, REGEXP_SUBSTR( S,'_[A-Z]{3}',1) from t; CON CONINF CONTYP100
How to repeat _ [A - Z] {3} for each underscore match and concatenate it
Select regexp_replace ('myTWst', '. *([A-Z]+). *', '\1') twice;
only gives you a result of 'W' because the '. '. ' * ' in the expression is "greedy". This means that it will match both the string he can before the rest of the evaluation of the model.
So the first '. '. "*" matches "myT", then the "([A-Z] +)" ends up with only the W to match against and the final "." "*" corresponds to the "m".
If instead you did:
SQL > select regexp_replace ('myTWst', '. *?) () [A-Z] +). (* $', '\1') twice;
RE
--
TWthe '? 'after the first'. '. "*" he is not greedy, so it takes what is necessary to allow the rest of the pattern to match, wherever it is just 'my' instead of 'myT '.
the "$" at the end indicates the last '. '. "*" to match all characters up to the end of the string, but even if it is greedy in itself, it is preceded by the "([A-Z] +) ' which itself is greedy and capitals as far as possible."
If in fact told us the "([A-Z] +)" for do not be greedy by putting a "?" after the "+" then it takes as much as necessary to then leave the rest of the pattern (in our case the greedy"." (' $* ') to match as much as possible.
SQL > select regexp_replace ('myTWst', '. *?) () [A-Z] + ?). (* $', '\1') twice;
R
-
TSo, now the '. '. "* $" is being greedy and account as much as possible while leaving enough for non greedy "([A-Z] +?)" for a match, which is just 1 uppercase letter. " As you can see, the result is just the first letter capitalized.
-
Hello
I have data in the following format
select 'A;1;B;2;C;3;D;4;E;5' from dual union all select 'U;11;V;12;W;13;X;14;' from dual
I need the output voltage:
Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 A 1 B 2 C 3 D 4 E 5 U 11 V 12 W 13 X 14 Can you please help?
Thank you
Vikram R
You will need an id column (or a generated) to determine which line is which once cut the columns upwards.
data (id, str))
Select 1, '; 1; B; 2; D, C; 3; 4; E; 5' of the double
Union of all the
Select 2, ' U; 11; V; 12; W; 13; X; 14;' of the double
),
splitdata like)
SELECT id,
trunc ((level-1) / 6) layer.
regexp_substr (str, ' ([^;] *) (; | $) ', 1, level, 'i', 1) divide.
MOD (level 1, 6) + 1 hdr
data t
connect by level<= regexp_count(str,="" ';')="" +="" 1="">=>
prior t.ID = t.id and
prior sys_guid() is not null - is unique, so make sure the Oracle will not execute a loop on the same path
)
Select HEADER1-tete2, HEADER3, HEADER4, HEADER5, HEADER6
of splitdata
pivot)
min (Split)
for hdr (1 as "HEADER1", 2 as "In-tete2", 3 as "HEADER3", 4 as 'HEADER4', 5 'HEADER5", 6 as 'HEADER6')
)
Commander order by id, layer
HEADER1 HEADER2 HEADER3 HEADER4 HEADER5 HEADER6 A 1 B 2 C 3 D 4 E 5 - - U 11 V 12 W 13 X 14 - - - - 4 selected lines.
-
How to remove the REGEXP_SUBSTR space
Choose the length (TRIM (REGEXP_SUBSTR ('V, 370498, 658561477, 20150917, 4.37
(((' [^,] +' 1, 5))) of the double
output
---
9
Select TRIM (REGEXP_SUBSTR ('V, 370498, 658561477, 20150917, 4.37
((' [^,] +' 1, 5)) of the double
output
-----
20150917
last value actual length 8 only
can help me please for these
Thank you
Thanks for the help
to replace suggested used
fix
Choose the length (regexp_substr (regexp_replace ('V, 370498, 658561477, 20150917, 4.37
(' [[: space:]] *', ")," [^,] (+' 1, 5)) solution, "
length (rtrim (regexp_substr ('V, 370498, 658561477, 20150917, 4.37
', '[^,]+', 1, 5)
10) has contributed to
Double;
Hi odie_63
I replied to your previous one (csv to xml using ult_file pl/sql conversion ), it is also very good
Thank you...
-
How to deal with NULL values in regexp_substr?
DECLARE TYPE t_rec IS TABLE OF VARCHAR2(200); /* case 1 */ l_input varchar2(100) := '28/09/2009 00:00:00|AFRISB|FC|773|7|17|512|76|60|U|'; /* case 2 */ -- l_input VARCHAR2(100) := '06/10/2009 00:00:00|PDIERR|PS|999|0|1|0|0||U|'; l_bars PLS_INTEGER; l_fields PLS_INTEGER; l_rec t_rec := t_rec(); BEGIN l_bars := regexp_count(l_input, '\|', 1, 'i'); l_fields := l_bars + 1; FOR fld IN 1 .. l_fields LOOP l_rec.EXTEND(); l_rec(fld) := REGEXP_SUBSTR(l_input, '[^|]+', 1, fld); dbms_output.put_line('Fld ' || fld || ': ' || l_rec(fld)); END LOOP; END;
The above code is that I break a string of pipe delimited into individual elements.
Looking at the case 1 in the code, the output displays each field correctly. However in case 2, the 9th field is null (nothing between the two tubes) so the regexp_substr 19 online is assigning the 'U' in the box 10 as a field 9.
What should I do to get the line 19 to correctly assign a NULL value to field 9?
Information about the version of the database are:
BANNER --------------------------------------------------------------------------------
12 c Oracle database Release 12.1.0.1.0 - 64 bit Production PL/SQL Release 12.1.0.1.0 - Production CORE Production 12.1.0.1.0 AMT for 64-bit Windows: Version 12.1.0.1.0 - Production NLSRTL Version 12.1.0.1.0 - Production
Thank you
Steve
Hello
If you want to use regexes, so instead of
REGEXP_SUBSTR (l_input, "[^ |]") +', 1, fld);
use
REGEXP_SUBSTR (l_input
, '([^|] *)(\|| $)'
-P
fld
NULL
-P
);
. The 6th argument to REGEXP_SUBSTR is a new feature of Oracle 11.1. It's kind of a back reference. Normally, REGEXP_SUBSTR returns the substring that matches the pattern in the 2nd argument. If the 6th argument is 1, however, REGEXP_SUBSTR returns only the part of the pattern between the 1st on the left '(' et sa correspondance)."
-
REGEXP_SUBSTR I need any word val, including space, or null
Hi all
I need to separate the last value in the field, but my query spaces not considered between the delimiters, please help thanks...
SELECT RTRIM (REGEXP_SUBSTR ('C | 00013010101 |)) C00009 | 009402 | 00000100.000 | 1. AZUSDINE 500 MG TABLET | AZULFIDINE | 00016010101 | 1. 19950118 | 20150330 | 00000000 | 00000000 | 0 | F | 9. 1. 1. 0 | 1. 1. AB | 00000000 | 1. 0 | 000 | 0 | 0000001 | 00,000 | 00,000 | 00,000 | 0000012 | 0000012 | AB | TAB | 00000001.000 | 19900930 | 19900930 | 00000000 | 1. 19950701 | 2. 0 | BOTTLE | 0 | 20080925 | 20110928 | 0 | 0 | 0 | AB | 00000100.000 | 0 | 00 | AB | 2. 2. 9. 3. 1. I have | AZULFIDINE 500 MG TABLET '
(' [a-zA-Z0-9] +--------|?', 1, 72),' | ') Double val
output
VAL
-----
AZULFIDINE
Mandatory
PUT out, VAL: AZULFIDINE 500 MG TABLET
Thank you
Olivier
If the number of fields is fixed, if you always want (in this case) the 69th field, you could do that (I replaced your channel hardcoded with a column called "input_string" for clarity):
SELECT RTRIM (REGEXP_SUBSTR (input_string |'|)) ',' [^ \ |] *\|',1,69),'|') Val from your_table
If you want just the entire last section, you can do it without using regular expressions at all:
SELECT SUBSTR (input_string, INSTR(input_string,'|',-1) + 1) val from your_table
-
REGEXP_SUBSTR simple query
Hi all
Select RTRIM (REGEXP_SUBSTR('675809532|11787148|0','[a-zA-Z0-9]+\|'),'| ') double cardid
Output
--------
675809532
form above query I had the first value 675809532 how can I second valueor third value only pls help for these
I need to pass the value to the variable individally
Thank you...
By adding the occurece to the RegExp as:
Select RTRIM (REGEXP_SUBSTR ("675809532 |")) 11787148 | 0','[a-zA-Z0-9] + \| ?', 1,2),'| ') the double cardid
and the regular expression would be easier that way:
Select REGEXP_SUBSTR ('675809532 | 11787148 | 0', ' [^ \ |] +' 1, 3) double cardid
HTH
-
Hello
I need to extract the first five characters digital of the specified column. I'm able to reach the requirement using substr and definition of functions.
I learned that the use of regular expressions we can achieve in a simple way. Please find below the test data.
with t as (select '123456suri' double empid
Union all select 'suri436789' of the double
Union all select '521521suri' of the double
Union select all 'suri785643abc' of the double)
select * from t ;
Desired output:
EmpID
---------
12345
52152
Please help me how to extract the results required using REGEXP_SUBSTR.
I tried with query below, but not able to restrict the result to only five digits.
Select double regexp_substr('3456789suri123','[0-9]+',1,1)
Thank you
Suri ;-)
Post edited by: Suri - added query
Good first try
\d is a shortcut for [0-9]
What happens when you try to \d\d?
How about \d\d\d?
You should be able to guess the rest of there
You can also use {n} means "repeat exactly n times.
-
Questioning REGEXP_SUBSTR, regular expressions
With the expression below, I expect to come back the first 4 words and do not understand why it is not doing.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+){3,4}') from dual; REGE ---- This
This works as expected.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+ ){3,4}') from dual; REGEXP_SUBSTR('TH ----------------- This is a sample
Hello
Solomon Yakobson says:
Frank Kulash wrote:
If you are looking for 3 or 4 instances of 1 or more letters, without anything in addition to the letters between them. Any group of 3 or more consecutive letters matches. For example,.
- "Th" as the 1st appearance of 1 or more letters,
- 'i' as the 2nd appearance of 1 or more letters, and
- of ' as the 3rd appearance of 1 or more letters
is a substring that matches the pattern you described.
In fact T is the 1st appearance of 1 or several letters, h is the second, I ranked third and s are defined. Otherwise:
SQL > select regexp_substr ('the following is an example of text string', ' ([[: alpha:]] +) {3,4}') of the double
2.REG
---
TheSQL >
returns no rows.
Not that it is important for the OP's question, but I think the way I presented it is more precise.
How can tell us if 'This' match of the 4 occurrences (all 1 character) or 3 occurrences (1 with 2 characters and 2 with 1 character each)?
In more general terms, when we say something like
(expr +) {x, y}
is '+' more greedy than "{x, y}.
It seems to me that '+' is dishonest in this case. Consider this query:
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]] {1,2})([[:alpha:]]+) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
which produces this output:
STR MATCHES
------------------------------------- ------------------------------
This is an example of text string Th = 1; i = 2; s = 3; = 4 is a samp = 1; l =
2; e = 3; 4 = = you 1; x = 2; t = 3; = 4 = stri
1; n = 2; g = 3; = 4
The following is an example of text string T = 1; h = 2; e = 3; = 4 followi = 1; n = 2; g
= 3 ; = 4 is a samp = 1; l = 2; e = 3; = 4 t
e = 1; x = 2; t = 3; = stri 4 = 1; n = 2; g = 3;
= 4
Fubar Fub = 1; a = 2; r = 3; = 4
cat c=1;a=2;t=3;=4
In this case, '+' appears to be labels as "{3.4}.
I don't have not seen this documented anywhere, but it seems it's because + gets to go first in the model. In other words, there is nothing to inherently rapacity on ' + '. If we change the first '+' above "{1,9}", like this
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]]{1,9}) ([[: alpha:]] +) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
the result remains the same.
Of course, is using the first query I posted above
(expr) (expr) (expr) (expr)?
It is possible that
(expr) {3,4}
which is what OP posted, is handled differently.
-
Hi all
Please find test data and results as XML and SQL output.
Version : Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
create table emp_xml (empno number, emp_name varchar2 (100), by e-mail to varchar2 (100));
insert into emp_xml values (100, 'DAVID',' [email protected]');
insert into emp_xml values (101, 'ROBERT',' [email protected]');
insert into emp_xml values (102, 'DANIEL',' [email protected]');
CREATE table emp_dept_xml (empno number, dept_list varchar2 (4000));
insert into emp_dept_xml values (' 100,'10, 20, 30, ");
insert into emp_dept_xml values (' 101,'40, 20, 10, 30, 50, ");
insert into emp_dept_xml values (102, ' 10'),
Expected in SQL output
-----------------------
EMPNO EMP_NAME EMAIL DEPTNO
DAVID 100 [email protected] 10
DAVID 100 [email protected] 20
DAVID 100 [email protected] 30
ROBERT 101 [email protected] 10
ROBERT 101 [email protected] 20
ROBERT 101 [email protected] 30
ROBERT 101 [email protected] 40
ROBERT 101 [email protected] 50
DANIEL 102 [email protected] 10
Results in XML
-----------------------
< USERS_DETAILS >
< USER >
< EMPNO > 100 < / EMPNO >
DAVID < NAME > < / NAME >
< EMAIL > [email protected] < / EMAIL >
< ASSIGNED_DEPT >
< DEPT > 10 < / DEPT >
< DEPT > 20 < / DEPT >
< DEPT > 30 < / DEPT >
< / ASSIGNED_DEPT >
< / USER >
< USER >
101/EMPNO < EMPNO > >
ROBERT < NAME > < / NAME >
< EMAIL > [email protected] < / EMAIL >
< ASSIGNED_DEPT >
< DEPT > 10 < / DEPT >
< DEPT > 20 < / DEPT >
< DEPT > 30 < / DEPT >
< DEPT > 40 < / DEPT >
< DEPT > 50 < / DEPT >
< / ASSIGNED_DEPT >
< / USER >
< USER >
< > 102 EMPNO < / EMPNO >
DANIEL < NAME > < / NAME >
< EMAIL > [email protected] < / EMAIL >
< ASSIGNED_DEPT >
< DEPT > 10 < / DEPT >
< / ASSIGNED_DEPT >
< / USER >
< / USERS_DETAILS >
Thank you
Rambeau
SQL> select e.empno 2 , e.emp_name 3 , e.email 4 , regexp_substr(d.dept_list, '[^,]+', 1, level) deptno 5 from emp_xml e 6 join emp_dept_xml d 7 on e.empno = d.empno 8 connect 9 by level <= length(d.dept_list) - length(replace(dept_list, ',')) 10 and prior e.empno = e.empno 11 and prior dbms_random.value() is not null; EMPNO EMP_NAME EMAIL DEPTNO ---------- -------------------- -------------------- -------------------- 100 DAVID [email protected] 10 100 DAVID [email protected] 20 100 DAVID [email protected] 30 101 ROBERT [email protected] 40 101 ROBERT [email protected] 20 101 ROBERT [email protected] 10 101 ROBERT [email protected] 30 101 ROBERT [email protected] 50 102 DANIEL [email protected] 10 9 rows selected. SQL> select xmlelement 2 ( 3 "USERS_DETAILS" 4 , xmlagg(xmlelement 5 ( 6 "USER" 7 , xmlelement("EMPNO", empno) 8 , xmlelement("NAME", emp_name) 9 , xmlelement("ASSIGNED_DEPT", xmlagg(xmlelement("DEPT", deptno))) 10 )) 11 ).extract('*') xml_output 12 from ( 13 select e.empno 14 , e.emp_name 15 , e.email 16 , regexp_substr(d.dept_list, '[^,]+', 1, level) deptno 17 from emp_xml e 18 join emp_dept_xml d 19 on e.empno = d.empno 20 connect 21 by level <= length(d.dept_list) - length(replace(dept_list, ',')) 22 and prior e.empno = e.empno 23 and prior dbms_random.value() is not null 24 ) 25 group 26 by empno 27 , emp_name; XML_OUTPUT --------------------------------------------------------------------------------
100 DAVID 10 20 30 101 ROBERT 40 50 30 20 10 102 DANIEL 10 -
regexp_substr within pl/sql
Table:
REFERRING_PAGE SEARCH_TERM ESTENCHERES.FR 4RUNER; HIGHLANDER; COROLLA; CAMRY; HONDA.COM AGREEMENT; CIVIC; PILOT FORD.COM EXPLORER; ESCAPE SUV; MUSTANG; TAURUS Outputs of the screen:
REFERRING_PAGE Search_term WORDS ESTENCHERES.FR 4RUNNER; HIGHLANDER; COROLLA; CAMRY; 4RUNNER; HIGHLANDER; COROLLA; CAMRY;
HONDA AGREEMENT; CIVIC; PILOT AGREEMENT; CIVIC; PILOT FORD.COM EXPLORER; EXPLORER ESCAPE SUV; MUSTANG; TAURUS Dear OTN forum;
How can I build this function RUN IMMEDIATELY REGEXP_SUBSTR in PL/SQL. Thanks in advance.
SET SERVEROUTPUT SIZE 100000;
DECLARE
v_referring_page dealers.referring_page%type;
v_search_term dealers.search_term%type;
MyCursor CURSOR IS
SELECT referring_page
search_term
AT SELECT RETAILERS
WHERE search_term IS NOT NULL
AND TRUNC (log_date) = TO_DATE('30-JAN-14','DD-MON-YY');
iRec myCursor % ROWTYPE;
BEGIN
OPEN myCursor;
LOOP
FETCH myCursor INTO iRec;
OUTPUT WHEN myCursor % NOTFOUND;
DBMS_OUTPUT. Put_line (iRec.referring_page |) » '|| iRec.search_term);
DBMS_OUTPUT. PUT_LINE(' ');
DBMS_OUTPUT. Put_line (EXECUTE IMMEDIATE ' SELECT REGEXP_SUBSTR (iRec.search_term, "[^;]")) + ", 1, level) FROM DUAL
CONNECT BY REGEXP_SUBSTR (iRec.search_term, "[^;]") (+ 1, level) IS NOT NULL ");"
END LOOP;
CLOSE MyCursor;
END;
Hello
2745978 wrote:
Table:
REFERRING_PAGE SEARCH_TERM ESTENCHERES.FR 4RUNER; HIGHLANDER; COROLLA; CAMRY; HONDA.COM AGREEMENT; CIVIC; PILOT FORD.COM EXPLORER; ESCAPE SUV; MUSTANG; TAURUS Outputs of the screen:
REFERRING_PAGE Search_term WORDS ESTENCHERES.FR 4RUNNER; HIGHLANDER; COROLLA; CAMRY; 4RUNNER; HIGHLANDER; COROLLA; CAMRY;
HONDA AGREEMENT; CIVIC; PILOT AGREEMENT; CIVIC; PILOT FORD.COM EXPLORER; EXPLORER ESCAPE SUV; MUSTANG; TAURUS Dear OTN forum;
How can I build this function RUN IMMEDIATELY REGEXP_SUBSTR in PL/SQL. Thanks in advance.
SET SERVEROUTPUT SIZE 100000;
DECLARE
v_referring_page dealers.referring_page%type;
v_search_term dealers.search_term%type;
MyCursor CURSOR IS
SELECT referring_page
search_term
AT SELECT RETAILERS
WHERE search_term IS NOT NULL
AND TRUNC (log_date) = TO_DATE('30-JAN-14','DD-MON-YY');
iRec myCursor % ROWTYPE;
BEGIN
OPEN myCursor;
LOOP
FETCH myCursor INTO iRec;
OUTPUT WHEN myCursor % NOTFOUND;
DBMS_OUTPUT. Put_line (iRec.referring_page |) » '|| iRec.search_term);
DBMS_OUTPUT. PUT_LINE(' ');
DBMS_OUTPUT. Put_line (EXECUTE IMMEDIATE ' SELECT REGEXP_SUBSTR (iRec.search_term, "[^;]")) + ", 1, level) FROM DUAL
CONNECT BY REGEXP_SUBSTR (iRec.search_term, "[^;]") (+ 1, level) IS NOT NULL ");"
END LOOP;
CLOSE MyCursor;
END;
REGEXP_SUBSTR, like almost all other single-row functions, can be invoked directly in PL/SQL; you need not EXECUTE IMMEDIATE or double table.
You can do something like this:
item_cnt: = REGEXP_COUNT (iRec.search_term
, '[^;] +'
);
IF item_cnt > 0
THEN
FOR j IN 1... item_cnt
LOOP
dbms_output.put_line (REGEXP_SUBSTR (iRec.search_term
, '[^;] +'
1
j
)
);
END LOOP;
END IF;
-
Good day to you all:
I have a column in a table that contains the names of files as such:
EXAMPLE1.05232014.BUSINESS.PDF
EXAMPLE2.05182014.SUPPORT.DOCX
EXAMPLE3.02252014.OPERATIONS.GIF
How to use the REGEXP_SUBSTR function to extract the file extension? My desired to above data output would be:
. PDF
. DOCX
. GIF
Please, if there is a way easier to extract file extension share, as I have mucho problemos with REGEXP_SUBSTR command.
SQL DEVELOPER VERSION Version 3.2.20.09 - Oracle 10 g environment
Thank you very much for your help!
I appreciate the expertise here...
Hello
With the help of regular expressions:
REGEXP_SUBSTR (file_name
, '\. [^.] *$'
)
Without them (probably faster):
SUBSTR (file_name
, INSTR (filename, ".", - 1).
)
Want to sure if the filename does not contain any '.'s at all? The above expression REGEXP_SUBSTR returns NULL and the expression of SUBSTR returns the file_name, but either can be replaced.
-
Split the cell enclosed in several lines using REGEXP_SUBSTR - Performance?
Hello
I have a table that has about 20,000 lines. There is a column called key word which has values like below:
File_id Keyword 1 SMITH; ALLEN; WARD; JONES; BRADY 2 S & P500; TOPIX 3 SMALL; LARGE; MEDIUM I want to display the data like this:
File_id KEYWORD 1 SMITH 1 ALLEN 1 WARD 1 BRADY 2 S & P500 2 TOPIX etc. I use this application and it works:
SELECT STG. FILE_ID, REGEXP_SUBSTR (STG. KEYWORD ' [^;] +', 1, LEVEL) AS A KEYWORD OF STG STG_TABLE
CONNECT REGEXP_SUBSTR (STG. KEYWORD ' [^;] +', 1, LEVEL) IS NOT NULL
But its so slow its unusable.
Is there a faster way to return this output?
Other info:
KEY Word is varchar2 (4000), but rarely more than 100 bytes are used
Oracle 11g 2
Thank you!
Wrong approach, there are too many lines that are generated
Apart from replacing regexp with substr/instr, try the first slot
SELECT
STG. FILE_ID
REGEXP_SUBSTR (STG. KEYWORD ' [^;] +', 1, LEVEL) AS KEYWORD
OF STG STG_TABLE
CONNECT
level<= regexp_count(stg.keyword,';')="" +="">=>
and prior STG. FILE_ID = STG. FILE_ID
and prior sys_guid() is not null
-
Problem with REGEXP_SUBSTR related query.
I'm having a problem with this query:
SELECT *.
FROM (SELECT REGEXP_SUBSTR ('{SUMMER} |)) {} POINT OF SALE}',
'({)([A-Z]+ *[A-Z]*)(})',
1,
LEVEL,
'I,
2)
Val
OF THE DOUBLE
CONNECT BY LEVEL < =.
REGEXP_COUNT ('{SUMMER} |) {} POINT OF SALE} ',' |') + 1)
WHERE val IS NOT NULL
I need the output in 2 rows in this format:
VAL
====
SUMMER
POINT OF SALE
But I'm not able to get the "POINT OF SALE" in the output due to space, or perhaps another reason. Anyone can correct my query?
So, you want something like that?
SQL > ed
A written file afiedt.buf1. SELECT *.
2 (SELECT REGEXP_SUBSTR ('{SUMMER} |)) {} POS} ',' [^ {|}] + ", LEVEL, 1, 'i') val"
3 FROM TWO
4. CONNECT BY LEVEL<>
5 REGEXP_COUNT ('{SUMMER} |) {} POINT OF SALE} ',' [^ |] +'))
6 * val WHERE IS NOT NULL
SQL > /.VAL
------------------------
SUMMER
POINT OF SALESQL >
-
SQL: REGEXP_SUBSTR CSV with string delimiter
Hello
I would like to create a function to split a CSV file with string using REGEXP delimiter.
Because the REGEXP function does not deal with NULL values, in the first place, I use a REGEXP_REPLACE:
SELECT REGEXP_REPLACE (' ' ' ';) "2011-12-30 15:33:15 '; "" 116 "; » « ; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; (""', '("") + ',' 'NULL' ') FROM dual;
Result:
'NULL '; "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; "' NULL '.
If I can deal with the empty columns.
Then I apply this REGEXP:
SELECT REGEXP_SUBSTR (' 'NULL';) "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; ("' NULL ' ',' [^(";")] +', 1, level)-LOOSE COLLECTION ltab_SplittedTelList OF the double CONNECT REGEXP_SUBSTR (' 'NULL';) "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; » NULL » ', ' [^ « ; »] +', 1, level) IS NOT NULL; Result:
NULL VALUE
2011-12-30 15:33:15
116
NULL VALUE
1
REPLIED
SIP/SDX20016-b6ec9c10
NULL VALUE
Very good, but if I put a delimiter column ';' in the middle of a string, for example in the middle of the date, I had my date cut in two.
I can't find the correct model for my REGEXP.
Jump, it is possible to do it with REGEXP.
Thanks in advance,
Greg.
Hi, Greg.
Here's a way to do it in pure SQL:
WITH got_str AS
(
SELECT "' ';'" 2011 12-30; 15:33:15 '; 116. " » « ; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; ' ' ' ' ' AS str
OF the double
)
SELECT THE LEVEL
, REGEXP_SUBSTR (' ";' |") Str | ';"'
, '";" ((([^"]*"[^;]) *[^"])*)'
1
LEVEL
NULL
1
) AS sub_str
OF got_str
CONNECT BY LEVEL<= 1="" +="" regexp_count="" (="">=>
, '";"'
)
;
Note that I added one; after 2011-12-30.
Output:
LEVEL SUB_STR
---------- -------------------------
1
2 on 12-30-2011; 15:33:15
3 116
4
5 1
6 ANSWERED
7 SIP/SDX20016-b6ec9c10
8
As always, the solution depends on your version. It works in Oracle 11.2.
Your message, it seems that you do this in PL/SQL. The above query will work in PL/SQL, of course, but it might be simpler to use the code of procedure. Parse the string from left to right, followed the quotation marks and semicolons. If you find a semicolon, and the total number of quotes spent so far is the same, then you have found the beginning of a new secondary channel.
Maybe you are looking for
-
Some details on caching in firefox
Basically, I want to have all the cache in RAM instead of my SSD.[I have disabled "disk cache", do I have to disable 'hide offline' too?]1 setting browser.cache.memory.capacity - 1, I noticed that he was staring at 32768 KB. Would it automatically in
-
DV 6 1050us: trackpad doesn't work
Hey,. so I updated my bios driver (downloaded from the hp Web site) and since then the built-in trackpad not working... an external mouse works fine... I'm afraid of what a USB mouse is connected in the update of the bios... can anyone think of a sol
-
HDX 16 t-1200 CTO Premium: change of DigitalPersona to single pass
I have a laptop PC HDX16T - 1200 CTO Premium, product number: nk135av under Windows 7 Ultimate which came loaded with digitalPersona. I am running the latest version (4.11.3826). With all the improvements of Windows and IE, sometimes it works good
-
Cannot install itunes 64-bit on 64-bit edition Windows 7 Home premium.
I can't install itunes 64-bit on 64-bit edition Windows 7 Home premium. Have tried all of the fixes recommended without success (including the latest version of the itunes 64-bit Installer Is the installation of windows 64-bit only a question problem
-
Hi, I'm totally new to BB dev. I'll make an application in the kit of native development. I was hoping to use .net, but I don't know where to start here. I'm new to C++, but having 18 years of web development, VB, VBA VB.net, Java and Java. I pick up