Reputation: 8166
I want to use the typical java notation. I need a Timer but I don't want to create a Package with just two variable (start and finish time, and a few methods).
Can I create a inline package, type or record that can contain functions?
Upvotes: 3
Views: 829
Reputation: 7928
You can use objects:
CREATE OR REPLACE TYPE timer AS OBJECT
(
start_time DATE
, end_time DATE
, CONSTRUCTOR FUNCTION timer
RETURN SELF AS RESULT
, MEMBER FUNCTION get_duration
RETURN NUMBER
)
;
/
CREATE OR REPLACE TYPE BODY timer IS
CONSTRUCTOR FUNCTION timer
RETURN SELF AS RESULT
IS
BEGIN
SELF.start_time := SYSDATE;
RETURN;
END;
MEMBER FUNCTION get_duration
RETURN NUMBER
IS
BEGIN
RETURN NVL(SELF.end_time, SYSDATE) - SELF.start_time;
END get_duration;
END;
/
Upvotes: 3