oracle-databaseoracle-spatialsrid

Oracle: Change SDO_GEOMETRY's SRID for all tables in a schema


I need to change the SRID (set it to NULL) in the geometry objects of all tables in a specific schema (for a specific user)

The command:

UPDATE my_table t SET t.geometrie.sdo_srid = null;

works fine for a single table. When I try to do it in a loop for all tables of a specific owner:

BEGIN FOR my_tables IN ( SELECT TABLE_NAME from all_tables where OWNER = 'LANDWERTZONEN' AND TABLE_NAME NOT LIKE 'GOOM%' AND TABLE_NAME NOT LIKE '%BKP' ) LOOP DBMS_OUTPUT.PUT_LINE('UPDATE ' || my_tables || ' t SET t.geometrie.sdo_srid = null'); END LOOP; END;

I get the error:

pls-00306 wrong number or types of arguments in call to '||'

What could be the problem here? Wrong concatenation? Wrong call?

Any suggestions are very welcome.


Solution

  • Besides the syntax error that Littlefoot pointed out, you may extend the logic to actually perform the update rather than printing out the UPDATE statement:

    DECLARE
      sql_stmt varchar2(256);
    BEGIN
      FOR st IN (
        SELECT OWNER, TABLE_NAME, COLUMN_NAME 
        FROM all_tab_columns 
        WHERE OWNER = 'LANDWERTZONEN' 
        AND TABLE_NAME NOT LIKE 'GOOM%' 
        AND TABLE_NAME NOT LIKE '%BKP'
        AND DATA_TYPE = 'SDO_GEOMETRY'
      )
      LOOP
        sql_stmt := 'UPDATE ' || st.owner ||'.' || st.table_name || ' t SET t.'|| st.column_name ||'.sdo_srid = null';
        DBMS_OUTPUT.PUT_LINE('Executing ' || sql_stmt);
        execute immediate sql_stmt;
        COMMIT;
      END LOOP;
    END;
    /
    

    This actually restricts the change to actual spatial tables / columns.

    Note that you must make sure the spatial indexes are dropped before execution (and update metadata and recreate the spatial indexes after execution).

    BUT I would question the reason for setting the SRIDs to NULL. This will seriously remove functionality: you will no longer be able to perform any measurements (area, length, distances). Also you will no longer be able to relate the data with data that has explicit SRIDs (like a GPS point). And if the data is actually geodetic (long/lat) then operations like within_distance, buffer generation ... are essentially no longer possible.

    Our advice is to always explicitly use the correct SRIDs.