Procedure with multiple Loops and Insert into table
Hello All,
I am trying to create the Procedure to create a new table for our DWH.
In this Case, I have 2 tables and I need to create Loop for each value from one table and get the respective data from second table based on first table data.
Please find the below example:
First table: TABLE_A
X Y Z
1 a 10
1 b abc
1 c xy
1 e $
2 a 11
2 c asf
2 d tal
2 f ghs
Second Table: TABLE_B
A B C D E F
10 abc xy sd ew 100
10 jhy xy sd ew 100
11 ght asf tal ss ghs
11 ght afr tal ss ghs
O/P Table from Procedure: OUTPUT_TABLE
A B C D E F X
10 abc xy sd ew 100 1
11 ght asf tal ss ghs 2
Business Logic In the Procedure:
CREATE OR REPLACE PROCEDURE OP_TAB_PROCEDURE IS
BEGIN
-- First get the DISTINCT values from the TABLE_A to generate the Loop
FOR ID (SEELCT DISTINCT X FROM TABLE_A_
LOOP
-- For Each ID get the Y ,Z values from TABLE_A other than $ in Z
TEMP:
SELECT Y, Z FROM TABLE_A WHERE X = ID.X AND Z <> '$' ;
Based on above SELECT statement, I need to construct dynamic SQL query to get the data from TABLE_B
OP_EACH_ID:
SELECT * , ID.X AS X FROM TABLE_A WHERE [In this place I need generate sql cond dynamically. For Example, For X=1 in TABLE_A , the where cond must A=10 AND B='abc' AND C='xy'
For X=2 , the Where cond must be WHERE A=11 AND C='asf' AND D='tal' AND F='ghs']
-- I need to INSERT all the values from OP_EACH_ID into OUT_PUT_TABLE
END LOOP ;
END;
I am new to PL/SQL , so please help me on the above case.
duplicate post
Similar Messages
-
Reg: read excel column and insert into table.
hi Friends,
i wanted to read the data from Excel and insert into in my oracle tables.
can you provide the link or example script.
how to read the column value from excel and insert into table.
please help.< unnecessary reference to personal blog removed by moderator >
Here are the steps:
1) First create a directory and grant read , write , execute to the user from where you want to access the flat files and load it.
2) Write a generic function to load PIPE delimited flat files:
CREATE OR REPLACE FUNCTION TABLE_LOAD ( p_table in varchar2,
p_dir in varchar2 DEFAULT ‘YOUR_DIRECTORY_NAME’,
P_FILENAME in varchar2,
p_ignore_headerlines IN INTEGER DEFAULT 1,
p_delimiter in varchar2 default ‘|’,
p_optional_enclosed in varchar2 default ‘”‘ )
return number
is
– FUNCTION TABLE_LOAD
– PURPOSE: Load the flat files i.e. only text files to Oracle
– tables.
– This is a generic function which can be used for
– importing any text flat files to oracle database.
– PARAMETERS:
– P_TABLE
– Pass name of the table for which import has to be done.
– P_DIR
– Name of the directory where the file is been placed.
– Note: The grant has to be given for the user to the directory
– before executing the function
– P_FILENAME
– The name of the flat file(a text file)
– P_IGNORE_HEADERLINES
– By default we are passing 1 to skip the first line of the file
– which are headers on the Flat files.
– P_DELIMITER
– Dafault “|” pipe is been passed.
– P_OPTIONAL_ENCLOSED
– Optionally enclosed by ‘ ” ‘ are been ignored.
– AUTHOR:
– Slobaray
l_input utl_file.file_type;
l_theCursor integer default dbms_sql.open_cursor;
l_lastLine varchar2(4000);
l_cnames varchar2(4000);
l_bindvars varchar2(4000);
l_status integer;
l_cnt number default 0;
l_rowCount number default 0;
l_sep char(1) default NULL;
L_ERRMSG varchar2(4000);
V_EOF BOOLEAN := false;
begin
l_cnt := 1;
for TAB_COLUMNS in (
select column_name, data_type from user_tab_columns where table_name=p_table order by column_id
) loop
l_cnames := l_cnames || tab_columns.column_name || ‘,’;
l_bindvars := l_bindvars || case when tab_columns.data_type in (‘DATE’, ‘TIMESTAMP(6)’) then ‘to_date(:b’ || l_cnt || ‘,”YYYY-MM-DD HH24:MI:SS”),’ else ‘:b’|| l_cnt || ‘,’ end;
l_cnt := l_cnt + 1;
end loop;
l_cnames := rtrim(l_cnames,’,');
L_BINDVARS := RTRIM(L_BINDVARS,’,');
L_INPUT := UTL_FILE.FOPEN( P_DIR, P_FILENAME, ‘r’ );
IF p_ignore_headerlines > 0
THEN
BEGIN
FOR i IN 1 .. p_ignore_headerlines
LOOP
UTL_FILE.get_line(l_input, l_lastLine);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_eof := TRUE;
end;
END IF;
if not v_eof then
dbms_sql.parse( l_theCursor, ‘insert into ‘ || p_table || ‘(‘ || l_cnames || ‘) values (‘ || l_bindvars || ‘)’, dbms_sql.native );
loop
begin
utl_file.get_line( l_input, l_lastLine );
exception
when NO_DATA_FOUND then
exit;
end;
if length(l_lastLine) > 0 then
for i in 1 .. l_cnt-1
LOOP
dbms_sql.bind_variable( l_theCursor, ‘:b’||i,
ltrim(rtrim(rtrim(
regexp_substr(l_lastLine,’([^|]*)(\||$)’,1,i),p_delimiter),p_optional_enclosed),p_optional_enclosed));
end loop;
begin
l_status := dbms_sql.execute(l_theCursor);
l_rowCount := l_rowCount + 1;
exception
when OTHERS then
L_ERRMSG := SQLERRM;
insert into BADLOG ( TABLE_NAME, ERRM, data, ERROR_DATE )
values ( P_TABLE,l_errmsg, l_lastLine ,systimestamp );
end;
end if;
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose( l_input );
commit;
end if;
insert into IMPORT_HIST (FILENAME,TABLE_NAME,NUM_OF_REC,IMPORT_DATE)
values ( P_FILENAME, P_TABLE,l_rowCount,sysdate );
UTL_FILE.FRENAME(
P_DIR,
P_FILENAME,
P_DIR,
REPLACE(P_FILENAME,
‘.txt’,
‘_’ || TO_CHAR(SYSDATE, ‘DD_MON_RRRR_HH24_MI_SS_AM’) || ‘.txt’
commit;
RETURN L_ROWCOUNT;
end TABLE_LOAD;
Note: when you run the function then it will also modify the source flat file with timestamp , so that we can have the track like which file was loaded .
3) Check if the user is having UTL_FILE privileges or not :
SQL> SELECT OWNER,
OBJECT_TYPE
FROM ALL_OBJECTS
WHERE OBJECT_NAME = ‘UTL_FILE’
AND OWNER =<>;
If the user is not having the privileges then grant “UTL_FILE” to user from SYS user:
SQL> GRANT EXECUTE ON UTL_FILE TO <>;
4) In the function I have used two tables like:
import_hist table and badlog table to track the history of the load and another to check the bad log if it occurs while doing the load .
Under the same user create an error log table to log the error out records while doing the import:
SQL> CREATE TABLE badlog
errm VARCHAR2(4000),
data VARCHAR2(4000) ,
error_date TIMESTAMP
Under the same user create Load history table to log the details of the file and tables that are imported with a track of records loaded:
SQL> create table IMPORT_HIST
FILENAME varchar2(200),
TABLE_NAME varchar2(200),
NUM_OF_REC number,
IMPORT_DATE DATE
5) Finally run the PLSQL block and check if it is loading properly or not if not then check the badlog:
Execute the PLSQL block to import the data from the USER:
SQL> declare
P_TABLE varchar2(200):=<>;
P_DIR varchar2(200):=<>;
P_FILENAME VARCHAR2(200):=<>;
v_Return NUMBER;
BEGIN
v_Return := TABLE_LOAD(
P_TABLE => P_TABLE,
P_DIR => P_DIR,
P_FILENAME => P_FILENAME,
P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES,
P_DELIMITER => P_DELIMITER,
P_OPTIONAL_ENCLOSED => P_OPTIONAL_ENCLOSED
DBMS_OUTPUT.PUT_LINE(‘v_Return = ‘ || v_Return);
end;
6) Once the PLSQL block is been executed then check for any error log table and also the target table if the records are been successfully imported or not. -
Reading xml data from url and insert into table
CREATE TABLE url_tab2
URL_NAME VARCHAR2(100),
URL SYS.URIType
INSERT INTO url_tab2 VALUES
(’This is a test URL’,
sys.UriFactory.getUri(’http://www.domain.com/test.xml’)
it is giving error as invalid characterCheck if your single quotes are the correct single quotes.
The principle works as advertised in the XMLDB Developers Guide...
C:\>sqlplus / as sysdba
SQL*Plus: Release 11.1.0.7.0 - Production on Tue Nov 25 21:44:46 2008
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create user OTN identified by OTN account unlock;
User created.
SQL> grant dba, xdbadmin to OTN;
Grant succeeded.
SQL> conn OTN/OTN
Connected.
SQL> CREATE TABLE uri_tab (docUrl SYS.URIType, docName VARCHAR2(200));
Table created.
SQL> -- Method SYS.URIFACTORY.getURI() with absolute URIs
SQL> -- Insert an HTTPUri with absolute URL into SYS.URIType using URIFACTORY.
SQL> -- The target is Oracle home page.
SQL> INSERT INTO uri_tab VALUES
2 (SYS.URIFACTORY.getURI('http://www.oracle.com'), 'AbsURL');
1 row created.
SQL> -- Insert an HTTPUri with relative URL using constructor SYS.HTTPURIType.
SQL> -- Note the absence of prefix http://. The target is the same.
SQL> INSERT INTO uri_tab VALUES (SYS.HTTPURIType('www.oracle.com'), 'RelURL');
1 row created.
SQL> -- Insert a DBUri that targets employee data from database table hr.employees.
SQL>
SQL> INSERT INTO uri_tab VALUES
2 (SYS.URIFACTORY.getURI('/oradb/HR/EMPLOYEES/ROW[EMPLOYEE_ID=200]'), 'Emp200');
1 row created.
SQL> SELECT e.docUrl.getCLOB(), docName FROM uri_tab e;
E.DOCURL.GETCLOB()
DOCNAME
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN
">
<html>
<head>
AbsURL
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN
">
<html>
E.DOCURL.GETCLOB()
DOCNAME
<head>
RelURL
<?xml version="1.0"?>
<ROW>
<EMPLOYEE_ID>200</EMPLOYEE_ID>
<FIRST_NAME>Jenn
Emp200
SQL> set long 1000
SQL> select HTTPURITYPE('www.oracle.com').getCLob() from dual;
HTTPURITYPE('WWW.ORACLE.COM').GETCLOB()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN
">
<html>
<head>
<title>Oracle 11g, Siebel, PeopleSoft |
Oracle, The World's Largest Enterprise S
oftware Company</title>
<meta name="title" content="Enterprise Applications | D
atabase | Fusion Middleware | Applicatio
ns Unlimited | Business | Oracle, The Wo
rld's Largest Enterprise Software CompanEdited by: Marco Gralike on Nov 25, 2008 10:13 PM -
Could anyone tell me how to read 4 lines altogether and insert into table
Hi ,
I want to load the below data into table by using sql loader.
First 4 lines should insert in one single row in table and again it should from '01' load the next 4 lines in another row.
01suresh
02works
03in
04bankok
01kumar
02works
03in
04abudabi
01Raju
02works
03in
04france
Could you please give me some suggestion how i can accomplish it.
Thanks in advance.
Regards,
Vinouser1142030 wrote:
First 4 lines should insert in one single row in table and again it should from '01' load the next 4 lines in another row.Not a problem, use CONTINUEIF. Control file:
LOAD DATA
INFILE *
REPLACE
CONTINUEIF NEXT PRESERVE(1:2) != "01"
INTO TABLE continueif
TRAILING NULLCOLS
DUMMY FILLER POSITION(1:2),
COL1 TERMINATED BY '02',
COL2 TERMINATED BY '03',
COL3 TERMINATED BY '04',
COL4 TERMINATED BY '01'
BEGINDATA
01suresh
02works
03in
04bankok
01kumar
02works
03in
04abudabi
01Raju
02works
03in
04france Now:
SQL> create table continueif(
2 col1 varchar2(10),
3 col2 varchar2(10),
4 col3 varchar2(10),
5 col4 varchar2(10)
6 )
7 /
Table created.
SQL> host sqlldr scott@orcl/tiger control=c:\temp\continueif.ctl log=c:\temp\continueif.log
SQL> select * from continueif
2 /
COL1 COL2 COL3 COL4
suresh works in bankok
kumar works in abudabi
Raju works in france
3 rows selected.
SQL> SY. -
Create and insert into table from Oracle to MS SQL server.
Hello,
Oracle Database 11g and Red hat 5
I have a very different kind of issue. I am handling the ORACLE db(remote db with all the important data). On the other side their is a MS SQL server db(local db with some testing data in it). All the users will access the ORACLE db for the actual processing but for sometime they need to apply some of their own concepts. So they will transfer the data from ORACLE to MS sql server.
I want to create a code in ORACLE db like a procedure , which will create a table in MS sql server , insert data into it,Also create some metadata table to keep some of my table's info on MS SQL serve db,If the table is present it should append the data, .... like many things ...
Overall my question is , how can i write a code to make these operation on a remote db, that to these operations are DDL and on MS SQL Server(Non-Oracle) ???
Please guide me with some ideas or solutions ...
Also provide if you have some good links to study ...
thanks in advance.I'm not sure why you never visit http://tahiti.oracle.com prior to asking any question. Is it forbidden in your locale? Are you afraid of it? Will your salary be decreased when you visit the documentation?
http://www.oracle.com/pls/db111/search?word=sql+server&partno=
should provide sufficient information.
Your doc question must be considered a violation of Forum Etiquette and an abuse of this forum.
Sybrand Bakker
Senior Oracle DBA -
I created a "comic strip" in photoshop (multiple rectangle shape layers, then various shapes within each box for each frame of the comic strip) that I want to import into AE. When I import it as a composition (to keep my layers), however, what appears is an simply a black image with white lines where the lines of the comic strip used to be. I checked the color modes, but they are both in RGB so I don't think that's the problem. Also, when I double click the cartoon strip composition, I can choose certain groups from the mini flow-chart at the top left and view those individual frames. However, I can't view the entire comic strip as a whole, which is necessary for my animation. Any help with this would be greatly appreciated, as I'm on a tight time constraint. Thanks!
When I asked what version down to the last decimal, I meant it. After Effects version should start with 11, but we need the numbers after that too.
And I understand that you want to pan between them, so just put all the different PSD's you import into the same comp and pan between them. -
Problem with reading data from screen and inserting in table
hi ther,
im new to abap-webdyn pro. can anyone suggest how to read data from screen and insert into table when press 'ADD' button.
i done screen gui , table creation but problems with action. what the content of acton add.
is ther any link that helps me or tut??
thankx in advance!
regardsHi,
Create a context node for the screen fields for which you want to enter the values with cardinality 1.1.....
Now in the layout of your view bind the screen input fields to that context node(attributes) to the value property of the input fields...
Now in the action of ADD button....
--> go the wizard and select the read node button and select the node which you have created it generates the auto code for you.....
for example if the node is contains aone attribute like MATNR
reading the node from wizard will generate the code as....
DATA lo_nd_matnr TYPE REF TO if_wd_context_node.
DATA lo_el_matnr TYPE REF TO if_wd_context_element.
DATA ls_matnr TYPE wd_this->element_matnr.
DATA lv_matnr TYPE wd_this->element_matnr-matnr.
* navigate from <CONTEXT> to <MATNR> via lead selection
lo_nd_matnr = wd_context->get_child_node( name = wd_this->wdctx_matnr ).
* @TODO handle non existant child
* IF lo_nd_matnr IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_matnr = lo_nd_matnr->get_element( ).
* @TODO handle not set lead selection
IF lo_el_matnr IS INITIAL.
ENDIF.
* get single attribute
lo_el_matnr->get_attribute(
EXPORTING
name = `MATNR`
IMPORTING
value = lv_matnr ).
here the variable lv_matnr will contain the entered value......
now you can use this value for further process.
Thanks,
Shailaja Ainala. -
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. -
Read text file insert into table using utl_file
Hi
i have script for read and insert into table but i want error records load into error table so i sent you my script and please fix the error log table
script
DECLARE
v_line VARCHAR2(2000);
v_file utl_file.file_type;
v_dir VARCHAR2(250);
v_filename VARCHAR2(50);
BEGIN
v_dir :='MID5010_DOC1TP';
v_filename := 'OPT_CM_BASE.txt';
v_file := utl_file.fopen(v_dir, v_filename, 'r');
LOOP
BEGIN
utl_file.get_line(v_file, v_line);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END ;
v_line := REPLACE(v_line,'|','|~');
INSERT
INTO optum_icd10cm_base VALUES
( REPLACE(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,1),'a~','a'),'.'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,2),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,3),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,4),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,5),'a~','a'),
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,6)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,6),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,6),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,7)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,7),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,7),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,8)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,8),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,8),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,9)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,9),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,9),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,10)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,10),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,10),'a~','a'),'mm-dd-yyyy')
END,
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,11),'a~','a')
-----commit;
END LOOP;
utl_file.fclose(v_file);
END;
text file
A50.0||Short|Long|Full|01-01-2009|01-2009||01-01-2013|09-18-2012|C|
A50.1||Short|Long|Full|01-01-2009|01-01-2009||001-2013|09-18-2012|C|
A50.2||Short|Long|Full|01-01-2009|01-01-2009|67|01-01-2013|09-18-2012|C|
A50.3||Short|Long|Full|011-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.4||Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|5|
A50.5|R|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.6||Short|Long||01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.7||Short||Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
2345||Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.8|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.9|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
B222|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.8|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.9|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.2|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.3|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
D642|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.5|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.6|D|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.7|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A001|C|Short Updated|Long Updated|Full Updated|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A009|C|Short Updated|Long Updated|Full Updated|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.10|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A0109|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A30|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A316|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A317|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
----clearly read text file insert into table and error records load into error table
please help mehI
i am using utl_file prepared script but i got error like 01861. 00000 - "literal does not match format string"
script:
DECLARE
f utl_file.file_type;
s VARCHAR2(32000);
f1 VARCHAR2(100);
f2 varchar2(100);
F3 VARCHAR2(100);
F4 VARCHAR2(100);
F5 VARCHAR2(100);
F6 DATE;
F7 DATE;
F8 DATE;
F9 DATE;
F10 DATE;
f11 CHAR(1);
BEGIN
--DBMS_OUTPUT.ENABLE(100000);
f := utl_file.fopen('MID5010_DOC1TP', 'OPT_CM_BASE.txt', 'R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f, s);
f1 := REGEXP_SUBSTR (s,'[^|]+',1,1);
f2 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,2);
F3 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,3);
F4 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,4);
F5 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,5);
F6 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,6),'mm-dd-yyyy');
F8 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,8),'mm-dd-yyyy');
F7 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,7),'mm-dd-yyyy');
F9 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,9),'mm-dd-yyyy');
F10 :=to_date(REGEXP_SUBSTR (REPLACE(s,'||','||') ,'[^|]+',1,10),'mm-dd-yyyy');
f11 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,11);
INSERT
INTO OPTUM_ICD10CM_BASE
( CODE,
STATUS,
SHORT_DESCRIPTION,
LONG_DESCRIPTION,
FULL_DESCRIPTION,
CODE_EFFECTIVE_DATE,
CHANGE_EFFECTIVE_DATE,
TERMINATION_DATE,
RELEASE_DATE,
CREATION_DATE,
VALIDITY
VALUES
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
f11
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
UTL_FILE.FCLOSE(F);
END;
please help me(in my org looks utl_file standards only) -
Splitting a list (loop and insert)
I have a text file with about 65000 records to be looped and
inserted into a
database. I am using cfhttp to read the list and turn it into
a query. I am
then using that query to loop and insert the records into a
database.
However, its too large and the server is timing out. Is there
a break the
list into 2 pieces and do it in serial?
I am using:
<cffunction name="getResidential" access="private"
returntype="void"
output="false" hint="">
<cfargument name="ResFile" type="string"
required="yes">
<cfhttp timeout="6600"
url="
http://www.mywebsite.com/assets/property/#ResFile#"
method="GET"
name="Property" delimiter="|" textqualifier=""
firstrowasheaders="yes" />
<cfloop query="Property">
<cfquery name="loopProperty" datasource="bpopros">
INSERT STATEMENT HERE
</cfquery>
</cfloop>
</cffunction>
Is it possible to do something like:
Function 1
<cfloop from="1" to="40000" index="i">
</cfloop>
Function 2
<cfloop from="40001" to="#Query.RecordCount#"
index="i">
</cfloop>
Any ideas? Thanks
Wally Kolcz
MyNextPet.org
Founder / Developer
586.871.4126I like your second solution, but wouldn't I need access to
the actual web
server? I need to do this on hosting. I am downloading the
files from a Real
Comp and then looping the data into my client's database for
searching. I
wanted to just use the files as a flat database and just
query or query off
of it, but there is a new file everyday. Only one update
(Sunday) is the
master list of 45-60k records. All the rest (Mon-Sat) are
just small
updates.
"Dan Bracuk" <[email protected]> wrote in
message
news:fdrgde$6qu$[email protected]..
> It's possible, but it's a better idea to look for ways
to do it without
> cold
> fusion.
>
> Food for thought, I have a requirement to move data from
one db to
> another. I
> use Cold Fusion to query the first db, output to text,
and ftp the text
> files
> to another server. I also have a scheduled job that
looks for these text
> files
> and loads them into db2.
> -
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 -
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= -
How to create a table with datatype blob and insert a pdf file (ravi)
how to create a table with datatype blob and insert a pdf file,
give me the explain asap
1.create the table?
2.insert the pdffiles into tables?
3.how to view the files?
Thanks & Regards
ravikumar.k
Edited by: 895044 on Dec 5, 2011 2:55 AM895044 wrote:
how to create a table with datatype blob and insert a pdf file,
give me the explain asapPerhaps you should read...
{message:id=9360002}
especially point 2.
We're not just sitting here waiting to answer your question as quickly as possible for you. -
Sample insert into table with BLOB column
This is my first opportunity to work with BLOB columns. I was wondering if anyone had some sample code that shows the loading of a blob column and inserted into the table with a blob column.
I have to produce a report (including crlf) and place it into a blob column. The user will download the report at a later time.
Any suggestions / code samples are greatly appreciated!!!!You can enable string binding in TopLink.
login.useStringBinding(int size);
or you could enable binding in general,
login.bindAllParameters();
Maybe you are looking for
-
Report to Check material attach in CJR2 (detail planning)
Hi All, Is there any report to show which material that i already input in CJr2 (detail planning) Step 1. CjR2 2. choose layout 1-701 CE planning 3. Input WBS and CE 4. Go to edit and detail planning 5. Input material no d
-
Transfer music from Windows 8.1 pc to iTunes library
transfer music from Windows 8.1 pc to iTunes library
-
Hi, User want to create po for below mentioned senario. They will purchase PLC control panel say for example -10,000 Rs for 1 Quantity. Errection of PLC is done say for example 2000 Rs software instaltion for PLC is for say 2000 rs Final testing and
-
in flash pro cc, how do i get the files i was working on previous session to open automatically?
-
Complete URL of an iView Component !!
Environment : EP 6.0 Sp2 Following is the complete url of an iview ... http://<servername>:<port>/irj/servlet/prt/portal/prtroot/<componentName>.default I am using the following code to get the url ... IPortalUrlGenerator portalGen = null; IUrlGenera