简体   繁体   中英

Copy a column from one table to another in oracle

I try to copy the column [codigomall] of the table 'sectores ' to the column [malla] of the table 'grm' . What I've tried so far is the following:

update grm
set grm.malla = (select c.codigomall from grm a, sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)
where exists (select c.codigomall from grm a, sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)

Oracle gives that the process is correct, but it doesn't copy any value in grm.malla .

I tried to replace c.codigmall with j.codigmall , but Oracle gave me an error:

update grm
set malla = (select j.codigomall from grm a, sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)
where exists (select j.codigomall from grm a, sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)

Do you know where I am failing? I have a feeling that the j.codigomall is a mistake

Context: There are two spatial layers, I want to inherit one column to another by spatial overlay

I think your problem is likely just that your outer table (the one you're updating) isn't connected to your select query in any way. I'm surprised that it isn't giving you an error, since you said the select query is returning multiple rows, and you're trying to assign them to a single column (grm.malla).

I'd try this and see if it helps.

update grm a
set a.malla = (select c.codigomall from sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)
where exists (select c.codigomall from sectores c, table(sdo_join('grm', 'geometry','sectores','geometry', 'mask=inside')) j where j.rowid1 = a.rowid and j.rowid2 = c.rowid)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM