Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2005
    Posts
    276

    Unanswered: populating data into tables

    I have the following code, where I'm populating data from tab2 to tab1 using dblink and also checking for a condition(using tab2 and tab3). Is the syntax of the code correct ??
    Can you please let me know if the highlighted part is correct.
    I'm getting the ORA 00918 ERROR..

    insert /* +append parallel(t1,2)*/ into tab1 t1
    (
    id,
    name,
    addr,
    phno,
    phno2,
    ...
    ...
    )
    select
    (
    id
    name,
    addr,
    phno,
    0
    ...
    ...
    )
    from tab2@mylink t2, tab3@mylink t3
    where t2.id=t3.id and
    t2.name=t3.name and
    t2.addr=t3.addr

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    You need to qualify your columns in the select statement:
    Code:
    INSERT ...
    select
    (
    t2.id,
    t2.name,
    t2.addr,
    t2.phno,
    0
    ...
    ...
    ) FROM ...

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Jul 2005
    Posts
    276
    When i do a simple insert ..
    insert into...
    (..
    ..)
    select
    ..
    ..
    from tab2@mylink;
    It works absolutely fine. When I add the tab3 dblink and the join condition, I'm getting the error of ora 00918

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    What part of LKBrwn_DBA response did you NOT understand?
    You will NEVER get an ORA-00918 when selecting from a single table.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Jul 2005
    Posts
    276
    It works...there was a typo in between..
    Thank you so much.

  6. #6
    Join Date
    Jul 2005
    Posts
    276
    I have another question related to this...
    What if I have a condition say t1.name=t3.ename to be included..
    I did like this..
    insert /* +append parallel(t1,2)*/ into tab1 t1
    (
    id,
    name,
    addr,
    phno,
    phno2,
    ...
    ...
    )
    select
    (
    t2.id
    t2.name,
    t2.addr,
    t2.phno,
    0
    ...
    ...
    )
    from tab2@mylink t2, tab3@mylink t3
    where t2.id=t3.id and
    t2.name=t3.name and
    t2.addr=t3.addr and
    t1.name=t3.ename
    I get an error at t1.name=t3.ename, ORA00904.

  7. #7
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    There is no table or alias with the name "t1" in the query.

  8. #8
    Join Date
    Jul 2005
    Posts
    276
    insert /* +append parallel(t1,2)*/ into tab1 t1
    (
    id,
    name,
    addr,
    phno,
    phno2,
    ...
    ...
    )
    select
    (
    id
    name,
    addr,
    phno,
    0
    ...
    ...
    )
    from tab2@mylink t2, tab3@mylink t3
    where t2.id=t3.id and
    t2.name=t3.name and
    t2.addr=t3.addr
    tab1 gets populated from tab2 for most of the columns except few, which I have to get from another table tab3

  9. #9
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Yes, but you can't use it here. This table MUST BE part of the FROM clause (among "tab2@mylink t2, tab3@mylink t3").

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •