I need query to split the string
I need query to split the input string into comma seperated triplets values.
Input String: Database
Output : Dat, ata,tab,aba,bas,ase
SQL> with t
2 as
3 (
4 select 'Database' str
5 from dual
6 )
7 select substr(str, level, 3) str
8 from t
9 where length(substr(str, level, 3)) = 3
10 connect by level <= length(str);
STR
Dat
ata
tab
aba
bas
ase
6 rows selected.
And if you want it as a single string then..
SQL> with t
2 as
3 (
4 select 'Database' str
5 from dual
6 )
7 select ltrim(sys_connect_by_path(str, ','), ',') str
8 from (
9 select row_number() over(order by level) rno
10 , substr(str, level, 3) str
11 from t
12 where length(substr(str, level, 3)) = 3
13 connect by level <= length(str)
14 )
15 where connect_by_isleaf = 1
16 start with rno = 1
17 connect by rno = prior rno + 1;
STR
Dat,ata,tab,aba,bas,ase
Similar Messages
-
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
How to Split the string using Substr and instr using loop condition
Hi every body,
I have below requirement.
I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
for example I am reciveing value as follows
ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
after modification i need above transactions should in below format
ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
Please help me to sort out this issue.
Many Thanks.
Edited by: user627525 on Dec 15, 2011 11:49 AMTry this - may not be the best way but...:
create or replace type myTableType as table of varchar2(255)
declare
v_array mytabletype;
v_new_str varchar2(4000);
function str2tbl
(p_str in varchar2,
p_delim in varchar2 default '.')
return myTableType
as
l_str long default p_str || p_delim;
l_n number;
l_data myTableType := myTabletype();
begin
loop
l_n := instr( l_str, p_delim );
exit when (nvl(l_n,0) = 0);
l_data.extend;
l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
l_str := substr( l_str, l_n+length(p_delim) );
end loop;
return l_data;
end;
begin
v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
FOR i IN 1 .. v_array.COUNT LOOP
v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
END LOOP;
dbms_output.put_line(RTRIM(v_new_str, ','));
end;
OUTPUT:
=======
'12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
Edited by: user130038 on Dec 15, 2011 12:11 PM -
How to split the string from character position.
HI ALL,
I need to split the string like this.
example:
String = "HelloWorld"
mid("HelloWorld", 2, 5);
it should print "ello"
menas mid is functiuon it will split "HelloWorld" from 2nd character to 5th character and prints "ello".
This one how to do in labview.
Regards
PunithString Subset is the function you are looking for.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to split the string by datetime in sql
Hi,
How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
can anyone help me in this please.
Thanks,declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated
output:
1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910201'
2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
3) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910202'
5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
6) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910203'
8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
Thanks,
See this illustration
declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
'(' + p.u.value('.[1]','varchar(max)') AS comments,
lbiref
FROM
SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
FROM @callcentre c
)t
CROSS APPLY x.nodes('/Root/Data')p(u)
and the output
Date comments lbiref
28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How To Split the String for "."
Hi Friends
I am Using Following Code to Split one String.
String str = "Jeetendra.choudhary";
String[] sp_str = str.split(".");
wdComponentApi.getMessageManager.reportSuccess(str[0]);
wdComponentApi.getMessageManager.reportSuccess(str[1]);
but its throwing null pointer exception.
when i am using following code its working fine.
String str = "Jeetendra/choudhary";
String[] sp_str = str.split("/");
wdComponentApi.getMessageManager.reportSuccess(str[0]);
wdComponentApi.getMessageManager.reportSuccess(str[1]);
what may be the issue and how to split the string with "." ?
Thanks & Regards
Jeetendra"." is a special character.
Use
str.split("\\.");
Regards
Benjamin
Edited by: Benjamin Hansen on Dec 29, 2009 7:52 AM -
How can I Split the String in to different strings
Hi All,
I have created a table A
If i select * from A
Result is :
1,2,3,4 - Line 1
11,222,3222,422 - Line 2
Now i what to split the data like by using substr and instr
A , B , C , D
1 2 3 4
11 222 3222 422
Can any one help me in this query,i need the full query..pls
Regardsexcuse me..
it's unclear ..
Now i what to split the data like by using substr and instr
A , B , C , D
1 2 3 4
11 222 3222 422
are u trying to select same result from table A to other tables B,C,D
what r the fields number u have,what their datatypes..?
Regards,
Abdetu.. -
Needs Query to get the cycle time automatically based on the value provided in the UDF on OWOR table
Dear all,
Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
Details of UDF:-
1.Start date =10/07/14 (Field Name U_EA_REST)
2.Start time =10:00 (Field Name U_EA_REASTARTTIME)
3.End date =11/07/14 (Field Name U_EA_REET)
4.End Time=14:00 (Field Name U_EA_REAENDTIME
Cycle Time=_______ (Field Name U_EA_REACYCLETIME)
Regards,
BanugopanRajendranDear all,
Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
Details of UDF:-
1.Start date =10/07/14 (Field Name U_EA_REST) - Date Type
2.Start time =10:00 (Field Name U_EA_REASTARTTIME) - Hour Type
3.End date =11/07/14 (Field Name U_EA_REET) - Date Type
4.End Time=14:00 (Field Name U_EA_REAENDTIME - Hour Type
Cycle Time=_______ (Field Name U_EA_REACYCLETIME) - Hour Type
Regards,
BanugopanRajendran -
Need query to compare the columns of 2 diff tables of 2 different schemas.
There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2).
I want the query to compare the columns of two different tables of two different schemas and provide whether the data as well as the count of data in
the column are same .
if not provide the data which is not similar in the columns of two different table.
NOTE:
I need queries for both the cases.
(i) The datatypes in columns of two different tables are same.
(ii) The datatypes in columns of two different tables are diffrent.Welcome to the forum!
Whenever you post provide your 4 digit Oracle version.
>
I need queries for both the cases.
>
Great - write the queries!
The forum is not a coding service where you ask people to write code for you for free.
YOU need to write the code. Then if you have a problem with the code you have written post the code you have written (using \ tags) and explain the problem you are having.
Read the FAQ about how to ask a question on the forums. -
Could not able to split the string at #!
Hi,
Hi Below is the value coming in a field character string 130 and I have used SPLIT at '#' and also Split at tab which has a value horzontal tab.
Below is the string Value..
'Feedback on Mr Richard Harris#360 category Partner#Department Human Resources#Office London#Review period 01.01.2010 to 31.12.2010'.
Please let me know how to resolve this?
Regards,
SrinivasThis works as it should:
DATA:
lv_field(130) TYPE c VALUE
'Feedback on Mr Richard Harris#360 category Partner#Department Human
resources#office london#review period 01.01.2010 to 31.12.2010',
lv_01(50) type c,
lv_02(50) type c,
lv_03(50) type c,
lv_04(50) type c,
lv_string TYPE string.
lv_string = lv_field.
split lv_string at '#' into
lv_01 lv_02 lv_03 lv_04.
write: / lv_01 ,
/ lv_02 ,
/ lv_03 ,
/ lv_04. -
Need some help with the String method
Hello,
I have been running a program for months now that I wrote that splits strings and evaluates the resulting split. I have a field only object (OrderDetail) that the values in the resulting array of strings from the split holds.Today, I was getting an array out of bounds exception on a split. I have not changed the code and from I can tell the structure of the message has not changed. The string is comma delimited. When I count the commas there are 26, which is expected, however, the split is not coming up with the same number.
Here is the code I used and the counter I created to count the commas:
public OrderDetail stringParse(String ord)
OrderDetail returnOD = new OrderDetail();
int commas = 0;
for( int i=0; i < ord.length(); i++ )
if(ord.charAt(i) == ',')
commas++;
String[] ordSplit = ord.split(",");
System.out.println("delims: " + ordSplit.length + " commas: " + commas + " "+ ordSplit[0] + " " + ordSplit[1] + " " + ordSplit[2] + " " + ordSplit[5]);
The rest of the method just assigns values to fields OrderDetail returnOD.
Here is the offending string (XXX's replace characters to hide private info)
1096200000000242505,1079300000007578558,,,2013.10.01T23:58:49.515,,USD/JPY,Maker,XXX.XX,XXX.XXXXX,XXXXXXXXXXXXXXXX,USD,Sell,FillOrKill,400000.00,Request,,,97.7190000,,,,,1096200000000242505,,,
For this particular string, ordSplit.length = 24 and commas = 26.
Any help is appreciated. Thank you.Today, I was getting an array out of bounds exception on a split
I don't see how that could happen with the 'split' method since it creates its own array.
For this particular string, ordSplit.length = 24 and commas = 26.
PERFECT! That is exactly what it should be!
Look closely at the end of the sample string you posted and you will see that it has trailing empty strings at the end: '1096200000000242505,,,'
Then if you read the Javadocs for the 'split' method you will find that those will NOT be included in the resulting array:
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
split
public String[] split(String regex)
Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
Just a hunch but your 'out of bounds exception' is likely due to your code assuming that there will be 26 entries in the array and there are really only 24. -
Need reg_exp for checking the string contains only alphanumeric or not
Dear All,
I need to check the given string in if condtion contains only the alphanumeric or not pls help me..
like
if reg_exp then
end if;
thanks,
OracleHi,
REGEXP_LIKE ( str
, '[^[:alnum:]]'
)returns TRUE if the string str contains any character other than an alphanumeric.
You can use this wherever conditions are allowed, such as a WHERE clause or a CASE expression. For example:
SELECT str
. CASE
WHEN REGEXP_LIKE ( str
, '[^[:alnum:]]'
THEN 'Contains speace, punctuation or special symbol'
ELSE 'Okay'
END AS is_alnum
FROM table_x
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using.
Edited by: Frank Kulash on Dec 30, 2011 4:37 AM -
How to split the string?
Hi Experts,
Can anyone explain me with code how to separate the single character from the given input string?
For Example: Input String str = 'RAGHU'
Output should be:
R
RA
RAGH
RAGHU
RAGH
RAG
RA
R
Can anyone help me with code for above required output?
Thanks in Advance,
Regards,
Raghu.HI,
sy-index will give u the iteration number.
first of all in this program u are counting the length of the string and it was in variable LEN.
we are always printing the string from 0 index(1st character) to POS number of characters.
length is 5 so LNG = 5 * 2 = 10 and LNG = 10 - 1 = 9.and first sy-index = 1.so,1 <= 5 so POS = 0 + 1 = 1. it is printing the first char
second sy-index = 2.so,2 <= 5 so POS = 1 + 1 = 2. it is printing the first two chars
third sy-index = 3.so,3 <= 5 so POS = 2 + 1 = 3. it is printing the first three chars
forth sy-index = 4.so,4 <= 5 so POS = 3 + 1 = 4. it is printing the first four chars
fifth sy-index = 5.so,5 <= 5 so POS = 4 + 1 = 5. it is printing the first five chars
sixth sy-index = 6.so,6 > 5 so POS = 5 - 1 = 4. it is printing the first four chars
seventh sy-index = 7.so,7 > 5 so POS = 4 - 1 = 3. it is printing the first three chars
eighth sy-index = 8.so,8 > 5 so POS = 3 - 1 = 2. it is printing the first two chars
ninth sy-index = 9.so,9 > 5 so POS = 2 - 1 = 1. it is printing the first char
rgds,
bharat. -
Query to find the string in the schema for different tables
Hi all,
Is the output possible :
1) Schema with N number of tables where N>100
2) You have string Say 'abc' and u dont know which column of the 100 tables of the schema this string falls.
3)you want to retrieve the table name, column name and expected string
Output:
Table name column name expected string
A a_id “abc”
D d_add “abc”You could probably adapt this solution that michaels provided ages ago (and which you'd have found if you bothered to search)...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table" -
Query to split the field value
Hi all
In employees table I am having employee_name column data as follows
Aaron, Mrs. Jamie (Jamie)
Aaron, Mrs. Jenette (Jenette)
Abbott, Ms. Rachel (Rachel)
Breton, Mr. Jean
Britz, Mrs. Sarie (Sarie)
--> Now, I want to display the employee name like "Mrs. Jamie" (with out Surname and with out bracket included text),
--> How to achieve this by SQL query. Help me out plz
Thanks in Advance
JagadeeshNeed more sample cases:
One way (without regexp).
WITH t AS
(SELECT 'Aaron, Mrs. Jamie (Jamie)' str FROM DUAL
UNION ALL
SELECT 'Aaron, Mrs. Jenette (Jenette)' FROM DUAL
UNION ALL
SELECT 'Abbott, Ms. Rachel (Rachel)' FROM DUAL
UNION ALL
SELECT 'Breton, Mr. Jean' FROM DUAL
UNION ALL
SELECT 'Britz, Mrs. Sarie (Sarie)' FROM DUAL)
SELECT CASE
WHEN INSTR (str, '(') > 0 THEN
SUBSTR (str,
INSTR (str, ',') + 2,
INSTR (str, '.') - INSTR (str, ',') - 1)
|| ' '
|| SUBSTR (str,
INSTR (str, '(') + 1,
LENGTH (str) - INSTR (str, '(') - 1)
ELSE
SUBSTR (str, INSTR (str, ',') + 2)
END
str
FROM t;
Output:
STR
Mrs. Jamie
Mrs. Jenette
Ms. Rachel
Mr. Jean
Mrs. Sarie
Cheers,
Manik
Maybe you are looking for
-
JDeveloper 10.1.3.3.0.3 Blue Screen of Death on Windows 7 64-bit
Hi, I am using JDeveloper 10.1.3.3.0.3 on a Windows 7 (64-bit) machine. Whenever I try and use the PgUp or PgDn keys or even use the main vertical scrollbar it produces a Blue Screen of Death. Saying the Video Scheduler has encountered an unexpected
-
Hello Can anyone suggest a good way to put up a web comic? Is there a program or plugin that can navigate the Previous / Next buttons? Or do I need to create this on my own in iWeb? I have played around with the slideshow option, but the image size t
-
Sending MIME information while doing FTP in OSB
Hi All, I'm trying to FTP a file to webmethods through an OSB process. If FTP is done from a command prompt or FileZilla to the location using MIME type like below, it works "ABC;application:x-wmflatfile" where "ABC" is the file name and "application
-
Dreamweaver pages messing up when add image
hello abode world. when im designing a site, i set all the dimensions to the right sizes i want and slice in photoshop, export html and images then open in dreamweaver. when i go to add images, the page gets messed up and all of the slices get all sc
-
Internal and External sources for OBIEE
Hi, When we say OBIEE can integrates data feeds from internal and external sources..what exactly does this mean. Can OBIEE even do that? Thanks