REGEXP_SUBSTR and OR !!!
Hi Al,
i would like to know how can i used the OR "|" with REGEXP_SUBSTR
SELECT REGEXP_SUBSTR('500.90 Oracle Parkway, 12-12-2000 78 Redwood Shores, CA','([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})') "REGEXPR_SUBSTR" FROM DUAL;this two condition
([0-9]{1,2}) ([0-9]{1,2}) ([0-9]{4})
or this i did it like this
SELECT REGEXP_SUBSTR('500.90 Oracle Parkway, 12-12-2000 78 Redwood Shores, CA','([0-9]{1,2}) ([0-9]{1,2}) ([0-9]{4} | ([0-9]{1,2}) (JANUARY|FEBRUARY|MARCH|APRIL|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER))') "REGEXPR_SUBSTR" FROM DUAL;
but not correct regards
Edited by: Ayham on Jan 10, 2013 2:33 AM
Edited by: Ayham on Jan 10, 2013 2:34 AM
Ayham wrote:
WHY THIS IS NOT WORKING....
with t as (select '500.90 Oracle Parkway, 12-12-2000 78 Redwood Shores, CA' as txt from dual union all
select '500.90 Oracle Parkway, 12 December 2000 78 Redwood Shores, CA' from dual union all
select '500.90 Oracle Parkway, February 2008 78 Redwood Shores, CA' from dual union all
select '500.90 Oracle Parkway, 2 February 78 Redwood Shores, CA' from dual union all
select '500.90 Oracle Parkway, 3 05 2010 78 Redwood Shores, CA' from dual
select regexp_substr(txt,'([0-9]{1,2}[ -])?([0-9]{1,2}|January|February|March|April|May|June|July|August|September|October|December)([ -][0-9]{4})?') result
from t;the output
50
50
50
50i already put just "?" in case of the years not thereIt's because of your "?" after the years. In that case the day of the month is optional (as it has a "?") and the year is optional (as you added a "?") so the only bit that needs to match is the middle part which is looking for 2 numeric digits or the month names. The start of each string has two numeric digits 50 so that's the first match it finds and that's what you're getting.
Similar Messages
-
[Mostly Sorted] Extracting tags - regexp_substr and count help needed!
My original query got sorted, but additional regexp_substr and count help is required further on down!
Hi,
I have a table on a 10.2.0.3 database which contains a clob field (sql_stmt), with contents that look something like:
SELECT <COB_DATE>, col2, .... coln
FROM tab1, tab2, ...., tabn
WHERE tab1.run_id = <RUNID>
AND tab2.other_col = '<OTHER TAG>'(That's a highly simplified sql_stmt example, of course - if they were all that small we'd not be needing a clob field!).
I wanted to extract all the tags from the sql_stmt field for a given row, so I can get my (well not "mine" - I'd never have designed something like this, but hey, it works, sorta, and I'm improving it as and where I can!) pl/sql to replace the tags with the correct values. A tag is anything that's in triangular brackets (eg. <RUNID> from the above example)
So, I did this:
SELECT SUBSTR (sql_stmt,
INSTR (sql_stmt, '<', 1, LEVEL),
INSTR (substr(sql_stmt, INSTR (sql_stmt, '<', 1, LEVEL)), '>', 1, 1)
) tag
FROM export_jobs
WHERE exp_id = p_exp_id
CONNECT BY LEVEL <= (LENGTH (sql_stmt) - LENGTH (REPLACE (sql_stmt, '<')))Which I thought would be fine (having tested it on a text column). However, it runs very poorly against a clob column, for some reason (probably doesn't like the substr, instr, etc on the clob, at a guess) - the waits show "direct path read".
When I cast the sql_stmt as a varchar2 like so:
with my_tab as (select cast(substr(sql_stmt, instr(sql_stmt, '<', 1), instr(sql_stmt, '>', -1) - instr(sql_stmt, '<', 1) + 1) as varchar2(4000)) sql_stmt
from export_jobs
WHERE exp_id = p_exp_id)
SELECT SUBSTR (sql_stmt,
INSTR (sql_stmt, '<', 1, LEVEL),
INSTR (substr(sql_stmt, INSTR (sql_stmt, '<', 1, LEVEL)), '>', 1, 1)
) tag
FROM my_tab
CONNECT BY LEVEL <= (LENGTH (sql_stmt) - LENGTH (REPLACE (sql_stmt, '<')))it runs blisteringly fast in comparison, except when the substr'd sql_stmt is over 4000 chars, of course! Using dbms_lob instr and substr etc doesn't help either.
So, I thought maybe I could find an xml related method, and from this link:get xml node name in loop , I tried:
select t.column_value.getrootelement() node
from (select sql_stmt xml from export_jobs where exp_id = 28) xml,
table (xmlsequence(xml.xml.extract('//*'))) tBut I get this error: ORA-22806: not an object or REF. (It might not be the way to go after all, as it's not proper xml, being as there are no corresponding close tags, but I was trying to think outside the box. I've not needed to use xml stuff before, so I'm a bit clueless about it, really!)
I tried casting sql_stmt into an xmltype, but I got: ORA-22907: invalid CAST to a type that is not a nested table or VARRAY
Is anyone able to suggest a better method of trying to extract my tags from the clob column, please?
Message was edited by:
BoneistI don't know if it may work for you, but I had a similar activity where I defined sql statements with bind variables (:var_name) and then I simply looked for witch variables to bind in that statement through this query.
with x as (
select ':var1
/*a block comment
:varname_dontcatch
select hello, --line comment :var_no
''a string with double quote '''' and a :variable '', --:variable
:var3,
:var2, '':var1'''':varno'',
from dual' as string
from dual
), fil as (
select string,
regexp_replace(string,'(/\*[^*]*\*/)'||'|'||'(--.*)'||'|'||'(''([^'']|(''''))*'')',null) as res
from x
select string,res,
regexp_substr(res,'\:[[:alpha:]]([[:alnum:]]|_)*',1,level)
from fil
connect by regexp_instr(res,'\:[[:alpha:]]([[:alnum:]]|_)*',1,level) > 0
/Or through these procedures
function get_binds(
inp_string in varchar2
) return string_table
deterministic
is
loc_str varchar2(32767);
loc_idx number;
out_tab string_table;
begin
--dbms_output.put_line('cond = '||inp_string);
loc_str := regexp_replace(inp_string,'(/\*[^*]*\*/)'||'|'||'(--.*)'||'|'||'(''([^'']|(''''))*'')',null);
loc_idx := 0;
out_tab := string_table();
--dbms_output.put_line('fcond ='||loc_str);
loop
loc_idx := regexp_instr(loc_str,'\:[[:alpha:]]([[:alnum:]]|_)*',loc_idx+1);
exit when loc_idx = 0;
out_tab.extend;
out_tab(out_tab.last) := regexp_substr(loc_str,'[[:alpha:]]([[:alnum:]]|_)*',loc_idx+1);
end loop;
return out_tab;
end;
function divide_string (
inp_string in varchar2
--,inp_length in number
--return string_table
return dbms_sql.varchar2a
is
inp_length number := 256;
loc_ind_1 pls_integer;
loc_ind_2 pls_integer;
loc_string_length pls_integer;
loc_curr_string varchar2(32767);
--out_tab string_table;
out_tab dbms_sql.varchar2a;
begin
--out_tab := dbms_sql.varchar2a();
loc_ind_1 := 1;
loc_ind_2 := 1;
loc_string_length := length(inp_string);
while ( loc_ind_2 < loc_string_length ) loop
--out_tab.extend;
loc_curr_string := substr(inp_string,loc_ind_2,inp_length);
dbms_output.put(loc_curr_string);
out_tab(loc_ind_1) := loc_curr_string;
loc_ind_1 := loc_ind_1 + 1;
loc_ind_2 := loc_ind_2 + length(loc_curr_string);
end loop;
dbms_output.put_line('');
return out_tab;
end;
function execute_statement(
inp_statement in varchar2,
inp_binds in string_table,
inp_parameters in parametri
return number
is
loc_stat dbms_sql.varchar2a;
loc_dyn_cur number;
out_rows number;
begin
loc_stat := divide_string(inp_statement);
loc_dyn_cur := dbms_sql.open_cursor;
dbms_sql.parse(c => loc_dyn_cur,
statement => loc_stat,
lb => loc_stat.first,
ub => loc_stat.last,
lfflg => false,
language_flag => dbms_sql.native
for i in inp_binds.first .. inp_binds.last loop
DBMS_SQL.BIND_VARIABLE(loc_dyn_cur, inp_binds(i), inp_parameters(inp_binds(i)));
dbms_output.put_line(':'||inp_binds(i)||'='||inp_parameters(inp_binds(i)));
end loop;
dbms_output.put_line('');
--out_rows := DBMS_SQL.EXECUTE(loc_dyn_cur);
DBMS_SQL.CLOSE_CURSOR(loc_dyn_cur);
return out_rows;
end;Bye Alessandro
Message was edited by:
Alessandro Rossi
There is something missing in the functions but if there is something that may interest you you can ask. -
Problem with REGEXP_SUBSTR and the desired results
I have table like below:
USERNAME
DOCNAME
DESCRIPTION
user1
doc1
yes|no|none
user1
doc2
ok|not
user1
doc3
allryt
Now I want to display the table like below:
USERNAME
DOCNAME
DESCRIPTION
user1
doc1
yes
user1
doc1
no
user1
doc1
none
user1
doc2
ok
user1
doc2
not
user1
doc3
allryt
Now this is the query which I am executing to separate the rows:
SELECT a.*, REGEXP_SUBSTR (description, '[^|]+', 1, LEVEL, 'i') val
FROM (SELECT * FROM sample_table WHERE username='user1') a
CONNECT BY LEVEL <=
REGEXP_COUNT (description, '[^|]+')
But I am getting results like below (rows getting duplicated)
user1
doc1
yes|no|none
yes
user1
doc1
yes|no|none
no
user1
doc1
yes|no|none
none
user1
doc2
ok|not
not
user1
doc1
yes|no|none
none
user1
doc2
ok|not
ok
user1
doc1
yes|no|none
no
user1
doc1
yes|no|none
none
user1
doc2
ok|not
not
user1
doc1
yes|no|none
none
user1
doc3
allryt
allryt
user1
doc1
yes|no|none
no
user1
doc1
yes|no|none
none
user1
doc2
ok|not
not
user1
doc1
yes|no|none
none
Can anyone correct my query or modify it?Try this
SQL> with t
2 as
3 (
4 select 'user1' user_name, 'doc1' doc_name, 'yes|no|none' descr from dual union all
5 select 'User1' user_name, 'doc2' doc_name, 'ok|not' descr from dual union all
6 select 'user1' user_name, 'doc3' doc_name, 'allryt' descr from dual
7 )
8 select user_name
9 , doc_name
10 , regexp_substr(descr, '[^\|]+', 1, level) descr
11 from t
12 connect by level <= length(descr) - length(replace(descr, '|')) + 1
13 and descr = prior descr
14 and prior sys_guid() is not null
15 order
16 by user_name
17 , doc_name
18 , level;
USER_ DOC_ DESCR
User1 doc2 ok
User1 doc2 not
user1 doc1 yes
user1 doc1 no
user1 doc1 none
user1 doc3 allryt
6 rows selected. -
Regexp_substr and select all
HI
I have this doubt, I have a query like this:
SELECT *
FROM table
WHERE DIVISION IN (
SELECT REGEXP_SUBSTR( DIVISIONS ,'[^,]+', 1, LEVEL) FROM DUAL
CONNECT BY REGEXP_SUBSTR( DIVISIONS , '[^,]+', 1, LEVEL) IS NOT NULL )
It works fine when DIVISIONS its like "3,4,5,6"
but i want, that when DIVISION its empty ( "" ) it does not filter,
Can you help me find how can i do this?
thanksHow about:
SQL> var divisions varchar2(100)
SQL> exec :divisions := '3,2,6,7,8,6,34'
PL/SQL procedure successfully completed.
SQL> -- generating sample data:
SQL> with t as (
2 select 1 div from dual union
3 select 2 div from dual union
4 select 3 div from dual union
5 select 4 div from dual union
6 select 5 div from dual union
7 select 6 div from dual
8 )
9 --
10 -- actual query
11 --
12 select *
13 from t
14 where
15 case
16 when :divisions is null then 1
17 when :divisions is not null
18 and div in ( select regexp_substr(:divisions ,'[^,]+', 1, level)
19 from dual
20 connect by regexp_substr(:divisions , '[^,]+', 1, level) is not null
21 ) then 1
22 end = 1;
DIV
2
3
6
3 rows selected.
SQL> exec :divisions := '';
PL/SQL procedure successfully completed.
SQL> -- generating sample data:
SQL> with t as (
2 select 1 div from dual union
3 select 2 div from dual union
4 select 3 div from dual union
5 select 4 div from dual union
6 select 5 div from dual union
7 select 6 div from dual
8 )
9 --
10 -- actual query
11 --
12 select *
13 from t
14 where
15 case
16 when :divisions is null then 1
17 when :divisions is not null
18 and div in ( select regexp_substr(:divisions ,'[^,]+', 1, level)
19 from dual
20 connect by regexp_substr(:divisions , '[^,]+', 1, level) is not null
21 ) then 1
22 end = 1;
DIV
1
2
3
4
5
6
6 rows selected. -
Regexp_substr and connect by level.
Hi
I have a a below query and out put also given below
Query:
select distinct cont_id,ct.TAG245 from contact_tag ct where ct.CONT_ID='AEGA-3R43UM'
OUTPUT
Cont_id TAG245
AEGA-3R43UM 060|02.00|060|02.00|060|02.00|060|02.00
In the above output for TAG245 we have two values first value is percentage and second value is frequency.
I need to make all frequency values sum.(ie 02.00+02.00+02.00+02.00)
Expected output
Plannedcall
6
Step 1
First I am approaching the above output dividing the each pipe symbols into each row using the below query but it is not working it is taking long time.Can you advice me on this so that i can goto next step:2.
The query
SELECT regexp_substr (ct.TAG245, '[|,]+', 1, level) frequency
FROM contact_tag ct
--where ct.CONT_ID='AEGA-3R43UM'
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (ct.TAG245, '[|,]+')) + 1
order by 1;
Step: 2
Once i get the output I will sum the even rows because all evenrows has frequency values.
Thanks876639 wrote:
Hi Blu Shadow
When I Run the below query
SELECT level as lvl, regexp_substr (ct.TAG245, '[^|]+', 1, level) frequency
FROM contact_tag ct
WHERE cont_id = 'AEGA-3R43UM'
CONNECT BY regexp_substr(ct.TAG245, '[^|]+', 1, level) is not null
it is taking long time, because you have used the with clause, here i am getting the values directly from Table Contact _tag,
could you telll me? why it is like that.Do you have an index on cont_id or is it the primary key?
How much data is in the table?
We can't tell you why it's going slow unless you provide us with sufficient information.
See the threads linked to by the following post:
{message:id=9360003} -
In oracle Httpuritype - Not getting the output correctly
Hi, I am trying out httpuritype in oracle for the first time. My requirement is to get the input string and the from_language and to_language and has to be converted accordingly.
I am using oracle 11.2.0.1.
So had setup acl explicitly and started writing the below program.
create or replace procedure trans_new_prc1
(p_words in varchar2, -- words to be translated
p_to in varchar2 , -- language to translate to
p_from in varchar2 ) -- language to translate from
is
l_res varchar2(2000);
l_words varchar2(2000);
txt varchar2(2000);
begin
txt:=utl_url.escape(l_words);
l_words:=regexp_substr(httpuritype('http://translate.google.co.in/?hl=en&tab=wT#'||p_from||'/'||p_to|| txt).getclob(),'"(.*?)"',1,1,null,1);
Dbms_output.put_line( l_words);
end;
While converting from polish language to english language I get the output as
SQL> exec trans_new_prc1('hen','pl','en');
text/html; charset=ISO-8859-2
But i need the exact string in polish language, which i am not getting. Please guide me.
Even while converting it into chinese language, i get the following message
SQL> exec trans_new_prc1('hen','zh-CN','en');
text/html; charset=ISO-8859-2
Please guide me to get the output exactly in chinese language.I think the problem is, google translate is not giving that info with this URL ! I removed REGEXP_SUBSTR and get all html code from HTTPURITYPE, in returned code, there is no translated word info!
for the code
exec trans_new_prc1('hen','ENGLISH','AUTO');result is:
<!DOCTYPE html><html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><meta name=keywords content="translate, translations, translation, translator, machine translation, online translation"><meta name=description content="Google's free online language translation service instantly translates text and web pages. This translator supports: English, Afrikaans, Albanian, Arabic, Armenian, Azerbaijani, Basque, Belarusian, Bengali, Bulgarian, Catalan, Chinese, Croatian, Czech, Danish, Dutch, Esperanto, Estonian, Filipino, Finnish, French, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Irish, Italian, Japanese, Kannada, Korean, Latin, Latvian, Lithuanian, Macedonian, Malay, Maltese, Norwegian, Persian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish, Swahili, Swedish, Tamil, Telugu, Thai, Turkish, Ukrainian, Urdu, Vietnamese, Welsh, Yiddish"><meta name=robots content=noodp><meta name=google content=notranslate><link rel="canonical" href="http://translate.google.com/"><title>Google Translate</title><link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml?hl=en" title="Google Translate"><script>function _gtErr(e){var i=new Image();i.src='/gen204?jserr='+encodeURIComponent(e+": "+e.stack).substr(0,2000);i.onload=function(){i.onload=null;};}window.onerror=_gtErr;</script><script>(function(){var ti_a=function(b){this.t={};this.tick=function(b,c,a){a=void 0!=a?a:(new Date).getTime();this.t=[a,c]};this.tick("start",null,b)},ti_b=new ti_a;window.jstiming={Timer:ti_a,load:ti_b};if(window.performance&&window.performance.timing){var ti_c=window.performance.timing,ti_d=window.jstiming.load,ti_e=ti_c.navigationStart,ti_f=ti_c.responseStart;0<ti_e&&ti_f>=ti_e&&(ti_d.tick("_wtsrt",void 0,ti_e),ti_d.tick("wtsrt_","_wtsrt",ti_f))}
there is no "THEM" (translated word) in it. (I couldnt write whole returned info because exceed post limits.) -
Hi,
I am working on a query that needs to group addresses and should return the first and last house number in that group. However the house numbers are stored as varchar2, but I want a first and last with a best effort to sort them numerically.
Housenumber can have values like '1', '1A', '1_2', '10' etc.
My approach was to sort first on the numerical part, using to_number and regexp_substr and a second sort by the varchar2.
Something like:
with t as ( select 1 id, '10' hn from dual union all
select 1, '1' from dual union all
select 1, '1A' from dual union all
select 1, '11' from dual union all
select 1, '11B' from dual union all
select 1, '1_2' from dual union all
select 1, '1 B' from dual union all
select 1, '2A' from dual union all
select 1, '1-2' from dual )
select hn from t
order by to_number(regexp_substr(hn,'[0-9]*')),hnWhich gives the sorted output:
HN
1
1 B
1-2
1A
1_2
2A
10
11
11BPerfect! But I am stuck at the second step. I want the id, the first (ie '1') and last ('11B') grouped:
ID FIRST LAST
1 1 11BIt feels like I've done 99% and only need a tiny step... oh, and we have 3+ million addresses (without an index on the house number), so performance is a concern :)
I am on 10.2.0.4.0
Thanks!Hi,
So you want only one row per id? That sounds like a job for GROUP BY:
SELECT id
, MIN (hn) KEEP ( DENSE_RANK FIRST
ORDER BY TO_NUMBER (REGEXP_SUBSTR (hn, '[0-9]*'))
) AS first
, MAX (hn) KEEP ( DENSE_RANK LAST
ORDER BY TO_NUMBER (REGEXP_SUBSTR (hn, '[0-9]*'))
) AS last
FROM t
GROUP BY id
;Depending on what you know about the numbers, you might be able to do something more efficient.
For example, if you know that the number (or at least the number that you use for sorting) comes at the very beginning of hn, and that it is never more than 6 digits long, you could try:
SELECT id
, MIN ( REGEXP_REPLACE ( ' ' || hn
, '[0-9 ]*([0-9 ]{6})'
, '\1'
) ) AS first
, MAX ( REGEXP_REPLACE ( ' ' || hn
, '[0-9 ]*([0-9 ]{6})'
, '\1'
) ) AS last
FROM t
GROUP BY id
;Edited by: Frank Kulash on Jun 17, 2011 6:59 AM -
Execute commands/statements in txt file supplied to plsql procedure
Hi,
I need to execute commands which are in txt file , this txt filepath is supplied to the procedure.
In the procedure i want to open the txt file and read the commands and run the commands.
Please help on this .
Edited by: 904032 on Jun 26, 2012 12:02 AMThe fact that you are supplying a file path (more correctly known as a directory) is going to be your first problem. Security within Oracle means that access to files on the file server require a directory object to be specified and these directory objects refer to a specific directory on the file server. If you're going to be passing different directories into your procedure then you're going to have to have different directory objects set up for all the possible directories that can be accessed (or issue dynamic DDL to redefine a known directory object each time).
Once you've done that you can use the UTL_FILE package (http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/u_file.htm#ARPLS70906) to read the contents of the file as lines.
Then it depends what you mean by "commands" and "statements". Are you referring to operating system commands?... If so you will need to use something like the DBMS_SCHEDULER package to issue a job to run immediately with the appropriate command, as that is able to issue operating system commands, or you are going to have to write some Java code to issue commands for you (plenty of examples if you google). OR, perhaps you are referring to SQL statements? These could possibly be issued using the PL/SQL execute immediate statement, but you will be leaving your database open to SQL injection and major security issues, something that most companies would consider a serious flaw and not want.
how to read string which is delimited by ';'. or how read each charater in a file ..About time you read the documentation (http://tahiti.oracle.com/). There are functions: SUBSTR and INSTR which can search for things in strings and extract parts of strings, or you can use the more advanced regular expression versions of those REGEXP_SUBSTR and REGEXP_INSTR, or even REGEXP_REPLACE (which is also good for extracting parts of strings).
If you want a more concise answer, you need to ask a more concise question... {message:id=9360002} -
Advanced String Manipulation Using REGEXP
Hello all,
I've been trying to split a string using either REGEXP_SUBSTR and REGEXP_REPLACE functions with much success so I wonder whether anyone here can give me a hand. Basically the string I want to split in to 3 is in this format:
'instanceno;partno;serialno'
I have read numerous articles within last few days but I still can't get it to working (I'm sure due to my lack of regular expression handling knowledge in OBIEE). I found two articles discussing similar scenarios. One in here and the other one is here. Both of those are good, but I cannot apply those principles to my query as I'm keep getting issues with the use of semicolon (;).
Could someone explain to me how to split this string so I can have 3 separate columns, please?
Thanks and regards,Hi Anuhas,
you have to create 3 columns in the report on 3 attribute columns inside le Logical Model with this syntax for the the string str = 'instanceno;partno;serialno'
COLUMN1 = evaluate('regexp_substr(%1,''[^\;]+'', 1,1)',REPLACE(*str*,';','\;'))
COLUMN2 = evaluate('regexp_substr(%1,''[^\;]+'', 1,2)',REPLACE(*str*,';','\;'))
COLUMN3 = evaluate('regexp_substr(%1,''[^\;]+'', 1,3)',REPLACE(*str*,';','\;'))
You have to use the REPLACE function (; --> \;) because the ; is e special character
In this way you have:
COLUMN1 = instanceno
COLUMN2 = partno
COLUMN3 = serialno
The regex_substr(a,b,c) contains:
a = str the string
b = [^\;]+ find for the beginning of the string the character ;
c = number of occurrence
I hope it hepls.
Regards,
Gianluca -
Regular Expression functions not supported in Interactive report filters ??
I'm using APEX 4.0.2 and I'm trying to create a row filter in an interactive report which uses regexp_instr and regexp_replace functions and I'm getting the message:
Invalid filter expression. regexp_instr
The code runs fine in SQL Workshop
select cytogenetics from z_patient
where regexp_instr(regexp_replace(cytogenetics,'(\,+|\"+|\s)',''),'(^46XX$|^46XY$|^46XX\[..\]$|^46XY\[..\]$)')=1
CYTOGENETICS
"46,XX [20]"
"46,XY[20]"
"46,XX"
"46,XY[20]"
"46,XY[30]"
"46,XY[26]"
"46,XY [33]"
"46,XX[32]
etc...
my filter is just the where clause above i.e.
regexp_instr(regexp_replace(cytogenetics,'(\,+|\"+|\s)',''),'(^46XX$|^46XY$|^46XX\[..\]$|^46XY\[..\]$)')=1
*Are regular expression functions just not supported in interactive report filters?*
thanks in advance
Paul PHi Paul,
regular expression functions are supported in interactive report filters, but it looks like that REGEXP_INSTR hasn't been added as valid command. Only REGEXP_SUBSTR and REGEXP_REPLACE are valid commands for computation expressions and REGEXP_SUBSTR, REGEXP_REPLACE and REGEXP_LIKE for row level filters.
I have filed bug# 12926266 to fix this issue. Sorry for the inconvenience.
Regards
Patrick
My Blog: http://www.inside-oracle-apex.com
APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf -
Hi,
Can anybody tell me some documentation to learn Reguler Expression.
Thanks®ards,
ChandanRegex Buddy is worth every penny. It even has a setting for Oracle regular expressions, as there many flavors of regex out there.
Also, you can take a look at this package body as it's filled with regexp_substr and regexp_replace examples. The goal of that package is to transform Mediawiki markup into HTML, which might help you understand some of the procedures.
Tyler -
Sql for extract file path without file_name form the folumn value
Dear Experts,
can someone give the sql script to extract file path without file_name form the folumn value.
can someome provide sql to extract only path in the column value.
column value :
/data/rrsapus/oradata22/rrsa_25122011rpsp_arpch.rsp
i need output like this */data/rrsapus/oradata22/*Hi,
Welcome to the forum!
INSTR and SUBSTR is probably the most efficient way. Use INSTR to find where the last '/' is, and SUBSTR to get that many characters, starting from the beginning of the string.
INSTR and SUBSTR (and REGEXP_SUBSTR, and REGEXP_REPLACE, and RTRIM, and REPLACE, and all the other bullt-in functions) are documented in the SQL language manual:
http://docs.oracle.com/cd/B28359_01/server.111/b28286/index.htm
REGEXP_SUBSTR or REGEXP_REPLACE would also do the job, perhaps with a little less code, but maybe not as efficiently.
Here's a more creative way:
SELECT RTRIM ( str
, REPLACE (str, '/')
) AS file_path
FROM table_x
;What results do you want if str does not contain a '/'? -
Regexp_replace and regexp_substr questions
Hello,
I am new to regular expressions. Need help with following :
1. Need to remove duplicate alphanumeric string followed by space character.
Input : 'SAY HELLO HELLO HELLO WORLD'
Output: 'SAY HELLO WORLD'
Input : 'MY STRING STRING HAS DUPLICATES'
Output: 'MY STRING HAS DUPLICATES'
2. Parsing.
Input1 : 'APT D67 1023 MAIN ST BUFFALO NY'
or
Input2 : '1023 MAIN ST APT D67 BUFFALO NY'
Extract the following: 'APT D67 '
Output: '1023 MAIN ST BUFFALO NY' , 'APT D67'
How to extract substr using regexp? 'D67' is alphanumeric value might neccesserely appear after APT. Regexp_instr?
3. Is it solution to use regexpr to eliminate duplicates in the following case ?
Input : _'APT 789_ 456 FLOWER DR APT 789 VALEJIA CA'
Output: 'APT 789 456 FLOWER DR VALEJIA CA'
Thanks in advance.REgards salim.
WITH T AS
(SELECT 'SAY HELLO HELLO HELLO WORLD' TXT
FROM DUAL
UNION ALL
SELECT 'APT 789 456 FLOWER DR APT 789 VALEJIA CA'
FROM DUAL
UNION ALL
SELECT 'MY STRING STRING HAS DUPLICATES'
FROM DUAL
SELECT TXT|| case when apt is not null then ' ,'|| APT end txt
FROM (
SELECT distinct RN,TXT ,rang,apt
FROM T
MODEL
RETURN UPDATED ROWS
PARTITION BY ( ROWNUM RN)
DIMENSION BY (0 POSITION)
MEASURES (TXT ,NVL(LENGTH(REGEXP_REPLACE(TXT,'[^ ]+','')),0)+1 NB_MOT, 0 rang,
REGEXP_SUBSTR(TXT,'^APT [0-9]+') apt)
RULES
(TXT[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] =
REGEXP_SUBSTR(TXT[0],'[^ ]+',1,CV(POSITION)) ,
APT[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] =
REGEXP_SUBSTR(TXT[0],'^APT [0-9]+'),
rang[position>=1]= instr(txt[0],txt[cv()],1)) )
MODEL
RETURN UPDATED ROWS
PARTITION BY ( RN,APT )
DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY RN ORDER BY rang ASC) AS POSITION)
MEASURES ( CAST( TXT AS VARCHAR2(1000) ) AS TXT )
RULES
UPSERT
ITERATE( 1000)
UNTIL ( PRESENTV(TXT[ITERATION_NUMBER+2],1,0) = 0 )
(TXT[0] = TXT[0] || CASE WHEN ITERATION_NUMBER+1=1 AND TXT[ITERATION_NUMBER+1]='APT' THEN NULL
WHEN ITERATION_NUMBER+1=2 AND TXT[ITERATION_NUMBER] ='APT' THEN NULL
ELSE ' ' || TXT[ITERATION_NUMBER+1] END )
ORDER BY rn
SQL> WITH T AS
2 (SELECT 'SAY HELLO HELLO HELLO WORLD' TXT
3 FROM DUAL
4 UNION ALL
5 SELECT 'APT 789 456 FLOWER DR APT 789 VALEJIA CA'
6 FROM DUAL
7 UNION ALL
8 SELECT 'MY STRING STRING HAS DUPLICATES'
9 FROM DUAL
10 )
11 SELECT TXT|| case when apt is not null then ' ,'|| APT end txt
12 FROM (
13 SELECT distinct RN,TXT ,rang,apt
14 FROM T
15 MODEL
16 RETURN UPDATED ROWS
17 PARTITION BY ( ROWNUM RN)
18 DIMENSION BY (0 POSITION)
19 MEASURES (TXT ,NVL(LENGTH(REGEXP_REPLACE(TXT,'[^ ]+','')),0)+1 NB_MOT, 0 rang,
20 REGEXP_SUBSTR(TXT,'^APT [0-9]+') apt)
21 RULES
22 (TXT[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] =
23 REGEXP_SUBSTR(TXT[0],'[^ ]+',1,CV(POSITION)) ,
24 APT[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] =
25 REGEXP_SUBSTR(TXT[0],'^APT [0-9]+'),
26 rang[position>=1]= instr(txt[0],txt[cv()],1)) )
27 MODEL
28 RETURN UPDATED ROWS
29 PARTITION BY ( RN,APT )
30 DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY RN ORDER BY rang ASC) AS POSITION)
31 MEASURES ( CAST( TXT AS VARCHAR2(1000) ) AS TXT )
32 RULES
33 UPSERT
34 ITERATE( 1000)
35 UNTIL ( PRESENTV(TXT[ITERATION_NUMBER+2],1,0) = 0 )
36 (TXT[0] = TXT[0] || CASE WHEN ITERATION_NUMBER+1=1 AND TXT[ITERATION_NUMBER+1]='APT' THEN N
ULL
37 WHEN ITERATION_NUMBER+1=2 AND TXT[ITERATION_NUMBER] ='APT' THEN NULL
38 ELSE ' ' || TXT[ITERATION_NUMBER+1] END )
39 ORDER BY rn
40 /
TXT
SAY HELLO WORLD
456 FLOWER DR VALEJIA CA ,APT 789
MY STRING HAS DUPLICATES
SQL> Edited by: Salim Chelabi on 2009-04-06 14:05
Edited by: Salim Chelabi on Apr 6, 2009 4:11 PM -
Need help on Regular expression and query
Hi Guru's, Hope you all are doing great!.
I have a scenario's where i need do insert the data into table.
I have three scenarios :
select 'Kodali,Raj,S' str from dual
union
select 'Alex Romano' from dual
union
select 'ppppp' from dual
Alex Romano
Kodali,Raj,S
pppppNow what i want is .
1. Alex Romano
if there is space between the string then i want to insert into first name and last name columns
2. Kodali,Raj,S
if its a comma between the string then i want to insert into last name , first name and middle name
3. if there is only one string then same insert into first name and last name.
I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
Can you please help me out.
WITH t AS (
select 'Kodali,Raj,S' str from dual
union
select 'Alex Romano' from dual
union
select 'ppppp' from dual
select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
from
SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
, max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
, max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME
FROM t
CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
GROUP BY str
) ;Currently i am putting a b and c if its null.
Thanks in advance!user590978 wrote:
Hi Guru's, Hope you all are doing great!.
I have a scenario's where i need do insert the data into table.
I have three scenarios :
select 'Kodali,Raj,S' str from dual
union
select 'Alex Romano' from dual
union
select 'ppppp' from dual
Alex Romano
Kodali,Raj,S
pppppNow what i want is .
1. Alex Romano
if there is space between the string then i want to insert into first name and last name columns
2. Kodali,Raj,S
if its a comma between the string then i want to insert into last name , first name and middle name
3. if there is only one string then same insert into first name and last name.
I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
Can you please help me out.
WITH t AS (
select 'Kodali,Raj,S' str from dual
union
select 'Alex Romano' from dual
union
select 'ppppp' from dual
select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
from
SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
, max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
, max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME
FROM t
CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
GROUP BY str
) ;Currently i am putting a b and c if its null.
Thanks in advance!It's never a popular suggestion, but why not fix the design to begin with?
It's the year 2013, can a client not pass you a "complex" data structure consisting of first, middle and last name?
Why rely on an unreliable construct when there are so many more usable way to achieve this?
Cheers, -
Find and replace value in Delimited String
Hi All,
I have a requirement, where i need to find and replace values in delimited string.
For example, the string is "GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~". The 4th column gives month and year. I need to replace it with previous month name. For example: "GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~". I need to do same for last 12 months.
I thought of first devide the values and store it in variable and then after replacing it with required value, join it back.
I just wanted to know if there is any better way to do it?for example (Assumption: the abbreviated month is the first occurance of 3 consecutive alphabetic charachters)
with testdata as (
select 'GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~' str from dual
select
str
,regexp_substr(str, '[[:alpha:]]{3}') part
,to_date('01'||regexp_substr(str, '[[:alpha:]]{3}')||'2013', 'DDMONYYYY') part_date
,replace (str
,regexp_substr(str, '[[:alpha:]]{3}')
,to_char(add_months(to_date('01'||regexp_substr(str, '[[:alpha:]]{3}')||'2013', 'DDMONYYYY'),-1),'MON')
) res
from testdata
STR
PART
PART_DATE
RES
GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~
FEB
02/01/2013
GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~
with year included
with testdata as (
select 'GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~' str from dual
select
str
,regexp_substr(str, '[[:alpha:]]{3}-\d{2}') part
,to_date(regexp_substr(str, '[[:alpha:]]{3}-\d{2}'), 'MON-YY') part_date
,replace (str
,regexp_substr(str, '[[:alpha:]]{3}-\d{2}')
,to_char(add_months(to_date(regexp_substr(str, '[[:alpha:]]{3}-\d{2}'), 'MON-YY'),-1),'MON-YY')
) res
from testdata
STR
PART
PART_DATE
RES
GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~
JAN-13
01/01/2013
GL~1001~157747~DEC-12~CREDIT~A~N~USD~NULL~
Message was edited by: chris227 year included
Maybe you are looking for
-
Error when trying to create a worksheet with 4 columns
Dear All, I was trying to create a worksheet in tabluar formate base on a table (folder) that has 3 columns (items) .. the worksheet was created successfully .. but when saved it , then closed and tried to reopen it i got the following error ORA-0312
-
Creating a Macro with Adobe Acrobat X v.10.0.0 HELP!
Hello, I am new to Adobe and was wondering if there is a way to create a macro for my situation. I am recording voting decisions from a pdf into an excel spreadsheet. I need to go through multiple pdf files and find the pages where votes have taken p
-
How do you unlock a ipod if its diabled for 21568012 minutes?
how do you unlock a ipod if its diabled for 21568012 minutes?
-
A616 Photosmart Printer won't print with Windows 7
W7 is supposed to have all the drivers for HP printers, however my A616 won't print from my computer running W7. It will from my old desktop at work, but that's not what I need. Anyone with the solution?
-
Hi, How to view if the material document is cancelled in MIGO? Arati.