1

I am trying to update a table B geom column with the coordinates from table A. Table A having coordinates in two separate columns x and y. Table B to have the coordinates from Table A into Table B's geom spatial column.

Table A and B have an ID in common for each record.

I usually use FME to do this but this time I'd like to do it using pure SQL.

Any suggestions on how to do it?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 3, 2015 at 1:53
2
  • stackoverflow.com/questions/14707442/… Commented Jun 3, 2015 at 2:09
  • @Mapperz, that answer about how to update SRID does not help much with this challenge. Commented Jun 3, 2015 at 7:40

1 Answer 1

2

This should work if your spatial table is "geo_table" and using SRID=4326, geometry column is "geometry", and coordinates are in table "coord_table" in columns "X" and "Y"

update geo_table a set a.geometry=
(select
SDO_GEOMETRY(2001,
4326,MDSYS.sdo_point_type(b.X,b.Y, NULL),NULL, NULL)
from coord_table b
where a.id=b.id);
answered Jun 3, 2015 at 7:35
2
  • Just nitpicking: you don't need the MDSYS prefix. Also parentheses around SDO_GEOMETRY are not required. But that is the correct solution. Commented Jun 3, 2015 at 9:39
  • Thanks, the cleaner the better so I edited my answer. I only tested that the statement gave correct result. Commented Jun 3, 2015 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.