Home » Other » Client Tools » Handling DATETIME format using SQLPLUS COPY command (Oracle 11G)
Handling DATETIME format using SQLPLUS COPY command [message #562128] |
Sun, 29 July 2012 02:22 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
infinitenumbers
Messages: 33 Registered: November 2010
|
Member |
|
|
Hi Guys,
I am using the SQL*PLUS COPY command to move the data from my database to another remote database. The data in my database also contains DATETIME format. But since COPY command cannot handle DATETIME format, I am wondering is there any workaround for this.
Note: Due to some limitations, I cannot use other methods like DATABASE LINK or EXPDP/IMPDP commands.
Thanks in Advance,
shil
[Updated on: Sun, 29 July 2012 02:26] Report message to a moderator
|
|
|
|
Re: Handling DATETIME format using SQLPLUS COPY command [message #562260 is a reply to message #562128] |
Mon, 30 July 2012 18:00 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](//www.gravatar.com/avatar/da93b8d9f57f4be8145750e5748ac9cd?s=64&d=mm&r=g) |
alan.kendall@nfl.com
Messages: 163 Registered: June 2012 Location: Culver City, California
|
Senior Member |
|
|
Shil,
I create insert statements that I spool to a flat file. Then I run the insert
statements on the other database.
The complicated part is that I insert with sqlplus "O'hara" as "O''hara" because sqlplus
will convert the 2 quotes to 1 quote. There are ways to get around this but I find that
code releases work much better with just the two quotes instead of one.
What is really weird is that my code is also run in sqlplus so when I run "temp.sql"
I need 4 quotes that will be converted to 2 and 2 quotes that will be converted to 1.
See "temp.sql" below.
SCOTT > select * from alan;
EMPNO ENAME JOB MGR HIREDATE
---------- ---------- --------- ---------- --------------------------------------------
7369 SMITH CLERK 7902 17-DEC-80 12.00.00.000000 AM
7499 O'hara SALESMAN 7698 20-FEB-81 12.00.00.000000 AM
7521 WARD SALESMAN 7698 22-FEB-81 12.00.00.000000 AM
7566 JONES MANAGER 7839 02-APR-81 12.00.00.000000 AM
7654 MARTIN SALESMAN 7698 28-SEP-81 12.00.00.000000 AM
7698 BLAKE MANAGER 7839 01-MAY-81 12.00.00.000000 AM
7782 CLARK MANAGER 7839 09-JUN-81 12.00.00.000000 AM
7788 SCOTT ANALYST 7566 19-APR-87 12.00.00.000000 AM
SCOTT > @temp
insert into ALAN values(7369,'SMITH','CLERK',7902,'17-DEC-80 12.00.00.000000 AM');
insert into ALAN values(7499,'O''hara','SALESMAN',7698,'20-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7521,'WARD','SALESMAN',7698,'22-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7566,'JONES','MANAGER',7839,'02-APR-81 12.00.00.000000 AM');
insert into ALAN values(7654,'MARTIN','SALESMAN',7698,'28-SEP-81 12.00.00.000000 AM');
insert into ALAN values(7698,'BLAKE','MANAGER',7839,'01-MAY-81 12.00.00.000000 AM');
insert into ALAN values(7782,'CLARK','MANAGER',7839,'09-JUN-81 12.00.00.000000 AM');
insert into ALAN values(7788,'SCOTT','ANALYST',7566,'19-APR-87 12.00.00.000000 AM');
SCOTT > list
1 select 'insert into ALAN values('
2 ||nvl(to_char(EMPNO),'null')
3 ||','||''''||replace(ENAME,'''','''''')||''''
4 ||','||''''||replace(JOB,'''','''''')||''''
5 ||','||nvl(to_char(MGR),'null')
6 ||','||''''||replace(HIREDATE,'''','''''')||''''
7* ||');' from SCOTT.ALAN
For tables with few rows I just cut and paste the insert
statements from one session to the other to run them.
If you describe one of your tables, I would be happy to put together the first sql for you.
Alan
|
|
|
|
|
|
|
|
|
|
Re: Handling DATETIME format using SQLPLUS COPY command [message #562619 is a reply to message #562523] |
Thu, 02 August 2012 18:52 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](//www.gravatar.com/avatar/da93b8d9f57f4be8145750e5748ac9cd?s=64&d=mm&r=g) |
alan.kendall@nfl.com
Messages: 163 Registered: June 2012 Location: Culver City, California
|
Senior Member |
|
|
You can simply connect to the database, spool the contents to a file and then connect to the other database and run the inserts.
SCOTT > connect scott/tiger@cscdap1p
Connected.
SCOTT > select * from alan;
7369 SMITH CLERK 7902 17-DEC-80 12.00.00.000000 AM
7499 O'hara SALESMAN 7698 20-FEB-81 12.00.00.000000 AM
7521 WARD SALESMAN 7698 22-FEB-81 12.00.00.000000 AM
7566 JONES MANAGER 7839 02-APR-81 12.00.00.000000 AM
7654 MARTIN SALESMAN 7698 28-SEP-81 12.00.00.000000 AM
7698 BLAKE MANAGER 7839 01-MAY-81 12.00.00.000000 AM
7782 CLARK MANAGER 7839 09-JUN-81 12.00.00.000000 AM
7788 SCOTT ANALYST 7566 19-APR-87 12.00.00.000000 AM
SCOTT > connect scott/tiger@cscdas1s
Connected.
SCOTT > select * from alan;
no rows selected
Watch me run the following "temp.sql" script to spool out the
rows from production and load them into stage.
"temp.sql" looks like the following:
connect scott/tiger@cscdap1p
set lines 300
set pages 0
set feedback off
spool temp.lst
select 'insert into ALAN values('
||nvl(to_char(EMPNO),'null')
||','||''''||replace(ENAME,'''','''''')||''''
||','||''''||replace(JOB,'''','''''')||''''
||','||nvl(to_char(MGR),'null')
||','||''''||replace(HIREDATE,'''','''''')||''''
||');' from SCOTT.ALAN;
spool off
set pages 50
set feedback on
connect scott/tiger@cscdas1s
@temp.lst
commit;
SCOTT > @temp
Connected.
insert into ALAN values(7369,'SMITH','CLERK',7902,'17-DEC-80 12.00.00.000000 AM');
insert into ALAN values(7499,'O''hara','SALESMAN',7698,'20-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7521,'WARD','SALESMAN',7698,'22-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7566,'JONES','MANAGER',7839,'02-APR-81 12.00.00.000000 AM');
insert into ALAN values(7654,'MARTIN','SALESMAN',7698,'28-SEP-81 12.00.00.000000 AM');
insert into ALAN values(7698,'BLAKE','MANAGER',7839,'01-MAY-81 12.00.00.000000 AM');
insert into ALAN values(7782,'CLARK','MANAGER',7839,'09-JUN-81 12.00.00.000000 AM');
insert into ALAN values(7788,'SCOTT','ANALYST',7566,'19-APR-87 12.00.00.000000 AM');
Connected.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.
SCOTT > connect scott/tiger@cscdas1s
Connected.
SCOTT > select * from alan;
EMPNO ENAME JOB MGR HIREDATE
---------- ---------- --------- ---------- --------------------------------------------
7369 SMITH CLERK 7902 17-DEC-80 12.00.00.000000 AM
7499 O'hara SALESMAN 7698 20-FEB-81 12.00.00.000000 AM
7521 WARD SALESMAN 7698 22-FEB-81 12.00.00.000000 AM
7566 JONES MANAGER 7839 02-APR-81 12.00.00.000000 AM
7654 MARTIN SALESMAN 7698 28-SEP-81 12.00.00.000000 AM
7698 BLAKE MANAGER 7839 01-MAY-81 12.00.00.000000 AM
7782 CLARK MANAGER 7839 09-JUN-81 12.00.00.000000 AM
7788 SCOTT ANALYST 7566 19-APR-87 12.00.00.000000 AM
And the temp.lst that temp.sql created looks like the following:
insert into ALAN values(7369,'SMITH','CLERK',7902,'17-DEC-80 12.00.00.000000 AM');
insert into ALAN values(7499,'O''hara','SALESMAN',7698,'20-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7521,'WARD','SALESMAN',7698,'22-FEB-81 12.00.00.000000 AM');
insert into ALAN values(7566,'JONES','MANAGER',7839,'02-APR-81 12.00.00.000000 AM');
insert into ALAN values(7654,'MARTIN','SALESMAN',7698,'28-SEP-81 12.00.00.000000 AM');
insert into ALAN values(7698,'BLAKE','MANAGER',7839,'01-MAY-81 12.00.00.000000 AM');
insert into ALAN values(7782,'CLARK','MANAGER',7839,'09-JUN-81 12.00.00.000000 AM');
insert into ALAN values(7788,'SCOTT','ANALYST',7566,'19-APR-87 12.00.00.000000 AM');
|
|
|
|
|
Goto Forum:
Current Time: Thu Feb 06 00:17:33 CST 2025
|