[Oracle 9i] Rijen van ene naar andere DB overzetten

Pagina: 1
Acties:

  • The Eagle
  • Registratie: Januari 2002
  • Laatst online: 22:23

The Eagle

I wear my sunglasses at night

Topicstarter
Lieden,

We draaien hier met PeopleSoft. Dat draait heel fijn op een Oracle 9i DB'tje. Nou wil het geval dat PS in het verleden een keer een hickup heeft gehad, waardoor ik in een tabel 4 rijen mis. Die rijen opnieuw aanmaken en op DB-niveau aanpassen zodat ze weer passen bij de data die al in het systeem stond, is niet zo'n probleem. Het probleem is wel dat de rijen opnieuw aanmaken niet op de productiedatabase kan gebeuren. Dat zal dus op een test-DB plaats moeten vinden. Vervolgens moeten die rijen in zijn geheel (na aangepast te zijn door ondergetekende :Y) ) ge-insert worden in de zelfde tabel in de productiedatabase. En dat laatste is de vraag: hoe doe je dat :?
Wanneer je in de zelfde DB zit kun je gewoon:
code:
1
2
3
4
5
insert into TABLE_2
select * from TABLE_1 
where VELD_1 = 'A'
and VELD_2 ='10
;

doen. Waarop vrolijk de rijen van de ene tabel in de andere geinsert worden.

Maar hoe doe je zoiets als TABLE_1 zich in DB _1 bevindt en TABLE_2 zich in DB_2 bevindt :?

Mijn dank is groot _/-\o_

Al is het nieuws nog zo slecht, het wordt leuker als je het op zijn Brabants zegt :)


  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

Met een database-link of via een COPY commando in SQL*Plus.
code:
1
copy from user/pw@db1 to user/pw@db2 insert <tabelnaam> using select...

Who is John Galt?


  • The Eagle
  • Registratie: Januari 2002
  • Laatst online: 22:23

The Eagle

I wear my sunglasses at night

Topicstarter
justmental schreef op woensdag 15 december 2004 @ 09:45:
Met een database-link of via een COPY commando in SQL*Plus.
code:
1
copy from user/pw@db1 to user/pw@db2 insert <tabelnaam> using select...
Ga ik zo ff proberen :) Maakt het nog uit in welke DB ik dan zit als ik dat commando uitvoer? Moet ik het commando geven vanuit de source- of vanuit de target DB?

Al is het nieuws nog zo slecht, het wordt leuker als je het op zijn Brabants zegt :)


  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

The_Eagle schreef op woensdag 15 december 2004 @ 09:54:
Ga ik zo ff proberen :) Maakt het nog uit in welke DB ik dan zit als ik dat commando uitvoer? Moet ik het commando geven vanuit de source- of vanuit de target DB?
Maakt niet uit, mag zelfs vanuit een derde.

Who is John Galt?


  • The Eagle
  • Registratie: Januari 2002
  • Laatst online: 22:23

The Eagle

I wear my sunglasses at night

Topicstarter
Thanx, dit werkt zo te zien :)

Wellicht wel handig om voor het nageslacht even te vermelden dat het gehele copy-commando op 1 regel moet staan; een copy/past vanuit een texteditor waarbij bijv de select op meerdere regels staat werkt helaas niet.

Case solved :)

Al is het nieuws nog zo slecht, het wordt leuker als je het op zijn Brabants zegt :)


  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

Daar is een teken voor om aan te geven dat je op de volgende regel verder gaat, ik meen een streepje -

Who is John Galt?


  • The Eagle
  • Registratie: Januari 2002
  • Laatst online: 22:23

The Eagle

I wear my sunglasses at night

Topicstarter
Thanx for the info mate :)

Maar ik moet me diep schamen - ik bedacht me achteraf dat ik hier dus een complete Oracle 8i DBA Bible had staan - met een complete SQLPlus Reference guide. Ik had het dus ook gewoon op kunnen zoeken :X :X

Voor het nageslacht dan maar, om het geheel te completeren, een stukje uit die reference guide:
COPY
The COPY command allows you to copy data from one table to another table. The
tables may be in different databases. Following is its syntax:
code:
1
2
3
4
5
6
COPY {FROM login|TO login}
{APPEND|CREATE|INSERT|REPLACE}
destination_table [( column_list)]
USING select_statement

login := username/ password@service


The syntax elements are as follows:
code:
1
2
3
4
5
6
7
8
9
10
username                   Specifies your Oracle username.
password                   Specifies your password.
service                       Specifies a Net8 service name.
APPEND                    Creates the destination table if it doesn&#8217;t already exist.
CREATE                    Creates the destination table.
INSERT                      Causes SQL*Plus to return an error if the destination table doesn&#8217;t exist.
REPLACE                  Deletes the data in the destination table before doing the copy. The table will be created if it doesn&#8217;t already exist.
destination_table          Identifies the table to which you are copying the data.
column_list                  Identifies the list of columns in the destination table that are to receive the data being copied.
select_statement         Specifies the SELECT statement that retrieves the data that you want to copy.


The example in Listing C-7 shows the COPY command being used to copy the ID_NO and ANIMAL_NAME columns of the AQUATIC_ANIMAL table to a new table in a remote database.

Listing C-7: Copy example
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
SQL> COPY TO seapark/seapark@seapark_remote -
> CREATE aquatic_animal_copy -
> USING SELECT id_no, animal_name -
> FROM aquatic_animal;

Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
Table AQUATIC_ANIMAL_COPY created.

  10 rows selected from DEFAULT HOST connection.
  10 rows inserted into AQUATIC_ANIMAL_COPY.
  10 rows committed into AQUATIC_ANIMAL_COPY at seapark@seapark_remote.
Zoals te zien in dat voorbeeld C-7: het was dus idd een streepje :Y)

[ Voor 4% gewijzigd door The Eagle op 15-12-2004 12:00 ]

Al is het nieuws nog zo slecht, het wordt leuker als je het op zijn Brabants zegt :)

Pagina: 1