Split data and insert into different rows
I have a string like 'sfdsf,sfdsf,sfsd,qweqeqw,iuoi,"
I have created a single column table
I have to extract data from first untill comma(,) occurs and insert into the table like the following
sfdsdf
sfdsf
sfsd
qweqeqw
iuoi
Please help me how to do it
Or a Single SQL query
SELECT trim(',' from DECODE(ROWNUM,1,SUBSTR(STR,1,INSTR(STR,',',1)),
LENGTH(STR)-LENGTH(REPLACE(STR,','))+1,SUBSTR(STR,INSTR(STR,',',-1,1)),
SUBSTR(STR,INSTR(STR,',',1,ROWNUM-1), INSTR(STR,',',1,ROWNUM)-INSTR(STR,',',1,ROWNUM-1))
)) STR1
FROM (SELECT 'sfdsf,sfdsf,sfsd,qweqeqw,iuoi' STR FROM DUAL),ALL_TABLES
WHERE ROWNUM <= LENGTH(STR)-LENGTH(REPLACE(STR,','))+1
ORDER BY ROWNUM
Similar Messages
-
How to parse a delimited string and insert into different columns?
Hi Experts,
I need to parse a delimited string ':level1_value:level2_value:level3_value:...' to 'level1_value', 'level2_value', etc., and insert them into different columns of one table as one row:
Table_Level (Level1, Level2, Level3, ...)
I know I can use substr and instr to get level value one by one and insert into Table, but I'm wondering if there's better ways to do it?
Thanks!user9954260 wrote:
However, there is one tiny problem - the delimiter from the source system is a '|' When I replace your test query with | as delimiter instead of the : it fails. Interestingly, if I use ; it works. See below:
with t as (
select 'str1|str2|str3||str5|str6' x from dual union all
select '|str2|str3|str4|str5|str6' from dual union all
select 'str1|str2|str3|str4|str5|' from dual union all
select 'str1|str2|||str5|str6' from dual)
select x,
regexp_replace(x,'^([^|]*).*$','\1') y1,
regexp_replace(x,'^[^|]*|([^|]*).*$','\1') y2,
regexp_replace(x,'^([^|]*|){2}([^|]*).*$','\2') y3,
regexp_replace(x,'^([^|]*|){3}([^|]*).*$','\2') y4,
regexp_replace(x,'^([^|]*|){4}([^|]*).*$','\2') y5,
regexp_replace(x,'^([^|]*|){5}([^|]*).*$','\2') y6
from t;
The "bar" or "pipe" symbol is a special character, also called a metacharacter.
If you want to use it as a literal in a regular expression, you will need to escape it with a backslash character (\).
Here's the solution -
test@ORA11G>
test@ORA11G> --
test@ORA11G> with t as (
2 select 'str1|str2|str3||str5|str6' x from dual union all
3 select '|str2|str3|str4|str5|str6' from dual union all
4 select 'str1|str2|str3|str4|str5|' from dual union all
5 select 'str1|str2|||str5|str6' from dual)
6 --
7 select x,
8 regexp_replace(x,'^([^|]*).*$','\1') y1,
9 regexp_replace(x,'^[^|]*\|([^|]*).*$','\1') y2,
10 regexp_replace(x,'^([^|]*\|){2}([^|]*).*$','\2') y3,
11 regexp_replace(x,'^([^|]*\|){3}([^|]*).*$','\2') y4,
12 regexp_replace(x,'^([^|]*\|){4}([^|]*).*$','\2') y5,
13 regexp_replace(x,'^([^|]*\|){5}([^|]*).*$','\2') y6
14 from t;
X Y1 Y2 Y3 Y4 Y5 Y6
str1|str2|str3||str5|str6 str1 str2 str3 str5 str6
|str2|str3|str4|str5|str6 str2 str3 str4 str5 str6
str1|str2|str3|str4|str5| str1 str2 str3 str4 str5
str1|str2|||str5|str6 str1 str2 str5 str6
4 rows selected.
test@ORA11G>
test@ORA11G>isotope
PS - it works for semi-colon character ";" because it is not a metacharacter. So its literal value is considered by the regex engine for matching.
Edited by: isotope on Feb 26, 2010 11:09 AM -
Splitting data in one row and inserting into seperate rows into a new table
i have a table table1 like the following
column1 column2 column3
a b,cbdm,d hj
ba hello man
i have to insert data from this table to table2 in the following format
Column1 column2 column3
a b hj
a cbdm hj
a d hj
ba hello man
It is like if data in column2 is seperated by comma i have to insert it into each sperate row
I have to write a single procedure which will do the above. Please,Please help me
I am very new to SQLI am absolutely agreeing with Billy.
But I think u will be able to learn a lot if u try to understand the following code
sql>select * from t1;
C1 C2 C3
a b,cdbm,d hj
ba hello man
x aa,d,df yy
sql>select * from t2;
no rows selected
sql>insert into t2
select col1,col2,col3
from (
select t1.c1 col1,t1.c2 col4,t1.c3 col3,
substr(t1.c2,
case n when 1 then 1 else instr(t1.c2,',',1,n-1)+1 end,
(case instr(t1.c2,',',1,n) when 0 then length(t1.c2)+1 else instr(t1.c2,',',1,n) end) -
(case n when 1 then 1 else instr(t1.c2,',',1,n-1)+1 end)) col2,n
from t1,(select c1,c2,c3,
row_number() over(partition by c1,c2,c3 order by c1) n
from t1 connect by level <=
(length(t1.c2)-length(replace(t1.c2,',','')))) t2
where t1.c1 = t2.c1)
where not(n != 1 and col4=col2);
sql>select * from t2;
C1 C2 C3
a b hj
a cdbm hj
a d hj
ba hello man
x aa yy
x d yy
x df yy -
Best Practice to fetch SQL Server data and Insert into Oracle Tables
Hello,
I want to read sqlserver data everry half an hour and write into oracle tables ( in two different databases). What is the best practice for doing this?
We do not have any database dblinks from oracle to sqlserver and vice versa.
Any help is highly appreciable?
ThanksWell, that's easy:
use a TimerTask to do the following every half an hour:
- open a connection to sql server
- open two connections to the oracle databases
- for each row you read from the sql server, do the inserts into the oracle databases
- commit
- close all connections -
Parse xml data and insert into database
Hi Friends,
I have an xml document which needs to be parsed and the data need to be inserted into an oracle database table.
Please tell me which will be the easiest and optimal way of doing this.
Thanks,
AchayanTake a look at the JDOM xml parsing library - google for JDOM download or something.
This will allow you to build an object representation of the XML doc, from which you can then extract the data.
J -
Read XML data and Insert into SQL Database
Hi Everybody,
i am new to Oracle SOA.
Can anybody help me out to how to insert xml data into sql server using BPEL and JDeveloper (with clear steps).
thanks in advance
Vishnu KumarHi Peter,
you are right,at high level i was able to figure at these things.
But i don't know how to implement it using jdeveloper.
It will be more helpful if you can give me detailed steps to do it.
Thanks
Vishnu Kumar -
How to read the data from XML file and insert into oracle DB
Hi All,
I have below require ment.
I will receive data in the XML file. then i need to read that data and insert into oracle tables. please let me know how this can be handled.
Many Thanks.Sounds a lot like this question, only with less details.
how to read data from XML variable and insert into table variable
We can only help if you provide us details to help as we cannot see what you are doing and only know what you tell us. Plenty of examples abound on the forums that cover the topics you seek as well. -
How to read ecel sheet and insert into oracle table
hi all,
am working on forms builder 6i. and i want , from a trigger to read from a a sheet excel file the data and insert into a table that i had aleady created.
i whrite a code that can till now open the excel file but i cant read the data to insert it into the table.
am using TEXT_IO.IS_OPEN to open the file
TEXT_IO.GET_LINE to take each line
and subst(x as variable) to read the first line , but the subsrt return nohing
any solution??There's already a topic made on this: how to copy data from excel to oracle forms
-
Read data from E$ table and insert into staging table
Hi all,
I am a new to ODI. I want your help in understanding how to read data from an "E$" table and insert into a staging table.
Scenario:
Two columns in a flat file, employee id and employee name, needs to be loaded into a datastore EMP+. A check constraint is added to allow data with employee names in upper case only to be loaded into the datastore. Check control is set to flow and static. Right click on the datastore, select control and then check. The rows that have violated the check constraint are kept in E$_EMP+ table.
Problem:
Issue is that I want to read the data from the E$_EMP+ table and transform the employee name into uppercase and move the corrected data from E$_EMP+ into EMP+. Please advise me on how to automatically handle "soft" exceptions in ODI.
Thank youHi Himanshu,
I have tried the approach you suggested already. That works. However, the scenario I described was very basic. Based on the error logged into the E$_EMP table, I will have to design the interface to apply more business logic before the data is actually merged into the target table.
Before the business logic is applied, I need to read each row from the E$EMP table first and I do not know how to read from E$EMP table. -
Split one column value and insert into multiple columns
hi
am new to plsql .
i want to split a characters from one column and insert into multiple columns
i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
for eg: before split
col1 :
col2 :
col3 :
col4 :
colu5: adsdf,fgrty,erfth,oiunth,okujt
after split
col1 :adsd
col2 :fgrty
col3 :erfth
col4 :oiunth
col5 : adsdf,fgrty,erfth,oiunth,okujt
can anyone help me
thanks
Edited by: 800324 on Dec 23, 2010 8:28 AM
Edited by: 800324 on Dec 23, 2010 8:36 AMHow about:
SQL> create table t
2 (col1 varchar2(30)
3 ,col2 varchar2(30)
4 ,col3 varchar2(30)
5 ,col4 varchar2(30)
6 ,col5 varchar2(30)
7 );
Table created.
SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
1 row created.
SQL> insert into t (col5) values ('x,y');
1 row created.
SQL> insert into t (col5) values ('a,b,c,d');
1 row created.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf,fgrty,erfth,oiunth,okujt
x,y
a,b,c,d
3 rows selected.
SQL>
SQL> merge into t a
2 using ( with t1 as ( select col5||',' col5
3 from t
4 )
5 select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
6 , substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
7 , substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
8 , substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
9 , rtrim(col5, ',') col5
10 from t1
11 ) b
12 on ( a.col5 = b.col5 )
13 when matched then update set a.col1 = b.col1
14 , a.col2 = b.col2
15 , a.col3 = b.col3
16 , a.col4 = b.col4
17 when not matched then insert (a.col1) values (null);
3 rows merged.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf fgrty erfth oiunth adsdf,fgrty,erfth,oiunth,okujt
x y x,y
a b c d a,b,c,d
3 rows selected.
SQL> Assuming you're on 9i... -
How to extract data from xml and insert into Oracle table
Hi,
I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
I need to extract the values of these columns and insert into the table
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>Re: Insert from XML to relational table
http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta= -
Insert date and time into write to spreadsheet
Easy question here
I need save 4 arrays of data and insert the date and time that it was taken (LV 8.6)
for example
9/4/09 10:00:01 AM 4 6 7 2
9/4/09 10:00:02 AM 4 6 7 2
9/4/09 10:00:03 AM 4 6 7 2
9/4/09 10:00:04 AM 4 6 7 2
Any ideas, I can't wire the timestamp or date/time string right into the create array
Thanks
Chris
Solved!
Go to Solution.Ok
the basic problem that I see is the the LabVIEW TimeStamp type is a cluster. Converting it to a dbl gives you a value in seconds elapsed since 1904 Jan 1 12:00AM GMT and, your spreadsheet cannot interprate that (or display that) as a "TIME." So, you want to convert it to a string (easy TS->String check the help for format options) BUT, you might want to pass all of your data as numbers into your spreadsheet so you can post-calculate or graph other outputs vs. TIME! This little chunk of code .....
converts a LV Timestamp to a number that Excel interperates as "the amount of days elapsed since 0 Jan 1900 @ 12:00AM LOCAL." You will need to format the cell in Excel to display it as a date-time But it can be operated on and graphed against with only Excel's limitations (Excel followed the Lotus bug of erroneously assuming 1900 was a leap year, and Leap seconds are unrecognized)
Enjoy!
Message Edited by Jeff Bohrer on 08-06-2009 02:28 PM
Jeff -
Inserting Date and Time into a date field
Okay I am a bit of a Oracle newbie. I am trying to insert the following date and time into a date field and I don't know how to format the second part of the to_Date() function.
Date/Time: 5/29/2003 7:58:45 PM
Thanks,
BrandenI believe you would want
to_date( '5/29/2003 7:58:45 PM', 'MM/DD/YYYY HH:MI:SS AM' )
Note that tahiti.oracle.com has all of Oracle's documentation, including the very useful SQL & PL/SQL reference manuals, available for free.
Justin -
Get the data from excel and insert into the database
I want to read the data from excel file, get the data from excel and insert into the database.
You can use the Apache POI HSSF API to read data from Excel files and you can use the Sun JDBC API to insert data in database.
This has nothing to do with JSP/JSTL. -
Hi, extract data from xml file and insert into another exiting xml file
i am searching code to extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
1st xml file which has two lines(text1.xml)
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:PrintDataRequest xmlns:xs="http://com.unisys.com/Anid"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
<xs:Person>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
These two lines has to be inserted in the existing another xml(text 2.xml) file(at line 3 and 4)
Regards,
bubblyJadz_Core wrote:
RandomAccessFile? If you know where you want to insert it.Are you sure about this? If using this, the receiving file would have to have bytes inserted that exactly match the number of bytes replaced. I'm thinking that you'll likely have to stream through the second XML with a SAX parser and copy information (or insert new information) as you stream with an XML writer of some sort.
Maybe you are looking for
-
Using Safari (Leopard) to login to my club forum
Sometimes when I login to my club website to access the club forum via Safari 3 in Leopard 10.5.1 the user log on the website shown a large number of logins at exactly the same time. (can be up to as many as five) This does not happen every time. Som
-
Purchase requisitions are not created for Component by MRP
Hi, I have created planned orders for assy. When I run the MRP the purchase requisitions are not created by MRP for the components. If I check the planned order the components tab is showing all the raw materials list as per the BOM. The master data
-
Illustrator CS5-Multiply used on tiffs are now hazy-gray in CMYK?
I have created AI documents in both RGB and CMYK document color modes. In both modes, I have a colored background or a photo. A TIFF file is Placed in the AI document on top of the background. It contains black line art on a white background (flatten
-
PI Mapping : Generating multiple nodes by one node
Hi, I'm looking for the solution how to generate two nodes by one node in source messages. In the following sample messages, two nodes in source are expected to generate 4 nodes in output. Source Structure <item> <id> <name> </item> Target
-
Multiple time hierarchies in demantra.
Hi Gurus, We have a unique requirement. We need to have two hierarchies. Daily->Monthly (Gregorian)->Quarterly->Yearly Daily->Weekly->4-4-5->Yearly Is it possible to have two time hierarchies? One hierarchy to be used for SOP and the other for DM. Th