dbTalk Databases Forums  

Multi column update based on another table

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Multi column update based on another table in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sashi
 
Posts: n/a

Default Multi column update based on another table - 01-14-2008 , 06:53 PM






Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
------------------------------------------------------------------------------------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
------------------------------------------------------------------------------------------------------------

Quote:
[Error] Script lines: 1-7 --------------------------
ORA-01427: single-row subquery returns more than one row 


Can someone please help out?
Thanks in advance,
Sashi


Reply With Quote
  #2  
Old   
William Robertson
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 02:14 AM






On Jan 15, 12:53 am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
------------------------------------------------------------------------------------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
------------------------------------------------------------------------------------------------------------

[Error] Script lines: 1-7 --------------------------

ORA-01427: single-row subquery returns more than one row

Can someone please help out?
Thanks in advance,
Sashi
The syntax is fine. It looks like DEVICE_ID is not unique in
CITI_DEVICE though.


Reply With Quote
  #3  
Old   
William Robertson
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 02:14 AM



On Jan 15, 12:53 am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
------------------------------------------------------------------------------------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
------------------------------------------------------------------------------------------------------------

[Error] Script lines: 1-7 --------------------------

ORA-01427: single-row subquery returns more than one row

Can someone please help out?
Thanks in advance,
Sashi
The syntax is fine. It looks like DEVICE_ID is not unique in
CITI_DEVICE though.


Reply With Quote
  #4  
Old   
William Robertson
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 02:14 AM



On Jan 15, 12:53 am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
------------------------------------------------------------------------------------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
------------------------------------------------------------------------------------------------------------

[Error] Script lines: 1-7 --------------------------

ORA-01427: single-row subquery returns more than one row

Can someone please help out?
Thanks in advance,
Sashi
The syntax is fine. It looks like DEVICE_ID is not unique in
CITI_DEVICE though.


Reply With Quote
  #5  
Old   
William Robertson
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 02:14 AM



On Jan 15, 12:53 am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
------------------------------------------------------------------------------------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
------------------------------------------------------------------------------------------------------------

[Error] Script lines: 1-7 --------------------------

ORA-01427: single-row subquery returns more than one row

Can someone please help out?
Thanks in advance,
Sashi
The syntax is fine. It looks like DEVICE_ID is not unique in
CITI_DEVICE though.


Reply With Quote
  #6  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 08:08 AM



Comments embedded.
On Jan 14, 6:53*pm, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
It isn't. You didn't receive a syntax error message, you received an
error message stating your single-row subquery returns more than one
row. Which indicates the 'key' in CITI_DEVICE isn't unique.

Quote:
---------------------------------------------------------------------------*---------------------------------
update CITI_CIRCUIT_LBCODE A
Set *(LOOPBACK_ADDR_A, HOST_NAME_A ) = *(SELECT
* * * * * * * * * * * * * * * * * * * * * LOOPBACK_ADDR,
* * * * * * * * * * * * * * * * * * * * * HOST_NAME
* * * * * * * * * * * * * * * * * * * * *FROM
* * * * * * * * * * * * * * * * * * * * *CITI_DEVICE B
* * * * * * * * * * * * * * * * * * * * *WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
---------------------------------------------------------------------------*---------------------------------

[Error] Script lines: 1-7 --------------------------

*ORA-01427: single-row subquery returns more than one row *
Meaning that for each row in table A you have multiple rows in table
B. Execute this query to see the problem:

select device_id, count(*)
from citi_device
group by device_id;

You'll notice that most, if not all, device_id's will produce a
count(*) greater than 1, and this is the source of your difficulties.
You'll need to find a distinct column to join on between the
CITI_DEVICE and CITI_CIRCUIT_LBCODE tables, if that's possible. Or
you'll need to find a combination of column values which will return
only one row from CITI_DEVICE for each row in CITI_CIRCUIT_LBCODE.

Quote:
Can someone please help out?
Thanks in advance,
Sashi

David Fitzjarrell


Reply With Quote
  #7  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 08:08 AM



Comments embedded.
On Jan 14, 6:53*pm, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
It isn't. You didn't receive a syntax error message, you received an
error message stating your single-row subquery returns more than one
row. Which indicates the 'key' in CITI_DEVICE isn't unique.

Quote:
---------------------------------------------------------------------------*---------------------------------
update CITI_CIRCUIT_LBCODE A
Set *(LOOPBACK_ADDR_A, HOST_NAME_A ) = *(SELECT
* * * * * * * * * * * * * * * * * * * * * LOOPBACK_ADDR,
* * * * * * * * * * * * * * * * * * * * * HOST_NAME
* * * * * * * * * * * * * * * * * * * * *FROM
* * * * * * * * * * * * * * * * * * * * *CITI_DEVICE B
* * * * * * * * * * * * * * * * * * * * *WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
---------------------------------------------------------------------------*---------------------------------

[Error] Script lines: 1-7 --------------------------

*ORA-01427: single-row subquery returns more than one row *
Meaning that for each row in table A you have multiple rows in table
B. Execute this query to see the problem:

select device_id, count(*)
from citi_device
group by device_id;

You'll notice that most, if not all, device_id's will produce a
count(*) greater than 1, and this is the source of your difficulties.
You'll need to find a distinct column to join on between the
CITI_DEVICE and CITI_CIRCUIT_LBCODE tables, if that's possible. Or
you'll need to find a combination of column values which will return
only one row from CITI_DEVICE for each row in CITI_CIRCUIT_LBCODE.

Quote:
Can someone please help out?
Thanks in advance,
Sashi

David Fitzjarrell


Reply With Quote
  #8  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 08:08 AM



Comments embedded.
On Jan 14, 6:53*pm, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
It isn't. You didn't receive a syntax error message, you received an
error message stating your single-row subquery returns more than one
row. Which indicates the 'key' in CITI_DEVICE isn't unique.

Quote:
---------------------------------------------------------------------------*---------------------------------
update CITI_CIRCUIT_LBCODE A
Set *(LOOPBACK_ADDR_A, HOST_NAME_A ) = *(SELECT
* * * * * * * * * * * * * * * * * * * * * LOOPBACK_ADDR,
* * * * * * * * * * * * * * * * * * * * * HOST_NAME
* * * * * * * * * * * * * * * * * * * * *FROM
* * * * * * * * * * * * * * * * * * * * *CITI_DEVICE B
* * * * * * * * * * * * * * * * * * * * *WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
---------------------------------------------------------------------------*---------------------------------

[Error] Script lines: 1-7 --------------------------

*ORA-01427: single-row subquery returns more than one row *
Meaning that for each row in table A you have multiple rows in table
B. Execute this query to see the problem:

select device_id, count(*)
from citi_device
group by device_id;

You'll notice that most, if not all, device_id's will produce a
count(*) greater than 1, and this is the source of your difficulties.
You'll need to find a distinct column to join on between the
CITI_DEVICE and CITI_CIRCUIT_LBCODE tables, if that's possible. Or
you'll need to find a combination of column values which will return
only one row from CITI_DEVICE for each row in CITI_CIRCUIT_LBCODE.

Quote:
Can someone please help out?
Thanks in advance,
Sashi

David Fitzjarrell


Reply With Quote
  #9  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 08:08 AM



Comments embedded.
On Jan 14, 6:53*pm, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:
It isn't. You didn't receive a syntax error message, you received an
error message stating your single-row subquery returns more than one
row. Which indicates the 'key' in CITI_DEVICE isn't unique.

Quote:
---------------------------------------------------------------------------*---------------------------------
update CITI_CIRCUIT_LBCODE A
Set *(LOOPBACK_ADDR_A, HOST_NAME_A ) = *(SELECT
* * * * * * * * * * * * * * * * * * * * * LOOPBACK_ADDR,
* * * * * * * * * * * * * * * * * * * * * HOST_NAME
* * * * * * * * * * * * * * * * * * * * *FROM
* * * * * * * * * * * * * * * * * * * * *CITI_DEVICE B
* * * * * * * * * * * * * * * * * * * * *WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
---------------------------------------------------------------------------*---------------------------------

[Error] Script lines: 1-7 --------------------------

*ORA-01427: single-row subquery returns more than one row *
Meaning that for each row in table A you have multiple rows in table
B. Execute this query to see the problem:

select device_id, count(*)
from citi_device
group by device_id;

You'll notice that most, if not all, device_id's will produce a
count(*) greater than 1, and this is the source of your difficulties.
You'll need to find a distinct column to join on between the
CITI_DEVICE and CITI_CIRCUIT_LBCODE tables, if that's possible. Or
you'll need to find a combination of column values which will return
only one row from CITI_DEVICE for each row in CITI_CIRCUIT_LBCODE.

Quote:
Can someone please help out?
Thanks in advance,
Sashi

David Fitzjarrell


Reply With Quote
  #10  
Old   
Sashi
 
Posts: n/a

Default Re: Multi column update based on another table - 01-15-2008 , 09:04 AM



On Jan 15, 9:08 am, "fitzjarr... (AT) cox (DOT) net" <fitzjarr... (AT) cox (DOT) net> wrote:
Quote:
Comments embedded.
On Jan 14, 6:53 pm, Sashi <small... (AT) gmail (DOT) com> wrote:

Hi Folks,
I'm writing a simple update statement in Ora 9.2 and am scratching my
head as to why the following syntax is wrong:

It isn't. You didn't receive a syntax error message, you received an
error message stating your single-row subquery returns more than one
row. Which indicates the 'key' in CITI_DEVICE isn't unique.

---------------------------------------------------------------------------*---------------------------------
update CITI_CIRCUIT_LBCODE A
Set (LOOPBACK_ADDR_A, HOST_NAME_A ) = (SELECT
LOOPBACK_ADDR,
HOST_NAME
FROM
CITI_DEVICE B
WHERE A.DEVICE_NAME_A =
B.DEVICE_ID);
---------------------------------------------------------------------------*---------------------------------

[Error] Script lines: 1-7 --------------------------

ORA-01427: single-row subquery returns more than one row

Meaning that for each row in table A you have multiple rows in table
B. Execute this query to see the problem:

select device_id, count(*)
from citi_device
group by device_id;

You'll notice that most, if not all, device_id's will produce a
count(*) greater than 1, and this is the source of your difficulties.
You'll need to find a distinct column to join on between the
CITI_DEVICE and CITI_CIRCUIT_LBCODE tables, if that's possible. Or
you'll need to find a combination of column values which will return
only one row from CITI_DEVICE for each row in CITI_CIRCUIT_LBCODE.



Can someone please help out?
Thanks in advance,
Sashi

David Fitzjarrell
Thanks, all. I thought as much.

I have a question: is it possible to use the distinct clause so that
the results are distinct only based on one column and not the entire
record?
Thanks,
Sashi


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.