query regexp_replace
Hi all
I have a text "AND this and where Leet accumulator or equivalent are the BT end NeAring AND '." I'm using regexp_replace to add {} before and after a few words. It does not work properly. Can someone pleaes point out where I'm going wrong.
I want the output to be
"{AND} {and} where Leet accumulator {or} are equivalent {in} {BT} end NeAring {AND}.
DECLARE
L_S VARCHAR2 (400);
BEGIN
-\s = Word, includes spaces.
-MARKET!
L_S: = regexp_replace (srcstr = > ' this and where Leet accumulator or equivalent are the end BT almost AND ',)
model = > ' (AND\ | \AND| \OR\ | \NEAR\|\NOT\|\MINUS\|\ACCUM\|\ABOUT\|\BT\|\BTG\|\BTI\|\BTP\|\EQUIV\|\FUZZY\|\HASPATH\|\INPATH\|\MDATA\|\NT\|\NTG\|\NTI\|\NTP\|\PT\|\RT\|\SQE\|\SYN\|\TR\|\TRSYN\|\TT\|\WITHIN)',
ReplaceStr = > "\1 {},"
position = > 1,
accident = > 0,
modifier = > "ix");
dbms_output.put_line (L_S);
END;
Thank you
Roy
If you can accept that the result was always a space as a separator, although it has perhaps more in the original version, you can do something like
DECLARE
L_S VARCHAR2 (400);
lv_txt VARCHAR2 (400): = ' T AND or or equivalent are less and within the BT end almost AND ';
lv_matches sys.odcivarchar2list: = sys.odcivarchar2list('AND','OR','NEAR','NOT','MINUS','ACCUM','ABOUT','BT','BTG','BTI','BTP','EQUIV','FUZZY','HASPATH','INPATH');
BEGIN
L_S: = lv_txt;
L_S: = regexp_replace (l_s, ' + ',' ');
I'm looping 1.lv_matches.count
L_S: = regexp_replace (l_s '(^|) ('| lv_matches (i) |') ( |$)', '\1{\2}\3', 1, 0, 'i');
end loop;
L_S: = replace (l_s, '',' ');
Dbms_output.put_line (l_s);
END;
{AND} T {or} {or} equivalent {less} {and} in the {} BT end NeAring {AND}
Correction: placed the first replace out of the loop (feels like Monday morning in fact)
Tags: Database
Similar Questions
-
Support query and REGEXP_REPLACE
Hi, I'm new in this forum. I have a problem with a query, I have this request:
SELECT AIR CONDITIONING
of cd_capturav2. A31102012condiciones
where design like '% RTN % '.
and FORM = "CUADROII7A1."
and partida = '10101'
and camporef1 = 1;
Which give me this line:
RIESGOTASA | CUADII8RTN | MONERT | = | 00 | THERE | (| RIESGOTASA | CUADII8RTN | CODPROD | = | 1411 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 14111. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1417 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1418 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1414 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1413. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1416. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1415. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 14121. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1412 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1700 |) | THERE | RIESGOTASA | CUADII8RTN | COEFACTUALIZACION | = | 1. THERE | RIESGOTASA | CUADII8RTN | CUADRO | <>| 7 C |
In this line, I need to extract all the CODPROD in a select this back numbers of codprod:
1411,14111,1417,1418,1414,1413,1416, etc.
I am using the REGEXP_REPLACE function, but idk how can I remove all the characters except CODPROD | = | number.
Thank you very much for your help!
PD: Sry for my English, this is not my mother tongue.
Published by: user12883924 on February 21, 2013 08:11Hello
Welcome to the forum!
user12883924 wrote:
Hi, I'm new in this forum.See the FAQ forum {message identifier: = 9360002}
It can really help you to quickly get the right solutions.I have a problem with a query, I have this request:
SELECT AIR CONDITIONING
of cd_capturav2. A31102012condiciones
where design like '% RTN % '.
and FORM = "CUADROII7A1."
and partida = '10101'
and camporef1 = 1;Which give me this line:
RIESGOTASA | CUADII8RTN | MONERT | = | 00 | THERE | (| RIESGOTASA | CUADII8RTN | CODPROD | = | 1411 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 14111. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1417 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1418 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1414 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1413. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1416. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1415. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 14121. O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1412 | O | RIESGOTASA | CUADII8RTN | CODPROD | = | 1700 |) | THERE | RIESGOTASA | CUADII8RTN | COEFACTUALIZACION | = | 1. THERE | RIESGOTASA | CUADII8RTN | CUADRO | <>|7C||||
In this line, I need to extract all the CODPROD in a select this back numbers of codprod:
1411,14111,1417,1418,1414,1413,1416, etc.Do you want just a list separated by commas in the numbers, as above, or do you want to ' CODPROD | = |' too, as below?
I am using the REGEXP_REPLACE function, but idk how can I remove all the characters except CODPROD | = | number.
If you want just the numbers:
WITH sample_data AS ( SELECT 'RIESGOTASA|CUADII8RTN|MONERT|=|00||Y|(|RIESGOTASA|CUADII8RTN|CODPROD|=|1411||O||RIESGOTASA|CUADII8RTN|CODPROD|=|14111||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1417||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1418||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1414||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1413||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1416||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1415||O||RIESGOTASA|CUADII8RTN|CODPROD|=|14121||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1412||O||RIESGOTASA|CUADII8RTN|CODPROD|=|1700|)|Y||RIESGOTASA|CUADII8RTN|COEFACTUALIZACION|=|1||Y||RIESGOTASA|CUADII8RTN|CUADRO||7C||||' AS condicion FROM dual ) SELECT RTRIM ( REGEXP_REPLACE ( condicion , '.*?((CODPROD\|=\|(\d+))|$)' , '\3,' ) , ',' ) AS codprods FROM sample_data ;
Output of the above query:
CODPRODS -------------------------------------------------------- 1411,14111,1417,1418,1414,1413,1416,1415,14121,1412,1700
Thank you very much for your help!
PD: Sry for my English, this is not my mother tongue.
No matter how you can write in English, it is good to provide clear examples in SQL. Always after a few lines of sample data (using CREATE TABLE and INSERT statements or a WITH clause which, as I have done above) and exactly the results you want from these data. Less you can count on the explanations in English, you have to rely on clear entry and exit of the examples.
Published by: Frank Kulash on 21 February 2013 11:40
Always say what version of Oracle you are using (for example, 11.2.0.3.0).
The query above works in Oracle 10 (or higher), but there could be an easier way in Oracle 11, using the new argument 6th to REGEXP_SUBSTR. -
SQL query to retrieve only numbers to a string variable
Dear all Experts,
I have a requirement in one of my projects where I need to extract only the numbers present in the variable.
for example:
BANK_ACCOUNT_NUMBER = 12345-67890';
BANK_ACCOUNT_NUMBER = 12345 67890';
BANK_ACCOUNT_NUMBER = "123.456.7890";
BANK_ACCOUNT_NUMBER = 123-A456BC7890D';
In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.
Please suggest me the query how to extract numeric values from varchar variable.
Thank you
Knockaert
select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
See you soon,.
Manik.
-
IAM facing problems sql query regexp
Hi all
under custom query note here is the type of clob data in table
value of the field personalized note is exists table Anshu Udainiya the value tag iam using the regular expression to replace
Select org_prog_cam_id, ndc_no, REGEXP_REPLACE (trim (to_char (custom_note)),' < [^ <>] + > ') custom_note
from DTC_AAG_NDC_NOTE_STAGING where org_prog_cam_id = 6696 and ndc_no = '51248015003'
less
Select 6696, '51248015003', to_char ('sdfsfsdfsd'))
of the double
first query of exit
ndc_no cust1 cust2 51248015003 < p > < span style = "color: #00FFFF" > < strong > < span style = "font-size: 16px" > < span style = "background-color: #FFD700" > Anshu Udainiya </span > < / span > < / strong > < / span > < /p > 16 second length of request of personalized note
Choose the length (REGEXP_REPLACE (trim (to_char ('Anshu unmar')),' < [^ <>] + > ')) coz of the double
coz
-----
14
can you please help these for urgent need... Thank you very much
Hello
assuming that it is the only element between 2 beacons (between > and)<) ans="" that="" you="" are="" using="" at="" least="" 11g="" you="" can="" use="" regexp="" in="" this="">)>
with t as ( select '
Anshu Udainiya
' str from dual ) select regexp_substr(str, '>([^<]+)<',1,1,null,1) txt, length(regexp_substr(str, '>([^<]+)<',1,1,null,1)) len from t; TXT LEN -------------- ---------- Anshu Udainiya 14Kind regards.
Alberto
-
I'm trying to use the Plugin to "Get IR Query" of https://apex.oracle.com/pls/apex/f?p=43045:1 and most of the time that it seems to work and returning valid code but I seem to have problems with concatenated columns and regular expressions.
If I use an concatenated columns and regular expression in search criteria, an additional line seems to be added to the returned sql
The additional line of code is 'and doesn't like ' 00' 0% " but its not valid (its lack a quote and |)"» so sql cannot be used elsewhere.
I created an example here to display question
https://Apex.Oracle.com/pls/Apex/f?p=86093:1
If you select the top option will then search for a line further incorrect ((deuxieme from bottom) is added, if it is disabled then the generated sql code is OK
I implemented the plugin bad?
Thanks in advance
With the help of everyone.
It seems that the problem was in the loop that has replaced the bind variable, if there are 10 or several variables it would replace the first occurrence of the variable name to bind and a portion of those above 10 e.g. APXWS_EXPR_1 and APXWS_EXPR_10 would become FILTER_TEXT and FILTER_TEXT0, would remain set to 0 at the end.
Changed replace to a regexp_replace which replaces only the first found occurrence and it seems to work
regexp_replace (v_query,
':' || v_report .name. Binds (i),
'''' || v_report. Binds (i) .value. ''''
1: 1);
I made the change to my example on apex.oracle.com and it seems to work fine now.
-
REGEXP_REPLACE question
DB version 11.2.0.3
I have a table with the following data:
CODE
ABC ({0})
I need to write a function that returns the following:
CODE
ABC (< YEAR CURRENT >)
where current_year = 2014
so the output will look like ABC (2014) if the current year = 2014
Is there an easy way to do it from REGEXP_REPLACE?
Thank you
Hello
Kevin_K wrote:
...
I want to get the result form dynamically
ABC (2014)
The solution you posted will help but answers to validate the hard coded value. I just want to replace the '{0}' with 2014
...
Sorry, I don't understand.
When do you day 'dynamic', you mean that the query will replace '{0}' with ' 2014 "as long as the year is 2014, but from January 1, 2015, the same code will replace with ' 2015"? Use SYSDATE will take care of that.
Just hard-code in my previous answer was "ABC (...)", and I thought it was part of your needs. (Looking at the sample data and results that you have posted, I always still think.) Why do you have after the INSERT statement for code = 'A2', if you do not have to use it in the expected results, or turn on the other?
The following query shows 2 ways that both get the results expected from this data set extremely low:
Select the desc1
WHEN "ABC ({0}).
THEN TO_CHAR (SYSDATE
, ' "ABC ("yyyy").
)
OTHERWISE code
END AS reply_1
REPLACE (desc1
, '{0}'
TO_CHAR (SYSDATE, 'YYYY')
) AS reply_3
of test123
where code = 'A1 '.
;
Output:
REPLY_1 REPLY_3
-------------------- --------------------
ABC ABC (2014) (2014)
Of course, you won't have the two columns. I guess that you definitely don't want reply_1, although I do understand not why (in other words, I understand not your needs).
-
How work REGEXP_REPLACE?
Hi all
How it works?
SELECT REGEXP_REPLACE('18.0.1', ' (\d+)\.) () \d+)\. ((\d+)', '\1') FROM dual; -> 18
Thank you
Hello 994122
This request is in fact equivalent to the following query:
SELECT REGEXP_SUBSTR ('18.0.1 ',' (\d+)\.) () \d+)\. ((\d+)', 1, 1, null, 1) FROM dual;
Because in the REGEXP_REPLACE in your code, you do not write only a part of the string exactly without modification to the original string (in the first group) you can call it a chain of analysis.
SELECT REGEXP_REPLACE('18.0.1', ' (\d+)\.) () \d+)\. ((\d+)', '\1') FROM dual; --> 18
\d: a numeric character, which equals the POSIX class [[: digit:]]
\d+: at least one or more numeric characters
(\d+): grouping of numbers operator - in REGEXP_REPLACE, you can make reference to such a group with \n
------: character for the exhaust point (because the dot has a meaning in the regular expression language that corresponds to the character of any)
. : any character
"\1": in this case you write again the same value in the first group and you do not take account of the other party in the chain. (Reference)
'-1'-> it refers to the first group of your channel "(\d+). (\d+)\. (\d+)', of course without brackets
'-2'->, it refers to the second category of your channel of '(\d+)\.) (\d+)\. (\d+)', of course without brackets
'-3'->, it refers to the third category of your channel of '(\d+)\.) (\d+)\. (\d+)', of course without brackets
I hope it helps.
Best regards, David
-
using regexp_replace to remove html tags and
Hello
I am using the regular expression to remove the html tags / a string, replacing them with nothing like shown below.
example = if I enter "Hello World < u > < p > < br > apex whats coming" I should get it == > "Hello World Apex whats to come.
Consider the query under, select regexp_replace (string, any html tag /, 'i') of double.
so, how can I write the expression?
Oracle 11g rel2,
Thank you.
Hello
You can post the exact string you want to replace.
If you have a string with & npsb, then you need to escape the symbol '&' (set escape '-' and add '-' infront of & in your chain) or need to cancel its definition (as mentioned by MANIK) otherwise it will encourage value for it.
Assuming that your string is the string ' &npsb;' and '& npsb; '.
set the escape ' \'
WITH t (STR)
AS (SELECT ' Hello world of)
<>> & npsb; "apex whats comes ------&npsb; to top"
THE DOUBLE)
SELECT REGEXP_REPLACE ([STR, '<[^>] * > | &npsb; | & npsb;')
T;
OUTPUT:
Hello to the world of the apex of whats to come
set define off
WITH t (STR)
AS (SELECT ' Hello world of)
<>> & npsb; "apex whats comes &npsb; to top"
THE DOUBLE)
SELECT REGEXP_REPLACE ([STR, '<[^>] * > | &npsb; | & npsb;')
T;
OUTPUT:
Hello to the world of the apex of whats to come
[^>[^> -
Hi all
I have the below where all the WITH clause needs to separate query and SELECT article queries must be separated. Any help is very appreciated. Try SUBSTR and INSTR.
SQL query:
######################################################################
WITH
test_does1 like)
Select 'Y' in double
)
Select *.
of test_does1
UNION ALL
SELECT 'X' FROM double
UNION ALL
SELECT 'A' FROM dual
UNION ALL
WITH
test_does2 like)
Select 'Y' in double
)
Select *.
of test_does2
######################################################################
OK... Then try the below (LISTAGG will not work in oracle 10g)
-Separate with clause
SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval
FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)
FROM (SELECT REPLACE (' WITH test_does1 AS))
(SELECT "Y" FROM dual)
)
SELECT * from test_does1
UNION ALL
SELECT "X" FROM dual
UNION ALL
SELECT "A" dual FROM
UNION ALL
WITH test_does2 AS
(SELECT "Y" FROM dual)
)
SELECT * FROM test_does2 ',' UNION ALL ',',') str1
THE DOUBLE)
CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">=>
WHERE the str AS "WITH % ';
-Select to separate
SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval
FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)
FROM (SELECT REPLACE (' WITH test_does1 AS))
(SELECT "Y" FROM dual)
)
SELECT * from test_does1
UNION ALL
SELECT "X" FROM dual
UNION ALL
SELECT "A" dual FROM
UNION ALL
WITH test_does2 AS
(SELECT "Y" FROM dual)
)
SELECT * FROM test_does2 ',' UNION ALL ',',') str1
THE DOUBLE)
CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">=>
WHERE str AS 'CHOOSE % ';
-Unit tests
SQL > SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval
2 FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)
3 (SELECT REPLACE (' WITH test_does1 AS))
4 (SELECT "Y" FROM dual)
5 )
6. SELECT * FROM test_does1
7 UNION ALL
8 "X" SELECT FROM dual
9 UNION ALL
10. SELECT "A" dual FROM
11 UNION ALL
12 test_does2 WITH AS
13 (SELECT "Y" FROM dual)
14)
15 SELECT * FROM test_does2 ',' UNION ALL ',',') str1
16 DOUBLE)
17 CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">=>
18. WHERE LIKE str "WITH % ';
LSVAL
--------------------------------------------------------------------------------
WITH test_does1 AS (SELECT FROM dual 'Y') SELECT * FROM test_does1 UNION ALL
WITH test_does2 AS (SELECT FROM dual 'Y') SELECT * FROM test_does2
SQL > SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval
2 FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)
3 (SELECT REPLACE (' WITH test_does1 AS))
4 (SELECT "Y" FROM dual)
5 )
6. SELECT * FROM test_does1
7 UNION ALL
8 "X" SELECT FROM dual
9 UNION ALL
10. SELECT "A" dual FROM
11 UNION ALL
12 test_does2 WITH AS
13 (SELECT "Y" FROM dual)
14)
15 SELECT * FROM test_does2 ',' UNION ALL ',',') str1
16 DOUBLE)
17 CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">=>
18. WHERE str LIKE "SELECT % ';
LSVAL
--------------------------------------------------------------------------------
SELECT 'X' FROM dual UNION ALL SELECT 'A' double
-
I would like to delete empty lines and spaces of my query results?
11 GR 2
-----------------------------------------------------
My query:
Select REGEXP_REPLACE (dbms_metadata.get_ddl ('PROCEDURE', 'HEL_'), ('user1...') ", 1, 0, 'i') of double
-------------------------------------
result:
CREATE OR REPLACE PROCEDURE "HEL_"
as
begin
dbms_output.put_line('Hello!');
end;------------------------------
expected result:
CREATE OR REPLACE PROCEDURE "HEL_"
as
begin
dbms_output.put_line('Hello!');
end;Hello
I don't think that there is a way to make changes in the same regular expression. You can do a REPLACE separate to get rid of 'the USER '. nesting into one another, like this:
SELECT REGEXP_REPLACE (REPLACE (dbms_metadata.get_ddl ('PROCÉDURE', 'HEL_')
"' USER1'."
)
, '^\s+'
NULL
1
0
, 'm'
) AS less_whitespace
OF the double
;
-
regexp_replace with all characters from the keyboard
Hello
Using Oracle 11 g 2. I am developing an expression that replaces all characters not found on the keyboard number 2. However, the expression that I developed does not manage all characters. When testing it, some characters are replaced with success, while others are not. For example, if I remove the () in the list of regexp_replace, I should wait for the result of the query to display 22, but it doesn't. Similar results, that's happened to the other characters. Here's my query. Any suggestion would be appreciated.
Select
regexp_replace (' $# () / *. %, cm & -~': +! @^ _ = |------;) "<>? / [] {} ', ' [^ A-Za-z0-9$#() / * %., cm &-~': + ! @^ _ = | \ ; "<>? ([/ {} []]', '2') as test
of the double
-in a class character between character indicates a range, so & -~ does, including (and).
[[Using characters such as] and - in a characterclass, they must be placed in dedicated positions] during the first and the last (or the first if that is not used for another).
Take a look at the documentation on this issue.
Consider
Select
regexp_replace (' $# () / * %., "& -~': +! @^ _ = |------;) » <>?/[]{}', '[^!-~]', '2') as test1
regexp_replace (' $# () / * %., "& -~': +! @^ _ = |------;) » <>?/[]{}', '[^!-''*-~]', '2') as test2
of the double
TEST1 TEST2 $#()/*%.,'&-~`:+!@^_=|\;" <>?/[]{} $#22/*%.,'&-~`:+!@^_=|\;" <>?/[]{} ! ~ - should probably give you the desired range.
In the second example [^!-"*-~], the () are excluded by splitting the beach to their posts.
-
Looking for a keyword using as a query that could contain several appearance in the same column
I am facing a problem. A bunch of my JSP frontend code was stored in a few tables in my database (65 rows in a table), I have identified using a few queries. Now, I want to update a Href link, which is present in all of these motions. But since these entries in the column are very long (50 to 60 lines long) and it is possible that some lines may the link (which must be replaced), several times, I'm not sure if a query updated simple using a only as will work for her or not?
Any suggestion/ideas are welcome.
Please let me know if you need more info.
Hello
e5d4d744-cf66-4FE0-8353-bbd8fd826b21 wrote:
I am facing a problem. A bunch of my JSP frontend code was stored in a few tables in my database (65 rows in a table), I have identified using a few queries. Now, I want to update a Href link, which is present in all of these motions. But since these entries in the column are very long (50 to 60 lines long) and it is possible that some lines may the link (which must be replaced), several times, I'm not sure if a query updated simple using a only as will work for her or not?
Any suggestion/ideas are welcome.
Please let me know if you need more info.
Yes; whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), so that people who want to help you can recreate the problem and test their ideas.
Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Simplify the problem as much as possible. For example, if your strings are sometimes up to 4000 characters, you don't have to display all of the data that is almost as long. You can probably show you want with strings that are 80 characters long.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
This statement:
UPDATE table_x
SET str = REPLACE (str
old_link
new_link
)
WHERE str LIKE "%" | old_link | '%'
;
will change all the occurrences of old_link to new_link. It will only change the lines where old_link occurs, but, aside from that, regardless of how many times old_link occurs in str: if it appears 2 times in the same str, two occurrences will be changed in new_link.
Watch out for the problem ' mother is in chemotherapy. If old_link is 'bar.com', the above statement will change "a". You may need to REGEXP_REPLACE or REGEXP_LIKE if you need to consider what (if any) comes immediately before "bar.com' to decide or not to change it.
-
Hi experts
I have three table
I want employee Division all departments of parent for this Department.CREATE TABLE DEPT ( DEPT_ID NUMBER(10) NOT NULL, DEPT_NAME VARCHAR2(300 BYTE), DEPT_PARENT NUMBER(10), DEPT_CATEGORY NUMBER(1) ) Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (1, 'A', NULL, 1); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (2, 'B', 1, 1); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (3, 'C', 1, 1); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (4, 'D', 2, 2); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (5, 'E', 2, 2); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (6, 'F', 4, 2); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (7, 'G', 6, 3); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (8, 'H', 1, 2); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (9, 'I', 8, 3); Insert into DEPT (DEPT_ID, DEPT_NAME, DEPT_PARENT, DEPT_CATEGORY) Values (10, 'J', 9, 2); COMMIT; ********* CREATE TABLE DEPT_MANAGER ( DEPT_ID NUMBER(10) NOT NULL, MGR_ID NUMBER(10) ) Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (1, 1); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (2, 2); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (3, 5); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (4, 6); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (5, 8); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (6, 11); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (7, 14); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (8, 16); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (9, 18); Insert into DEPT_MANAGER (DEPT_ID, MGR_ID) Values (10, 19); COMMIT; ********** CREATE TABLE EMPLOYEE ( EMP_ID NUMBER(10) NOT NULL, DEPT_ID NUMBER(10) ) Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (1, 1); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (2, 2); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (3, 2); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (4, 2); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (5, 3); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (6, 4); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (7, 4); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (8, 5); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (9, 5); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (10, 5); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (11, 6); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (12, 6); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (13, 7); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (14, 7); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (15, 8); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (16, 9); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (17, 9); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (18, 10); Insert into EMPLOYEE (EMP_ID, DEPT_ID) Values (19, 10); COMMIT; SELECT * FROM DEPT; DEPT_ID DEPT_NAME DEPT_PARENT DEPT_CATEGORY ------- --------- ----------- ------------- 1 A 1 2 B 1 1 3 C 1 1 4 D 2 2 5 E 2 2 6 F 4 2 7 G 6 3 8 H 1 2 9 I 8 3 10 J 9 2 SELECT * FROM DEPT_MANAGER; DEPT_ID MGR_ID ------- ------ 1 1 2 2 3 5 4 6 5 8 6 11 7 14 8 16 9 18 10 19 SELECT * FROM EMPLOYEE; EMP_ID DEPT_ID ------- ------ 1 1 2 2 3 2 4 2 5 3 6 4 7 4 8 5 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 9 17 9 18 10 19 10
I want to show each Department in a column,
Description:
1. I'm doing dept_id for the employee in the EMPLOYEE table
2. I do all departments of parent for employee Division of table DEPT
3.
I need to check (employee service and all departments of parent).
table DEPT_MANAGER.
If emp_id Manger for any Department,
and this department match (the employee Department or all departments of parent)
This Department will be excluded from the result with all the kids if found.
We will apply some employees Description:
ex:
***************************
emp_no = 1
1 dept_id = 1
2 departments parent for dept_id 1 = null
3. no match.
output: (Nothing)
***************************
emp_no = 2
1 dept_id = 2
2 departments for dept_id parent (2) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = output 2, because the employee as the Director of this Department.
output: 1
***************************
emp_no = 3
1 dept_id = 2
2 departments for dept_id parent (2) = 1
and the parent of the departments for dept_id 1 = null
3. no match.
output: 1 2
***************************
emp_no = 5
1 dept_id = 3
2 departments for dept_id parent (3) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = output 3, because the employee as the Director of this Department.
output: 1
***************************
emp_no = 7
1 dept_id = 4
2 departments for dept_id parent (4) = 2
and the parent of the departments for dept_id (2) = 1
and the parent of the departments for dept_id 1 = null
3. no match.
output: 4 2 1
***************************
emp_no = 7
1 dept_id = 4
2 departments for dept_id parent (4) = 2
and the parent of the departments for dept_id (2) = 1
and the parent of the departments for dept_id 1 = null
3. no match.
output: 4 2 1
***************************
emp_no = 7
1 dept_id = 4
2 departments for dept_id parent (4) = 2
and the parent of the departments for dept_id (2) = 1
and the parent of the departments for dept_id 1 = null
3. no match.
output: 4 2 1
***************************
emp_no = 11
1 dept_id = 6
2 departments for dept_id parent (6) = 4
and the parent of the departments for dept_id (4) = 2
and the parent of the departments for dept_id (2) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = exit 6, because the employee as the Director of this Department.
output: 4 2 1
***************************
emp_no = 16
1 dept_id = 9
2 departments for dept_id parent (9) = 8
and the parent of the departments for dept_id (8) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = 8 output, because the employee as the Director of this Department.
and exclude dept_id = 9 output, because child dept_id (9) for department (8).
and (9) Department has been excluded
output: 1
***************************
emp_no = 18
1 dept_id = 10
2 departments for dept_id parent (10) = 9
and the parent of the departments for dept_id (9) = 8
and the parent of the departments for dept_id (8) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = exit 9, because the employee as the Director of this Department.
and exclude dept_id = 10 output, because child dept_id (10) for department (9).
and the Department (10) has been excluded
output: 8-1
***************************
emp_no = 19
1 dept_id = 10
2 departments for dept_id parent (10) = 9
and the parent of the departments for dept_id (9) = 8
and the parent of the departments for dept_id (8) = 1
and the parent of the departments for dept_id 1 = null
3 exclude dept_id = 10 output, because the employee as the Director of this Department.
output: 9 8 1
******************************
Desired outputDesired Output EMP_ID DEPT_ID1 DEPT_ID2 DEPT_ID3 DEPT_ID4 DEPT_ID5 DEPT_ID6 ....... ------- ------- ------- ------- ------- ------- ------- 1 2 1 3 1 4 2 1 5 1 6 2 1 7 4 2 1 8 2 1 9 5 2 1 10 5 2 1 11 4 2 1 12 6 4 2 1 13 7 6 4 2 1 14 6 4 2 1 15 8 1 16 1 17 9 8 1 18 8 1 19 9 8 1 ***************************************************************** And i want dept_id for every emp_id from table employee and check DEPT_CATEGORY for every dept_id from table dept, if DEPT_CATEGORY = 3 then make dept_parent for this dept_id
EMP_ID DEPT_ID
------- ------
1 1
2 2
6 W
1 W
5 3
6 4
4 of 7
8 5
9 5
10 5
11 6
12 6
13-6 - change of parent (7) 7 = 6
14-6 - change of parent (7) 7 = 6
15 8
16 8 - change 9-parent (7) = 8
17 8 - change 9-parent (7) = 8
18 10
19 10
Thanks in advanceHello
Welcome to the forum!
905689 wrote:
Hi expertsI have three table
CREATE TABLE DEPT ( ...
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.
... ***************************
emp_no = 31 dept_id = 2
2 departments for dept_id parent (2) = 1
and the parent of the departments for dept_id 1 = null
3. no match.
output: 1 2
*************************** ...I understand the above explanation, but that doesn't seem to match the results below:
Desired Output EMP_ID DEPT_ID1 DEPT_ID2 DEPT_ID3 DEPT_ID4 DEPT_ID5 DEPT_ID6 ....... ------- ------- ------- ------- ------- ------- ------- 1 2 1 3 1 4 2 1 ...
I guess it is a typo and the output for emp_id = 3 line should resemble the line for emp_id = 4 (with the exception of emp_id himself, of course).
Here's a way to get the first output desired:
WITH bottom_up_results AS ( SELECT CONNECT_BY_ROOT dept_id AS orig_dept_id , SYS_CONNECT_BY_PATH (dept_id, '/') AS path FROM dept WHERE CONNECT_BY_ISLEAF = 1 START WITH dept_id IN ( SELECT dept_id FROM employee ) CONNECT BY dept_id = PRIOR dept_parent ) , got_employee_info AS ( SELECT e.emp_id , REGEXP_REPLACE ( b.path || '/' , '^.*/' || TO_CHAR (m.dept_id) || '/' , '/' ) AS new_path -- , b.path -- FOR TESTING ONLY -- , m.dept_id -- FOR TESTING ONLY FROM employee e JOIN bottom_up_results b ON e.dept_id = b.orig_dept_id LEFT OUTER JOIN dept_manager m ON e.emp_id = m.mgr_id ) SELECT emp_id , REGEXP_SUBSTR (new_path, '[^/]+', 1, 1) AS dept_id1 , REGEXP_SUBSTR (new_path, '[^/]+', 1, 2) AS dept_id2 , REGEXP_SUBSTR (new_path, '[^/]+', 1, 3) AS dept_id3 , REGEXP_SUBSTR (new_path, '[^/]+', 1, 4) AS dept_id4 , REGEXP_SUBSTR (new_path, '[^/]+', 1, 5) AS dept_id5 , REGEXP_SUBSTR (new_path, '[^/]+', 1, 6) AS dept_id6 , ... -- repeat as many times as needed FROM got_employee_info ORDER BY emp_id ;
It's basically a hierarchical query from the bottom up , where we start with the leaves of a tree and move to the root. The complication is that, for managers, we do not want to start their own deparatent; We want to start after the Department that they manage. You do understand where is the starting point for each employee, but I think it's simpler and more efficient just to assume that the path of each employee will start to their own Department (this is the path variable), but, as soon as we have this path, ignore the part up to and including the detriment they manage If applicable. (this is new_path.)
*****************************************************************
And I want dept_id for each table employee emp_id
and check each dept_id of table dept, DEPT_CATEGORY
If DEPT_CATEGORY = 3 then do dept_parent for this dept_idSo, in the case of dept_category = 3, you want to dept_partent; otherwise, you want dept_id.
This sounds like a job for CASE:Desired Output EMP_ID DEPT_ID ------- ------ 1 1 2 2 3 2 4 2 5 3 6 4 7 4 8 5 9 5 10 5 11 6 12 6 13 6 --- change from 7 to parent (7) = 6 14 6 --- change from 7 to parent (7) = 6 15 8 16 8 --- change from 9 to parent (7) = 8 17 8 --- change from 9 to parent (7) = 8 18 10 19 10
When you say
"parent (* 7 *) = 8", you mean
"parent (* 9 *) = 8", right?SELECT e.emp_id , CASE WHEN dept_category = 3 THEN d.dept_parent ELSE d.dept_id END AS dept_id FROM employee e JOIN dept d ON e.dept_id = d.dept_id ORDER BY e.emp_id ;
Published by: Frank Kulash, January 3, 2012 12:43
-
need help to understand REGEXP_REPLACE
Hi all
I'm new to this site so please forgive me for making mistakes. I have a field 'DESCRIPTION of the STUDENT' and they have the following values
2830 ORO - (2011) Rob Miller [6]
2830 ORO - Cathy Ingrid (2011) [7]
2830 ORO - (2011) Sam Sullivan [8]
2650 Robert Lawson
2660 Pat Ortt (2009)
2690 - mark lively
2710 Tim Lacreta
What I want in my desired output is
(2011) Rob Miller [6]
Cathy Ingrid (2011) [7]
(2011) Sam Sullivan [8]
Robert Lawson
Pat Ortt (2009)
Mark lively
Tim Lacreta
Need help please, I know I have to use REGEXP_REPLACE, but I do not understand how I went through the documentation, but has not been of any help.
Thank youHello
Welcome to the forum!
Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data. Since this is your first post, I'll do it for you:
CREATE TABLE table_x ( student_description VARCHAR2 (80) ); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Rob Miller [6]'); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Cathy Ingid [7]'); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Sam Sullivan [8]'); INSERT INTO table_x (student_description) VALUES ('2650 - Robert Lawson'); INSERT INTO table_x (student_description) VALUES ('2660 - Pat Ortt(2009)'); INSERT INTO table_x (student_description) VALUES ('2690 - Mark Lively'); INSERT INTO table_x (student_description) VALUES ('2710 - Tim Lacreta');
Explain how you get the results you want from these data. For example: "I want the student_description part that comes after the substring of characters 3 space-dash-space. Spaces are important, because the first part of student_description, the part I want to delete, can contain a hyphen (for example ' 2830 - ORO - (2011) Rob Miller [6] "). »
I think you want something like this:
SELECT student_description , REGEXP_REPLACE ( student_description , '.* - (.*$)' , '\1' ) AS after_dash FROM table_x ;
«. "*" means "0 or more characters (all).
"-" means exactly what it says: a space, followed by a hyphen, followed by a space. Hyphen has no special meaning outside the brackets.
' $' means the end of the string.It would be more effective to do this particular job without using regular expressions:
SELECT student_description , SUBSTR ( student_description , 3 + INSTR ( student_description , ' - ' ) ) AS after_dash FROM table_x ;
Depending on your needs, you may need to adjust this query if student_description does not always contain ' - '.
Published by: Frank Kulash, December 29, 2011 14:08
-
Hello
In my table, I have the name used like this
EX:
BOSE, MR. BIRAT
NANDY, MR. AMITABHA
The name before the colon is the name of family and after it's first name
Now, I want to show in the front-end server like this for both above
MR. BOSE BIRAT
MR. AMITABHA NANDY
How to write a Sql query, where you can get the name before the decimal point and place at the end of the name and remove the comma from also for display purpose.
Thank youSomething like that?
WITH t AS (SELECT 'BOSE, Mr. BIRAT' as n FROM DUAL UNION ALL SELECT 'NANDY, Mr. AMITABHA' FROM dual ) SELECT n, regexp_replace(n, '([^,]+), (.+)*', '\2 \1') FROM t;
Maybe you are looking for
-
How do I enable "Click to play" so the videos do not play unless I want to do?
In my view, there is a setting that will prevent the video to play unless I click on the play button. I want to prevent videos from automatically playing all the sites I visit.
-
Hi all, thanks ahead for any help. I use sync for awhile now and works a lot and on all my devices. Now my problem is that I forgot the email that I use for my sync now has been deleted and I don't know how to change it. I save all the bookmarks and
-
How go referenced Managed and keep opening folders Structure?
I am preparing to become "independent opening." My first step is to go to referenced Managed. With photos outside of the opening, I can switch to another dam or simply use the Finder with another editor as affinity. I spent so much time to organiz
-
Update HP Pavilion-e070sl RAM of 4 GB
Hi, I need to know what is the maximum. memory allowed for my laptop. I have 4 GB DDR3 1600 (800 Mhz). I did find a few features of the HP site. AIDA wrote: Types of memory support DDR3-1866, DDR3-1600, DDR3-1333, DDR3-1066 SDRAM Maximum memory amoun
-
custom user interface will not close
Hello I have created a custom UI TS, based on the graphic interface delivered simple TS. When I close the user interface, the process remains in the list of windows processes, I can put an end from the windows Task Manager. This only happens if the a