Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Updating multiple rows with calculated values (distance by Pythagorean theorem)

1ddb0fc1-fc76-4548-a8f5-708fc37d36a1Dec 11 2014 — edited Dec 11 2014

Updating multiple rows with calculated values (distance by Pythagorean theorem)

Very confused been sat in front of this screen for 6 hours straight trying to figure this out -  how do I update all rows with calculated data derived from the values in two other columns of the same record.

here's the situation:

I have a table called 'customers'. It had 4 columns - 'Customer_ID', 'Customer_Name', ' Coordinate_X' and 'Coordinate_Y'. since creating and filling the table with data I have added an empty 5th column called 'Distance'

What I'd like to do is fill the 'distance' column with the calculated distances from (0,0) to the locations specified in the 'Coordinate_X' and 'Coordinate_Y' columns of each row. I figured I could use Pythagoras's theory - and the correct values come up when I use the query:

Select SQRT(Power(customers.coordinate_x,2) + Power(customers.coordinate_y,2)) from customers

I fiddled about trying to make a trigger - failed that through lack of experience.

messed about trying to create a vie - failed that

Then I tried to fill the column using queries - failed that too.

I've been trying things like this;

update customers set distance = (Select SQRT(Power(customers.coordinate_x,2) + Power(customers.coordinate_y,2)) from customers)

Nothing's working - the best I'm getting is ORA-01427: single-row subquery returns more than one row

Any ideas?

Kind regards,

Neil

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2015
Added on Dec 11 2014
3 comments
1,613 views