Procedure to extract several substring of a string
Hi allI was wondering how can I extract substring of a string. I would write a procedure to update data in the table and by mistake if the string doesnot match the pattern.
Example of a string: [1594374: "SFD"] [1597251: 'TTT'] [1601085: 'SSS']
Using this channel, I would update as table 'test' which has columns ID and TYPE.
Updates of the statements will be:
UPDATE TEST SET type is 'DFS' where id = 1594374;.
UPDATE TEST SET type is 'TTT' where id = 1597251;.
UPDATE TEST SET type is 'TTT' where id = 1597251;.
I would be grateful if someone could help me with this.
Thank you
SQL> create table test(
2 id number,
3 type varchar2(10)
4 )
5 /
Table created.
SQL> insert into test(id) values(1594374)
2 /
1 row created.
SQL> insert into test(id) values(1597251)
2 /
1 row created.
SQL> insert into test(id) values(1601085)
2 /
1 row created.
SQL> select * from test
2 /
ID TYPE
---------- ----------
1594374
1597251
1601085
SQL> merge
2 into test a
3 using (
4 select ltrim(regexp_substr('[1594374:''DYC''][1597251:''TTT''][1601085:''SSS'']','\[(\d+)',1,level),'[') id,
5 ltrim(regexp_substr('[1594374:''DYC''][1597251:''TTT''][1601085:''SSS'']',':''[^'']+',1,level),':''') type
6 from dual
7 connect by level <= length(regexp_replace('[1594374:''DYC''][1597251:''TTT''][1601085:''SSS'']','[^[]'))
8 ) b
9 on (a.id = b.id)
10 when matched
11 then
12 update set a.type = b.type
13 /
3 rows merged.
SQL> select * from test
2 /
ID TYPE
---------- ----------
1594374 DYC
1597251 TTT
1601085 SSS
SQL>
SY.
Tags: Database
Similar Questions
-
Extract the substring of the string
For the life of me I can not find a function to extract a substring of an existing string. The closest I could find was SearchSplit String and replace substring, but none of them do what I want.
That's what I want to do:
Assuming that the string "Test String", the letters are in positions as follows:
T e s t _ S t r i e n t
0 1 2 3 4 5 6 7 8 9 10Now correct the substring offset 5 on position 7 (length 3):
Substring = r t S
5 6 7
In Java, for example, you can easily do this using the code below:
String str = "Test String";
Substring of String = str.substring (5.7);
There are no simple function to do this in LabVIEW? If not, what is the best way to do it?
Use String subset of index 5 and length 3.
-
How to extract the same part of the substring of two strings?
How can I retrieve the first identical substring of two strings?
version: 10 gr 2
as for example:
As you can see, the size of the substring is unknown.Given: str1: randomStringWith123abc str2: randomStringfor345abc Get: substr:randomString Given: str3: dummyhowareu str4: dummyiamfine Get: substr:dummy
any ideas?Hello
something like this:
with x as (select 'dummyhowareu' str1, 'dummyiamfine' str2 from dual) select replace(str1,ltrim(str1,str2)) from x
Herald tiomela
http://htendam.WordPress.com -
How to extract a substring of the subject of actionEvent.getSource ()?
Hello
I am trying to extract a substring of the form actionEvent.getSource (), but when I use the javascript substring it works doesn´t work. It sounds simple, but it does not work.
When I apply alert (actionEvent.getSource ()) it produces ' AdfRichCommandToolbarButton [oracle.adf.RichCommandToolbarButton] id = zoomine, but when
It is used with actionEvent.getSource () .substring (1, 5), it doesn´t work.
It's the code of the function:
function tClick (actionEvent)
{actionEvent.cancel ();
eventSource var = actionEvent.getSource ();
var x = eventSource.substring (1, 5);
Alert (x);
}
Can someone help me?
Thank you
KuThe problem is that actionEvent.getSource () returns a string. It returns an object.
try actionEvent.getSource (m:System.NET.SocketAddress.ToString () .substring (1, 5))
or even better explain what you are trying to archive. We can help you get a better solution to your problem.Timo
-
Extract an a piece of string starting with a number
Hello
I'm new to SQL, I can use some help with the following problem. I need to extract the number of contract of a string, but the position of the contract number and the text inside the string may vary, which means that it is important to link the SELECT statement with the number. Extract only numbers would help too, because the contract number contains letters and other characters. For example, if there is a "Payment for a contract nr 1100/70HE" string, the SELECT statement must be able to extract only '1100/70HE' this string.
Thank you in advance,
Keit1007555 wrote:
The first three characters of a certain number of contracts are always numbers. If the application needs to find a piece of string, where three characters are numbers. The global chain can look like 'Payment for a contract number 1100/70HE', "Payment of 1100/70HE of the contract", "1100/70HE contract payment" etc. I hope that clarifies it a bit.SQL> ed Wrote file afiedt.buf 1 with t as 2 (select '"Payment to a contract nr 1100/70HE payment' as str from dual) 3 select regexp_substr(str,'[0-9]{3}[^ ]+') con 4* from t 5 / CON --------- 1100/70HE {code}
-
How can I extract a substring in WHERE Clause <; CFQUERY >;?
Is it possible to extract a substring in the WHERE clause of either < CFQUERY > or in a query of queries? I try to use the following query to find all e-mail addresses with the domain "comcast.net" (i.e., everything that follows the '@' in the email address). I ask an MS-Access database table.
< cfquery name='test' datasource='membership'>
SELECT Email_address
OF tblMembers
WHERE the MID (email_address, INSTR (email_address, ' @') + 1) = "comcast.net"
< / cfquery >If I try this as a query, I get the error message "[Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] data type incompatible in criteria expression."
If I try it as a t/t, I get the error message " " Met 'MID (e-mail1.,. Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition,'.
I would be very grateful for any help on finding something that works! Thanks for your help!
You couldn't do a LIKE in where clause instead:
SELECT Email_address
OF tblMembers
WHERE email_address LIKE ' %@comcast.net'
You should get the addresses you're looking for.
-Carl V.
-
Procedure to insert several lines
create or replace procedure relevent_doc_after_insert (JOBNUMBER IN varchar2,
DOCNAME IN VARCHAR2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
vDocName VARCHAR2 (80);
CURSOR insertAfterdata
IS
SELECT mnd_doc_name
OF clm_min_doc_to_process
WHERE mnd_doc_name! = DOCNAME;
BEGIN
OPEN insertAfterdata.
LOOP
EXTRACTION insertAfterdata
IN
vDocName;
EXIT WHEN insertAfterdata % NOTFOUND;
INSERT INTO clm_relevent_doc (rd_id,
rd_job_no,
rd_doc_name,
rd_created_user,
rd_created_date,
rd_status)
VALUES (relevant_doc_sequence. NEXTVAL,
JOBNUMBER,
vDocName,
'system ', he said.
To_char (SYSDATE, "yyyy-mm-dd HH12:MI:SS"),
'pending');
COMMIT;
END LOOP;
CLOSE InsertAfterdata;
EXCEPTION
WHILE OTHERS THEN
NULL;
END;
Above is my procedure
I pass below the settings during the execution
JOBNUMBER = 123
DOCNAME = driving licence
When the CURSOR query get the 3rows as a result but insert several rows in the clm_relevent_doc table, why did this happen.It does not work properly, is it not? If this isn't the case, then please point where.
Also as knani questioned, and so I did (although not confirmed), you really need the independent transaction? can you justify using autonomous transactions, in this procedure?
select * from clm_min_doc_to_process; MND_ID MND_DOC_NAME MND_DOC_CODE ---------------------- ------------------ -------------------- 1 Driving Licence DL 2 SA Report SARPT 3 Estimate EST 4 Photos PHOT select * from clm_relevent_doc; RD_ID RD_JOB_NO RD_DOC_NAME RD_CREATED_USER RD_CREATED_DATE RD_ADD_DOC_NAME RD_UPDATE_USER RD_REQUEST RD_REQUEST_METHOD RD_STATUS RD_RECEIVED_DATE_TIME ---------------------- --------------- -------------- ----------------- ---------------- ---------------- ---------------- ---------- ----------------- --------- --------------------- set serveroutput on; begin relevent_doc_after_insert(123, 'Photos'); end; anonymous block completed 3 rows inserted select * from clm_relevent_doc; RD_ID RD_JOB_NO RD_DOC_NAME RD_CREATED_USER RD_CREATED_DATE RD_ADD_DOC_NAME RD_UPDATE_USER RD_REQUEST RD_REQUEST_METHOD RD_STATUS RD_RECEIVED_DATE_TIME ---------------------- --------------- --------------- --------------- ------------------- --------------- -------------- ---------- ----------------- --------- --------------------- 1 123 Driving Licence system 2013-01-21 06:43:23 pending 2 123 SA Report system 2013-01-21 06:43:23 pending 3 123 Estimate system 2013-01-21 06:43:23 pending
-
Need help to extract the data into a string of separate brackets
Hello
I have a scenario where I have to extract data into a string that is enclosed in [].
Here's what I want to do...
entry:
[name_first] [name_mi] [name_last]
required output: this must return all data that are placed between square brackets.
name_first
name_mi
name_last
I tried the "REGEXP_SUBSTR' but my version of the database is 9i, and it is available only from 10 g.
Thanks in advance.Hello
You can use SUBSTR and INSTR
This should work in Oracle 9:WITH cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 3 ) , got_pos AS ( SELECT x.txt , c.n , INSTR (x.txt, '[', 1, c.n) AS l_pos , INSTR (x.txt, ']', 1, c.n) AS r_pos FROM table_x x CROSS JOIN cntr c ) SELECT txt , n , SUBSTR ( txt , l_pos + 1 , r_pos - (l_pos + 1) ) AS sub_txt FROM got_pos ORDER BY txt , n ;
Sorry, I don't have an Oracle 9 database now; I had to test this in Oracle 10.
jimmy437 wrote:
... I tried the "REGEXP_SUBSTR' but my version of the database is 9i, and it is available only from 10 g.It's true. Regular expressions are very useful, but they are not available in Oracle 9 (or earlier).
Oracle 9 has a package supplied by Oracle, OWA_PATTERN, which provides regular expression features:
http://docs.Oracle.com/CD/B12037_01/AppDev.101/b10802/w_patt.htm
I know it's the Oracle 10, documentation, but there are in Oracle 9, too.Oracle 9 is very old. You should consider the upgrade.
-
Extraction of the bracketed text string data
I have a bit of SQL to retrieve the text in brackets at the end of a string:
Still, it extracts data from the media at the end of the string.WITH test_data AS ( SELECT 'Joseph Bloggs (Joe) (THIS)' v1 FROM DUAL UNION ALL SELECT 'Robert Holnas (Bob) (THAT)' FROM DUAL UNION ALL SELECT 'Mary Mild (THIS)' FROM DUAL UNION ALL SELECT 'Jack Jill (THIS)' FROM DUAL ) SELECT v1 , INSTR(v1, '(') start_bracket_pos , INSTR(v1, ')') end_bracket_pos , TRIM(SUBSTR(v1,INSTR(v1, '(')+1,INSTR(v1, ')')-INSTR(v1, '(')-1)) current_label , (LENGTH(v1) - LENGTH(REPLACE(v1, ')'))) / LENGTH(')') "ct_(" , (LENGTH(v1) - LENGTH(REPLACE(v1, ')'))) / LENGTH(')') "ct_)" FROM test_data;
I was wondering if I can change it to be able to extract the text between for example two sets of brackets - for the above test data, it would be useful to be able to extract the 'Joe' and 'Bob', but also 'CE' and 'WHO' at the end as well. It would be useful to have a column that contains the first support content and the 2nd set of content in another column.
Is there a switch that I can use for example an INSTR() to return the position of the first open bracket and the 2nd and so on?
Any advice much appreciated
Thank youA way, using reg exp:
SQL> WITH test_data AS 2 ( 3 SELECT 'Joseph Bloggs (Joe) (THIS)' v1 FROM DUAL UNION ALL 4 SELECT 'Robert Holnas (Bob) (THAT)' FROM DUAL UNION ALL 5 SELECT 'Mary Mild (THIS)' FROM DUAL UNION ALL 6 SELECT 'Jack Jill (THIS)' FROM DUAL 7 ) 8 SELECT v1 9 , regexp_substr(v1,'\((.*?)\)',1,1,null,1) bracket1 10 , regexp_substr(v1,'\((.*?)\)',1,2,null,1) bracket2 11 FROM test_data; V1 BRACKET1 BRACKET2 -------------------------- -------------------------- -------------------------- Joseph Bloggs (Joe) (THIS) Joe THIS Robert Holnas (Bob) (THAT) Bob THAT Mary Mild (THIS) THIS Jack Jill (THIS) THIS
The regular expression find something in parentheses (the? makes not greedy, it's important.)
1 means start over from the beginning of the string.
Next number means bracket1 "first occurrence", bracket2 is "second occurrence" - you can continue with 3, 4, etc.
null value uses only the default options for reg exp (here could be option for example for sensitive cases in search).
Final 1 means that the result is the first 'group' in the reg exp - this only receives us the text in brackets and not the media themselves. -
extract a portion of a string in a complete chain
Hello
I have a large string separated by "->" character. In my case I want to extract the characters between the 2nd and 3rd "->", characters after 4th "->". I tried a lot of location functions but could not achieve what I wanted. Help, please.
Example of
John->->-> Roger Sam Robert
to get the Sam as a value in the column and Roger in column B. There is also a special case like a few times, I have only
John-Robert-> Sam >
And want to get Sam in column A and not specified in column B.
Thank you
RaviHi Ravi,
The functions below can be used to achieve this:
Locate (str1, str2)
Locate(str1,str2,startPost) - Note We use Locate and not LocateN
SUBSTRING (long expr FOR startPos)Assuming that your string is - John-> Robert-> Sam-> Roger. To find
first position (FP) of->: LOCATE('->','John->Robert->Sam->Roger') //pos = 5
second position (SP) of->: LOCATE ('->', 'John-> Robert-> Sam-> Roger', LOCATE('->','John->Robert->Sam->Roger') + 2) / / pos = 13
-> third position (TP): LOCATE ('->', 'John-> Robert-> Sam-> Roger', LOCATE ('->', 'John-> Robert-> Sam-> Roger', LOCATE ('->', ' John-> Robert-> Sam-> Roger') + 2) + 2) //pos=18Your A pass where you get Sam, we need to check first if it the 3rd-> present or not. To do this, we verify the existence of the third position (TP) of->. If it is not present TP returns 0 your fx should be like:
-case when TP = 0 then
FOR the Substring('John->Robert->Sam->Roger' from (SP + 2) (length ('John-> Robert-> Sam-> Roger') - (SP + 1)))
on the other
SUBSTRING ("John-> Robert-> Sam-> Roger" (SP + 2) FOR ((TP-2) - SP))
endYour pass B where you get Roger, we need to check first if it the 3rd-> present or not. To do this, we verify the existence of the third position (TP) of->. If it is not present TP returns 0 your fx should be like:
-case when TP = 0 then
NULL VALUE
on the other
For the Substring('John->Robert->Sam->Roger' from (TP + 2) (length ('John-> Robert-> Sam-> Roger') - (TP + 1)))
endReplace the PS, SP and TP with real functions mentioned at the beginning. Also, replace the string with the name of your actual column.
It really works, but there may be better ways to do it.
Thank you
-
Use INSTR to extract a piece of the string?
The guys from morning and Happy Friday.
I have a situation where I have to take advantage of the string by using a select statement.
Here's the chain I have to get the content between the 2nd and 3rd backslash. So basically I have to extract marypoppins. Any ideas?
Here's where I started... and I've fallen on trying to find the 3rd backslash. I can easily start the INSTR 4 because I know that he will always be "C:\". »C:\USERS\marypoppins\Docs\Specification
select select substr(C:\USERS\marypoppins\Docs\Specification', INSTRB('C:\USERS\marypoppins\Docs\Specification', '\', 4), .....) from dual;
WITH abc AS (SELECT 'C:\USERS\marypoppins\Docs\Specification' a FROM DUAL) SELECT SUBSTR (a, INSTR (a, '\', 1, 2) + 1, INSTR (a, '\', 1, 3) - INSTR (a, '\', 1, 2) - 1 ) FROM abc;
-
How to extract the time to a string with lots of information?
Well guys,.
I have a question here...
I need to extract only the TIME to a string. But that chain has a lot of information
as a 'Identification' text data and time...
This "Identification" may be only letters or numbers or words of 2 or 3...
Anyone know a good way to do that?
I tried:
But only works if 'Identification' is only 1 Word...
I'm using LabVIEW 7.1
and the format is: ID - 14/04/2010 - 13:32:25
Thank you
Regular expression matching is available in 7.1?
Match pattern works, too.
-
Extract text from a text string
I have this text in a text field: "555-555-5555 PAUL ADRIANO 11596 MAIN ST 03/01/2013" there at - there a way for me to extract just the phone number and put in another field of own text?
Sure. In this case, you can divide the string with the comma as a delimiter and then deal with the elements in the resulting table.
It will look something like this:
var myString = "702-555-5555,GASTELUM NOEL & GALLEGO-EGURROLA MARIBEL,1328 N SLOAN LN,1/4/2013"; var items = myString.split(","); if (items.length==4) { var phoneNumber = items[0]; var name = items[1]; var address = items[2]; var date = items[3] }
-
How to upgrade to the substring of a string value?
tried that precedes a TOAD and I had ' ORA-00927: lack of equal sign. " Help, please!UPDATE table1 SET SUBSTR (TO_CHAR(field_value),3,2) = ' 50' and SUBSTR (TO_CHAR(field_value),5,2) = '50' where ( SUBSTR(TO_CHAR(field_value), 3, 2) = '100' ) or ( SUBSTR(TO_CHAR(field_value), 5, 2) = '100' )
data type for field_value's number. is version of Oracle 10 g
Thank youHere is an example of how you can do:
SQL> CREATE TABLE x 2 AS 3 SELECT 'SOME50HERE' AS field_x 4 FROM dual; Table created. SQL> SELECT * FROM x; FIELD_X ---------- SOME50HERE 1 row selected. SQL> UPDATE x 2 SET field_x = SUBSTR(field_x,1,4) 3 || '75' 4 || SUBSTR(field_x,7) 5 ; 1 row updated. SQL> SELECT * FROM x; FIELD_X ---------- SOME75HERE
Basically, it must break your string into three parts:
1. the foregoing text you want to change.
2. the text that you want to change.
3. the part after the text you want to change.Then you concatenate them all together.
If #1 is not a fixed number of characters, you can still use SUBSTR, by searching for the string you want to edit as follows:
UPDATE x SET field_x = SUBSTR(field_x,1,INSTR(field_x,'50') - 1) || '75' || SUBSTR(field_x,7) ;
-
Substring of a string in report
Hello
I have some values such as ' / shared, outstanding, _portal, outstanding ' & ' shared/SalesAnalytics/_portal/sales' under a column in OBIEE report.
Now instead of display the full path to the result I want to display only the string after the _portal/"...like"in the above case.
'Outstanding' & 'dirty '.
Please let me know how can we achieve this in the answers?
Thank youHi user,
Try something like this,
Substring ("YourColumnName" of (position (in 'YourColumnName', ' _') + 8))
Rgds,
DpKa
Maybe you are looking for
-
How to access the Bios on HPE - 520
How can I access the BIOS on my HPE-520? My system contains only a HP 2.4 GHz wireless keyboard, so after the start of my keyboard is not found before Windows is running. This PC is not a PS2 Connector and a USB keyboard will not work until Windows i
-
How to install ati updates if I have switchable graphics (i5 y560 / ATI 5730).
Is it possible to update my ATI drivers if I have a y560 w / switchable graphics? Official installer of course does not work. I read of a "Workaround" to run the official Installer, so that it can recover the files and then manually update pending. B
-
Outlook Express - left side of my impression of the texts has been cut
We need help on our problem. When we printed in the paper version of a Network Copier, the left side of the texts on paper has been cut vertically. Any solution for example. changing the default settings for alignment or...? Please notify.
-
When I scan in OfficeJet 7210, the document is saved as an entirely black with white horizontal lines. O/s's Mavericks. Apple technical support could not find a problem with the computer system. When I scan the document, his image appears perfectly
-
Hello. I recently got a Compaq Presario SR5333WM of another desktop PC, and I want to restore the computer to factory settings. In other words, format the memory. Does anyone know how easily on this computer model? (If it's important it's a Windows V