Home » Server Options » Spatial » Trigger to calculate length
Trigger to calculate length [message #75815] Mon, 20 October 2003 05:58 Go to next message
Jeffrey
Messages: 30
Registered: January 2003
Member
Hi, i am a newbie to Oracle Spatial and Oracle itself.

My questions is, how do i write a trigger to calculate the length of and object and insert the value into one of the columns of the table?

I have tried the statement below, but it returns errors.

declare
tablename char(30); /* a variable to keep table name
tablename:= Test; /* error occurs here, Test is the name of the table
begin
:new.length:=sdo_geom.sdo_length(tablename.geoloc,user_sdo_geom_metadata); /* sdo_geom.sdo_length is the function that returns the length
end;

Can someone help me out with my trigger here?
Re: Trigger to calculate length [message #75837 is a reply to message #75815] Wed, 08 September 2004 10:46 Go to previous message
Bryan Hall
Messages: 6
Registered: September 2004
Junior Member
This should work (I did not test it) or at least get you closer. Just replace TABLENAME with your tablename. I'm assuming the geometry column is named geometry:

create trigger TABLENAME_TG
before insert or update on TABLENAME FOR EACH ROW
Begin
/* sdo_geom.sdo_length is the function that returns the length */
:new.length:=SELECT SDO_GEOM.SDO_LENGTH(c.geometry, m.diminfo)
FROM TABLENAME c, user_sdo_geom_metadata m
WHERE m.table_name = 'TABLENAME' AND m.column_name = 'GEOMETRY';

End;
/
Previous Topic: Does Oracle Spatial support floating point coordinates?
Next Topic: searching for an element in varray
Goto Forum:
  


Current Time: Sun Dec 22 02:24:20 CST 2024