Generate xml from a table and insert the xml into another table
I want to generate an xml file from a table and insert it into another table all in one tsql
insert into table B(xmlfile)
select * from tableA
FOR
XML
PATH('ac'),TYPE,ELEMENTS
XSINIL,ROOT('Accum')
Is not working any help
I have solved my issue all I did was to change my column datatype to xml
Similar Messages
-
Search in Nested Tables and Insert the result into new Nested Table!
How can I search in Nested Tables ex: (pr_travel_date_range,pr_bo_arr) using the SQL below and insert the result into a new Nested Table: ex:g_splited_range_arr.
Here are the DDL and DML SQLs;
Don't worry about the NUMBER( 8 )
CREATE OR REPLACE TYPE DATE_RANGE IS OBJECT ( start_date NUMBER( 8 ), end_date NUMBER( 8 ) );
CREATE OR REPLACE TYPE DATE_RANGE_ARR IS TABLE OF DATE_RANGE;
DECLARE
g_splited_range_arr DATE_RANGE_ARR := DATE_RANGE_ARR( );
g_travel_range DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
g_bo_arr DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
FUNCTION split_date_sql( pr_travel_date_range DATE_RANGE,
pr_bo_arr DATE_RANGE_ARR )
RETURN DATE_RANGE_ARR
IS
l_splited_range_arr DATE_RANGE_ARR;
BEGIN
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM (WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
UNION ALL
SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date);
RETURN l_splited_range_arr;
END;
BEGIN
g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP
DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-' || g_splited_range_arr(index_g_splited_range_arr).end_date );
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;Or can I create a VIEW with parameters of Nested Tables in it so I can simply call
SELECT *
BULK COLLECT INTO g_splited_range_arr
FROM view_split_date(g_travel_range,g_bo_arr);@riedelme
For your questions:
1) I don't want to store in the database as a nested table
2) I don't want to retrieve data from the database. Data will come from function split_date() parameter and data will be processed in the function and function will return it in nested table format. For more detail please look at the raw function SQL.
I have a SQL like:
WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM travel
UNION ALL
SELECT tr_end_date, 0 FROM travel
UNION ALL
SELECT bo_start_date - 1, 1 FROM black_out_dates
UNION ALL
SELECT bo_end_date + 1, -1 FROM black_out_dates),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val)
AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val)
AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date;I want to change the tables black_out_dates and travel to Nested Array so I can use it in a function with Nested Array travel and Nested Array black_out_dates parameters and the function will return Nested Array of date ranges.
Here is what I want in raw SQL:
DECLARE
g_splited_range_arr DATE_RANGE_ARR := DATE_RANGE_ARR( );
g_travel_range DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
g_bo_arr DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
FUNCTION split_date_sql( pr_travel_date_range DATE_RANGE,
pr_bo_arr DATE_RANGE_ARR )
RETURN DATE_RANGE_ARR
IS
l_splited_range_arr DATE_RANGE_ARR;
BEGIN
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM (WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
UNION ALL
SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date);
RETURN l_splited_range_arr;
END;
BEGIN
g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP
DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-' || g_splited_range_arr(index_g_splited_range_arr).end_date );
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;I must change the tables black_out_dates and travel in a way so it will be something like
FROM TABLE( pr_travel_date_range )to get the result into l_splited_range_arr so it will be something like
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM ( -
Select from 2 tables and insert same data into 2 other tables(BPEL Process)
Hi All,
Please suggest me how to select from 2 tables and insert the same data into 2 tables. I am successful in selecting data from 2 tables, but i am not able to insert the same data into 2 other tables. There is foreign key constraint between 2 tables.
Thanks in Advance,
MAHI have created DB Adapter for selecting from 2 tables and also DB adapter for insert and i have created parent child relationship between 2 tables.
I am getting this error
<Faulthttp://schemas.xmlsoap.org/soap/envelope/>
<faultcode>env:Server</faultcode>
<faultstring>com.oracle.bpel.client.delivery.ReceiveTimeOutException: Waiting for response has timed out. The conversation id is 6f3fe20c1b031057:-6cc7dfb5:11b8bf5fbe1:-7fa4. Please check the process instance for detail.</faultstring>
</Fault> -
How can i open a DOC or TXT file and insert the data into table?
How can i open a DOC or TXT file and insert the data into table?
I have a doc file . the doc include some columns and some rows.(for example 'ID,Name,Date,...').
I'd like open DOC file and I'd like insert them into the table with same columns.
Thanks.Use the SQL*Loader utility or the UTL_FILE package.
-
The attached file is work inprogress, with some dummy data sp that I can test it out without having to connect to equipment.
The second tab is the one that I am having the problem with. the output array from the replace element appears to be starting at the index position of 1 rather than 0 but that is ok it is still show that the new data is placed in incrementing element locations. However the main array that I am trying to build that is suppose to take each new calculation and place it in the next index(row) does not ap
pear to be working or at least I am not getting any indication on the inidcator.
Basically what I am attempting to do is is gather some pulses from adevice for a minute, place the results for a calculation, so that it displays then do the same again the next minute, but put these result in the next row and so on until the specifiied time has expired and the loop exits. I need to have all results displayed and keep building the array(display until, the end of the test)Eventually I will have to include a min max section that displays the min and max values calculated, but that should be easy with the min max function.Actually I thought this should have been easy but, I gues I can not see the forest through the trees. Can any one help to slear this up for me.
Attachments:
regulation_tester_7_loops.vi 244 KBI didn't really have time to dig in and understand your program in depth,
but I have a few tips for you that might things a bit easier:
- You use local variables excessively which really complicates things. Try
not to use them and it will make your life easier.
- If you flowchart the design (very similar to a dataflow diagram, keep in
mind!) you want to gather data, calculate a value from that data, store the
calculation in an array, and loop while the time is in a certain range. So
theres really not much need for a sequence as long as you get rid of the
local variables (sequences also complicate things)
- You loop again if timepassed+1 is still less than some constant. Rather
than messing with locals it seems so much easier to use a shiftregister (if
absolutely necessary) or in this case base it upon the number of iterations
of the loop. In this case it looks like "time passed" is the same thing as
the number of loop iterations, but I didn't check closely. There's an i
terminal in your whileloop to read for the number of iterations.
- After having simplified your design by eliminating unnecessary sequence
and local variables, you should be able to draw out the labview diagram.
Don't try to use the "insert into array" vis since theres no need. Each
iteration of your loop calculates a number which goes into the next position
of the array right? Pass your result outside the loop, and enable indexing
on the terminal so Labview automatically generates the array for you. If
your calculation is a function of previous data, then use a shift register
to keep previous values around.
I wish you luck. Post again if you have any questions. Without a more
detailed understanding of your task at hand it's kind of hard to post actual
code suggestions for you.
-joey
"nelsons" wrote in message
news:[email protected]...
> how do I create a 1d array that takes a single calculation and insert
> the result into the first row and then the next calculation the next
> time the loop passes that point and puts the results in thsecond row
> and so on until the loop is exited.
>
> The attached file is work inprogress, with some dummy data sp that I
> can test it out without having to connect to equipment.
> The second tab is the one that I am having the problem with. the
> output array from the replace element appears to be starting at the
> index position of 1 rather than 0 but that is ok it is still show that
> the new data is placed in incrementing element locations. However the
> main array that I am trying to build that is suppose to take each new
> calculation and place it in the next index(row) does not appear to be
> working or at least I am not getting any indication on the inidcator.
>
> Basically what I am attempting to do is is gather some pulses from
> adevice for a minute, place the results for a calculation, so that it
> displays then do the same again the next minute, but put these result
> in the next row and so on until the specifiied time has expired and
> the loop exits. I need to have all results displayed and keep building
> the array(display until, the end of the test)Eventually I will have to
> include a min max section that displays the min and max values
> calculated, but that should be easy with the min max function.Actually
> I thought this should have been easy but, I gues I can not see the
> forest through the trees. Can any one help to slear this up for me. -
Insert the data into two tables at a time.
Hi ,
i have these two tables
create table [dbo].[test1](
[test1_id] [int] identity(1,1) primary key,
[test2_id] [int] not null
create table [dbo].[test2](
[test2_id] [int] identity(1,1) primary key,
[test1_id] [int] not null
alter table [dbo].[test1]
add constraint [fk_test1_test2_id] foreign key([test2_id])
references [dbo].[test2] ([test2_id])
alter table [dbo].[test2] add constraint [fk_test2_test2_id] foreign key([test1_id])
references [dbo].[test1] ([test1_id])
I want to insert the data into two tables in one insert statement. How can i do this using T-SQL ?
Thanks in advance.You can INSERT into both tables within one Transaction but not in one statement. By the way, you would need to alter your dbo.Test1 table to allow null for first INSERT test2_id column
See sample code below:
CREATE TABLE #test1(test1_ID INT IDENTITY(1,1),test2_id INT NULL)
CREATE TABLE #test2(test2_ID INT IDENTITY(1,1),test1_ID INT)
DECLARE @Test1dentity INT
DECLARE @Test2dentity INT
BEGIN TRAN
-- Insert NULL as test2_ID value is unknown
INSERT INTO #test1(test2_ID)
SELECT NULL;
-- get inserted identity value
SET @Test1dentity = SCOPE_IDENTITY();
INSERT INTO #test2(test1_ID)
SELECT @Test1dentity;
-- get inserted identity value
SET @Test2dentity = SCOPE_IDENTITY();
-- Update test1 table
UPDATE #test1
SET test2_ID = @Test2dentity
WHERE test1_ID = @Test1dentity;
COMMIT
SELECT * FROM #test1;
SELECT * FROM #test2;
-- Drop temp tables
IF OBJECT_ID('tempdb..#test1') IS NOT NULL
BEGIN
DROP TABLE #test1
END
IF OBJECT_ID('tempdb..#test2') IS NOT NULL
BEGIN
DROP TABLE #test2
END
web: www.ronnierahman.com -
Taking the data from interactive forms and load the data into SAP system?
hi all,
I want to know how to take the data from interactive forms and load the data into sap system?
if u have any sample scenario, explain with that.
thanks in advance
RajaHello,
Check the program...
SAPBC480_DEMO.
Check the below threads
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/88e7ea34-0501-0010-95b0-ed14cfbeb85a
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/bfbcd790-0201-0010-679d-e36a3c6b89fa
Thanks
Seshu -
Dequeue XML from Oracle AQ and insert data into table
Using PL/SQL in a stored procedure, I need to dequeue a message from an Oracle AQ queue, parse the XML content and insert the data in an Oracle table. This is being done in Oracle 9.2.x.
The payload for the message consists of 2 attributes, APPLICATION_DATA (VARCHAR2(32) and MESSAGE_BODY (CLOB). The MESSAGE_BODY is an XML document. A sample of the message is shown below:
(M_NAME=MSG_LAW_WR_CRE_UPD, <?xml version = "1.0"?>
<MSG_LAW_WR_CRE_UPD ID = "WMIS-4744" SRC_SYSTEM_CODE = "WMIS" SRC_SYSTEM_INSTANCE = "WMIS">
<WR:CMP_LAW_WR_CRE_UPD xmlns:WR = "WR" >
<WR:DATETIME>12/19/2005</WR:DATETIME>
<WR:RUSCODE>100</WR:RUSCODE>
<WR:WRNO>38213</WR:WRNO>
</WR:CMP_LAW_WR_CRE_UPD>
</MSG_LAW_WR_CRE_UPD>)
This message needs to be dequeued from a queue named INBOUND, parsed and inserted into a table named INFO_TO_ACCT (CREATEDATE date, RUSCODE varchar2(10), WRNO number).
Any help would be appreciated.SELECT EXTRACTVALUE(xmltype('<?xml version = "1.0"?>
<MSG_LAW_WR_CRE_UPD ID = "WMIS-4744" SRC_SYSTEM_CODE = "WMIS" SRC_SYSTEM_INSTANCE = "WMIS">
<CMP_LAW_WR_CRE_UPD>
<DATETIME>12/19/2005</DATETIME>
<RUSCODE>100</RUSCODE>
<WRNO>38213</WRNO>
</CMP_LAW_WR_CRE_UPD>
</MSG_LAW_WR_CRE_UPD>'),'//DATETIME/text()') FROM DUAL;
hope this helps. -
Compare String in a table and insert the common values into a New table
Hi all,
Anyone has idea on how to compare a string value in a table.
I have a Students Table with Student_id and Student_Subject_list columns as below.
create table Students( Student_id number,
Student_Subject_list varchar2(2000)
INSERT INTO Students VALUES (1,'Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History');
INSERT INTO Students VALUES (2,'Math,Law,Business,Social,Language arts,History,Biotechnology,communication');
INSERT INTO Students VALUES (3,'History,Spanish,French,Langage arts');
INSERT INTO Students VALUES (4,'History,Maths,Science,Chemistry,English,Reading');
INSERT INTO Students VALUES (5,'Math,Science,Arts,Music,Computer Programming,Language arts,History');
INSERT INTO Students VALUES (6,'Finance,Stocks');
output
Student_id Student_Subject_list
1 Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History
2 Math,Law,Business,Social,Language arts,History,Biotechnology,communication
3 History,Spanish,French,Langage arts
4 History,Maths,Science,Chemistry,English,Reading
5 Math,Science,Arts,Music,Computer Programming,Language arts,History
6 Finance,Stocks
I need help or some suggestion in write a query which can compare each row string value of Student_Subject_list columns and insert the
common subjects into a new table(Matched_Subjects).The second table should have the below colums and data.
create table Matched_Subjects(Student_id number,
Matching_studesnt_id Number,
Matched_Student_Subject varchar2(2000)
INSERT INTO Matched_Subjects VALUES (1,2,'Math,Law,Business,Social,Language arts,History');
INSERT INTO Matched_Subjects VALUES (1,3,'History,Langage arts');
INSERT INTO Matched_Subjects VALUES (1,4,'History,Maths,Science');
INSERT INTO Matched_Subjects VALUES (1,5,'Math,Science,Arts,Music,Language arts,History');
INSERT INTO Matched_Subjects VALUES (2,3,'History,Langage arts');
INSERT INTO Matched_Subjects VALUES (2,4,'History,Maths');
INSERT INTO Matched_Subjects VALUES (2,5,'Math,Language arts,History');
INSERT INTO Matched_Subjects VALUES (3,4,'History');
INSERT INTO Matched_Subjects VALUES (3,5,'Language arts,History');
INSERT INTO Matched_Subjects VALUES (4,5,'Math,Science');
output:
Student_id Match_Student_id Matched_Student_Subject
1 2 Math,Law,Business,Social,Language arts,History
1 3 History,Langage arts
1 4 History,Maths,Science
1 5 Math,Science,Arts,Music,Language arts,History
2 3 History,Langage arts
2 4 History,Maths
2 5 Math,Language arts,History
3 4 History
3 5 Language arts,History
4 5 Math,Science
any help will be appreciated.
Thanks.
Edited by: user7988 on Sep 25, 2011 8:45 AMuser7988 wrote:
Is there an alternate approach to this without using xmlagg/xmlelement What Oracle version are you using? In 11.2 you can use LISTAGG:
insert
into Matched_Subjects
with t as (
select student_id,
column_value l,
regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
from students,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
as sys.OdciNumberList
select t1.student_id,
t2.student_id,
listagg(t1.subject,',') within group(order by t1.l)
from t t1,
t t2
where t1.student_id < t2.student_id
and t1.subject = t2.subject
group by t1.student_id,
t2.student_id
STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
1 2 Math,Law,Business,Social,Language arts,History
1 3 Language arts,History
1 4 Science,History
1 5 Math,Science,Arts,Music,Language arts,History
2 3 Language arts,History
2 4 History
2 5 Math,Language arts,History
3 4 History
3 5 History,Language arts
4 5 History,Science
10 rows selected.
SQL> Prior to 11.2 you can create your own string aggregation function STRAGG - there are plenty of example on this forum. Or use hierarchical query:
insert
into Matched_Subjects
with t1 as (
select student_id,
column_value l,
regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
from students,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
as sys.OdciNumberList
t2 as (
select t1.student_id student_id1,
t2.student_id student_id2,
t1.subject,
row_number() over(partition by t1.student_id,t2.student_id order by t1.l) rn
from t1,
t1 t2
where t1.student_id < t2.student_id
and t1.subject = t2.subject
select student_id1,
student_id2,
ltrim(sys_connect_by_path(subject,','),',') MATCHED_STUDENT_SUBJECT
from t2
where connect_by_isleaf = 1
start with rn = 1
connect by student_id1 = prior student_id1
and student_id2 = prior student_id2
and rn = prior rn + 1
STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
1 2 Math,Law,Business,Social,Language arts,History
1 3 Language arts,History
1 4 Science,History
1 5 Math,Science,Arts,Music,Language arts,History
2 3 Language arts,History
2 4 History
2 5 Math,Language arts,History
3 4 History
3 5 History,Language arts
4 5 History,Science
10 rows selected.SY. -
Compare 2 tables and insert rows missing in each table.
I have a tough situation. I have two exact tables- one online and one offline database. I know that there are missing rows of data from each table, so I need to make a comparison of one table and insert rows that do not exist. I was thinking to try this, but it took over 3 hours to run and did not return anything:
insert into t
select * from t a
where not exists (select * from [email protected] b
where a.col1 != b.col1
and a.col2 != b.col2
and a.col3 != b.col3);
and it goes on for another 7columns.
The trouble I have is to include a date clause so that the query can be broken down into running only a few months of data comparisions at a time- the records go back 4 years to compare. Also is there a way to write this so that it will query both tables at the same time in order to speed things up- or is one table at a time the best advice? Each table has over 100 million records to compare, that's why I was hoping to use a date criteria since one column is date.
Let me know what you advise to make this work, I hope I was on the right track.Not sure if the MINUS operator will perform better with your data set but;
SQL> create table t1 (some_id number, some_date date)
Table created.
SQL> create table t2 (some_id number, some_date date)
Table created.
SQL> insert into t1 values (1, trunc(sysdate))
1 row created.
SQL> insert into t1 values (2, trunc(sysdate-5))
1 row created.
SQL> insert into t1 values (4, trunc(sysdate-90))
1 row created.
SQL> insert into t2 values (1, trunc(sysdate))
1 row created.
SQL> insert into t2 values (3, trunc(sysdate-10))
1 row created.
SQL> insert into t2 values (5, trunc(sysdate-100))
1 row created.
SQL> select * from t1
SOME_ID SOME_DAT
1 07-07-30
2 07-07-25
4 07-05-01
3 rows selected.
SQL> select * from t2
SOME_ID SOME_DAT
1 07-07-30
3 07-07-20
5 07-04-21
3 rows selected.
SQL> insert into t1 (
select some_id, some_date from t2 where some_date between sysdate-50 and sysdate
minus
select some_id, some_date from t1 where some_date between sysdate-50 and sysdate)
1 row created.
SQL> insert into t2 (
select some_id, some_date from t1 where some_date between sysdate-50 and sysdate
minus
select some_id, some_date from t2 where some_date between sysdate-50 and sysdate)
1 row created.
SQL> select * from t1
SOME_ID SOME_DAT
1 07-07-30
2 07-07-25
4 07-05-01
3 07-07-20
4 rows selected.
SQL> select * from t2
SOME_ID SOME_DAT
1 07-07-30
3 07-07-20
5 07-04-21
2 07-07-25
4 rows selected. -
When I export an AAF file/project from Protools 9 using an external drive and import the AAF into Logice Pro X the drum track does not play correctly. It is out of sync with the rest of the track. I created the drum loop as a plugin using Native Instruments Maschine. Has anyone else had this problem?? Also how would I go about exporting the midi tracks from the Protools session. The midi track does not show when the file is imported to Logic Pro X. The midi data should export with the AAF file correct??
Are you using any plugins in Logic?
In Preferences/Audio under the General tab, how do you have the plug-in-latency compensation set? -
I have a mpp screen for a cd library management system (we are practicing on it).
We have a main screen where a user should enter the enteries and while clicking a add button it should be inserted in a table, Here the problem rises the table name are ztransaction and zstatus.The fields in mpp are cdid,customerid,transaction id,date of issue and duedate.Now after entering all the values on clicking add button it should be inserted to database table ztransaction and the field cdid alone should be inserted both in ztransaction and zstatus.
Thank youHi Raghuram R G,
Check for Primary key and foreign key in the Database table??? Because of this it was not inserting...check and confirm??
Regds,
Vijay SR -
Parsing an EDI file and populating the data into database table
Hi ,
Please help me in parsing an edi file and getting the required columns.
we get an EDI file from a bank. I need to parse that file and populate the db table with the required columns.
the file is '*' delimited and every line ends with '\'.
The record starts with 'ST*' and ends with 'SE*'.
sample edi file is
ISA*00* *00* *ZZ*043000096820 *ZZ*2156833510 *131202*0710*U*00401*000001204*0*P*>\ ignore first 2 lines
GS*RA*043000096820*2156833510*131202*0710*1204*X*003020\
ST*820*000041031\
BPR*X*270*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\
TRN*1*101036661273032\
DTM*007*131202\
N1*1U*BPS\
N1*BE*MICHAEL DRAYTON*34*159783633\
N1*PE*BPS*ZZ*183383689C2 ABC\
N1*PR*ABC TREAS 310\
SE*9*000041031\ ST*820*000041032\
BPR*X*686*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\
TRN*1*101036661273034\
DTM*007*131202\
N1*1U*BPS\
N1*BE*SAMIA GRAVES*34*892909238\
N1*PE*BPS*ZZ*184545710C5 ABC\
N1*PR*ABC TREAS 310\
SE*9*000041032\
Below is the procedure I am trying to use for parsing that file. but the logic is not working. can you please help me in doing this. its very urgent requirement.
CREATE OR REPLACE package body p1 is
Function parse_spec(p_str varchar2) return t_str_nt is
begin
return regexp_replace(p_str,'\\$',null);
end;
procedure edi( is
l_out_file utl_file.file_type;
l_lin varchar2(200);
field1 number(9);
field2 varchar2(10 byte);
field3 varchar2(15 byte);
field4 varchar2(15 byte);
field5 varchar2(20 byte);
field6 varchar2(20 byte);
field7 varchar2(20 byte);
field8 varchar2(9 byte);
field9 varchar2(15 byte);
field10 varchar2(5 byte);
l_item_nt t_str_nt:=t_str_nt();
begin
l_out_file := utl_file.fopen (file_path, file_name, 'r');
IF utl_file.is_open(l_out_file) THEN
LOOP
BEGIN
l_item_nt:= utl_file.get_line(l_out_file, l_lin);
IF l_item_nt IS NULL THEN
raise no_data_found;
Else
for k in 1..l_item_nt.count loop
case
when l_item_nt(k) like 'ST*%' then
field1:= ltrim(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),0);
when l_item_nt(k) like 'BPR*X*%' then
field2 := regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);
when l_item_nt(k) like 'TRN*1*%' then
field3:= regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);
when l_item_nt(k) like 'DTM*007*%' then
field4:= regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);
when l_item_nt(k) like '%*BE*%' then
field5 := regexp_substr(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),'[^ ]+', 1, 1);
field6 := regexp_substr(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),'[^ ]+', 1, 1);
field7 := regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,5);
when l_item_nt(k) like '%*PE*%*ZZ*%' then
field8:= regexp_substr(regexp_substr(parse_spec(line),'[^*]+',1,5),'[^ ]+',1,1)
field9 := regexp_substr(regexp_substr(parse_spec(line),'[^*]+',1,5),'[^ ]+',1,2);
when l_item_nt(k) like 'SE*%' then
insert into t1(field1,field2,field3,field5,field6,field7,field8,field9)
-- values(field1,field2,field3,field5,field6,field7,field8,field9);
else
dbms_output.put_line ('end of line');
end case;
end loop;
end if;
end loop;
utl_file.fclose(l_out_file);
exception
when no_data_found then
dbms_output.put_line('No data found');
end;I would not use regular expressions for parsing as it is CPU intensive - and standard string processing suffices.
I would break the EDI up into lines. I would tokenise each line. I then have 2d array that can be referenced to find a specific field. E.g. line x and token y is field abc.
Basic approach:
SQL> create or replace type TStrings as table of varchar2(4000);
2 /
Type created.
SQL> -- create a parser that tokenises a string
SQL> create or replace function Tokenise(
2 csvLine varchar2,
3 separator varchar2 default ',',
4 enclosedBy varchar2 default null
5 ) return TStrings is
6 strList TStrings;
7 str varchar2(32767);
8 i integer;
9 l integer;
10 enclose1 integer;
11 enclose2 integer;
12 encloseStr varchar2(4000);
13 replaceStr varchar2(4000);
14
15 procedure AddString( line varchar2 ) is
16 begin
17 strList.Extend(1);
18 strList( strList.Count ) := Replace( line, CHR(0), separator );
19 end;
20
21 begin
22 strList := new TStrings();
23
24 str := csvLine;
25 loop
26 if enclosedBy is not null then
27 -- find the ennclosed text, if any
28 enclose1 := InStr( str, enclosedBy, 1 );
29 enclose2 := InStr( str, enclosedBy, 2 );
30
31 if (enclose1 > 0) and (enclose2 > 0) and (enclose2 > enclose1) then
32 -- extract the enclosed string
33 encloseStr := SubStr( str, enclose1, enclose2-enclose1+1 );
34 -- replace the separator char's with zero char's
35 replaceStr := Replace( encloseStr, separator, CHR(0) );
36 -- and remove the enclosed quotes
37 replaceStr := Replace( replaceStr, enclosedBy );
38 -- change the enclosed string in the big string to the replacement string
39 str := Replace( str, encloseStr, replaceStr );
40 end if;
41 end if;
42
43 l := Length( str );
44 i := InStr( str, separator );
45
46 if i = 0 then
47 AddString( str );
48 else
49 AddString( SubStr( str, 1, i-1 ) );
50 str := SubStr( str, i+1 );
51 end if;
52
53 -- if the separator was on the last char of the line, there is
54 -- a trailing null column which we need to add manually
55 if i = l then
56 AddString( null );
57 end if;
58
59 exit when str is NULL;
60 exit when i = 0;
61 end loop;
62
63 return( strList );
64 end;
65 /
Function created.
SQL>
SQL>
SQL> declare
2 ediDoc varchar2(32767) :=
3 'ISA*00* *00* *ZZ*043000096820 *ZZ*2156833510 *131202*0710*U*00401*000001204*0*P*>\GS*RA*043000096820*2156833510*131202*0710*1204*X*003020\ST*820*000041031\BPR*X*270*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\TRN*1*101036661273032\DTM*007*131202\N1*1U*BPS\N1*BE*MICHAEL DRAYTON*34*159783633\N1*PE*BPS*ZZ*183383689C2 ABC\N1*PR*ABC TREAS 310\SE*9*000041031\ST*820*000041032\BPR*X*686*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\TRN*1*101036661273034\DTM*007*131202\N1*1U*BPS\N1*BE*SAMIA GRAVES*34*892909238\N1*PE*BPS*ZZ*184545710C5 ABC\N1*PR*ABC TREAS 310\SE*9*000041032\';
4
5 lines TStrings;
6 tokens TStrings;
7 begin
8 -- split EDI string into lines
9 lines := Tokenise( ediDoc, '\' );
10
11 -- process line and extract fields
12 for i in 3..lines.Count loop
13 dbms_output.put_line( '***********************' ) ;
14 dbms_output.put_line( 'line=['||lines(i)||']' );
15 tokens := Tokenise( lines(i), '*' );
16
17 for j in 1..tokens.Count loop
18 dbms_output.put_line( to_char(j,'00')||'='||tokens(j) );
19 end loop;
20 end loop;
21 end;
22 /
line=[ST*820*000041031]
01=ST
02=820
03=000041031
line=[BPR*X*270*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202]
01=BPR
02=X
03=270
04=C
05=ACH
06=PPD
07=01
08=101036669
09=
10=
11=9101036669
12=
13=01
14=031000053
15=DA
16=00000008606086714
17=131202
line=[TRN*1*101036661273032]
01=TRN
02=1
03=101036661273032
<snipped> -
How to read a table and transfer the data into an internal table?
Hello,
I try to read all the data from a table (all attribute values from a node) and to write these data into an internal table. Any idea how to do this?
Thanks for any help.Hi,
Check this code.
Here i creates context one node i.e flights and attributes are from SFLIGHT table.
DATA: lo_nd_flights TYPE REF TO if_wd_context_node,
lo_el_flights TYPE REF TO if_wd_context_element,
ls_flights TYPE if_main=>element_flights,
it_flights type if_main=>elements_flights.
navigate from <CONTEXT> to <FLIGHTS> via lead selection
lo_nd_flights = wd_context->get_child_node( 'FLIGHTS' ).
CALL METHOD LO_ND_FLIGHTS->GET_STATIC_ATTRIBUTES_TABLE
IMPORTING
TABLE = it_flights.
now the table data will be in internal table it_flights. -
How to associate an xml from httpservice to datagrid if the xml element name contains periods in it
Following is the xml from an http service, how to associate
this xml to a data grid (employee name, number) since it contains
periods(dots) in xml element name.
An early help is appreciated.....
<?xml version="1.0" encoding="ISO-8859-1"?>
<com.companyx>
<person>
<employee.data>
<employee.name>mrx</employee.name>
<employee.number>1001</employee.number>
</employee.data>
<employee.data>
<employee.name>mry</employee.name>
<employee.number>1002</employee.number>
</employee.data>
<employee.data>
<employee.name>mrz</employee.name>
<employee.number>1003</employee.number>
</employee.data>
<page>0</page>
</person>
</com.companyx>
Thanks,
Vijay KarthikHI
GOOD
IT IS POSSIBLE IN ABAP
Extensible Markup Language (XML) is a simple, very flexible text format derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing, XML is also playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere.
XSD->
XML Schemas express shared vocabularies and allow machines to carry out rules made by people. They provide a means for defining the structure, content and semantics of XML documents. in more detail.
XDS->
XDS can process data images from CCD-, imaging-plate, and multiwire-detectors in a variety of formats. Detector specific Input file templates greatly simplify the use of XDS; they are provided as part of the documentation.
XDS runs under Unix or Linux on a single server or a grid of up to 99 machines of the same type managed by the MOSIX system; in addition, by using OpenMP, it can be executed in parallel on up to 32 processors at each node that share the same address space.
http://www2.stylusstudio.com/SSDN/default.asp?action=9&fid=23&read=2926
/people/r.eijpe/blog/2006/02/19/xml-dom-processing-in-abap-part-iiia150-xml-dom-within-sap-xi-abap-mapping
THANKS
MRUTYUN
Maybe you are looking for
-
how to have multiple images on the same screen? like in the movies where you see several actions at the same time .... i don't find a tutorial in adobe tv.... thanks !!
-
Downgrade USB 3.0 to USB 2.0
Hi, I bought two Q190 PCs with Vista OEM (yes, I know ... but the OS was cheap). It is working well, but those USB 3.0 from the front are not working and I have a project where I need all six USBs. I don't need them to be 3.0. USB 2.0 is enought. Sea
-
Hi All, how to send output of a report to spool and output of of report should not be display and i need spool number in status bar of the selection screen.all this function should happen when i exectute selcetion after providing varient in selectio
-
Hi, I have installed an admin server, a managed server and a node manager on a single machine. (btw, I'm using WLS7 sp2) With the default config, the managed server starts and stops successfully from
-
The error panel told me to contact you. Hopefully you will let me know what to do. Juan zumbadoEverizon.net Photoshop also told me that it could not do something with colors- but I could not replicate the problem. Juan