home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!hayes!fgreene
- From: fgreene@hayes.com
- Newsgroups: comp.databases.oracle
- Subject: Re: SQL*Loader foreign key problem
- Message-ID: <6558.2b3048c0@hayes.com>
- Date: 17 Dec 92 09:30:40 EDT
- References: <1go4ktINNarb@fmsrl5.srl.ford.com>
- Organization: Hayes Microcomputer Products, Norcross, GA
- Lines: 54
-
- In article <1go4ktINNarb@fmsrl5.srl.ford.com>, hugh@slee01.srl.ford.com (Hugh Fader) writes:
- > I am having a problem with SQL*Loader and foreign keys. I have two
- > tables:
- >
- > CREATE TABLE components(
- > id NUMBER(4,0) NOT NULL,
- > confignum NUMBER(3,0) NOT NULL
- > [other stuff deleted]
- > )
- >
- > CREATE TABLE conventional_data(
- > id NUMBER(4,0) NOT NULL,
- > comp_id NUMBER(4,0) NOT NULL,
- > [other stuff deleted]
- > )
- >
- > The conventional_data.comp_id column is a foreign key which references
- > components.id.
- >
- > Here is my problem: I am trying to load data into the
- > conventional_data table using SQL*Loader. Each row in the external
- > file contains a confignum value which is assumed to pre-exist in the
- > components table. How can I assign a value to
- > conventional_data.comp_id that points to the appropriate row in the
- > components table? It seems as though I would have to use a SQL select
- > in order to do this. Have I hit the limit as to what SQL*Loader can
- > do?
- >
- > --
- > Hugh Fader
- > Ford Research Laboratory
- > hugh@slee01.srl.ford.com
- Using SQL*Loader, insert the data directy into the conventional_data
- table with a NULL value assigned to comp_id. After the load is complete,
- run a SQL*Plus script to update the conventional_data table and synch
- the values to the components table. Something like:
-
- update conventional_data A
- set comp_id = (select id
- from components B
- where B.confignum = B.confignum)
- Where comp_id is null;
-
- ---------------------------------------------------------------------------
- | Frank Greene | ////// ////// |
- | DELPHI SYSTEMS, Inc. | //// //// |
- | Telephone [615] 458-6032 | //// //// ////// |
- | 324 Ootsima Way | //// //// //// |
- | Loudon, TN 37774 | ////// ////// ////// |
- ----------------------------------------------------------------------------
- | Of course, any opinions or suggestions are strictly my own |
- ----------------------------------------------------------------------------
-
- >
-