CREATE FUNCTION [ owner_name.]udf_name ( [ parameter_decl [ , ... ] ] )
RETURN data_type [IMPORT java_import_clause ] BEGIN [ java_snippet ] END parameter_decl:= parameter_name data_type |
CREATE function EXTRACT(extractfield varchar(20), col timestamp)
return integer import import java.util.Date; begin extractfield=extractfield.toLowerCase(); switch(extractfield) { case "date" : return col.getDate(); case "month" : return col.getMonth(); case "year" : return col.getYear(); case "time" : return (int)col.getTime(); case "minute" : return (int)col.getMinutes(); case "hour" : return (int)col.getHours(); case "second" : return (int)col.getSeconds(); case "day" : return col.getDay(); case "default" : return -1; } return 1; end |
SELECT EXTRACT('date' , orderdate) from pub.order;
EXTRACT(date,OrderDate) ----------------------- 9 27 SELECT EXTRACT('day' , orderdate) from pub.order; EXTRACT(day,OrderDate) ---------------------- 3 5 SELECT EXTRACT('month' , orderdate) from pub.order; EXTRACT(month,OrderDate) ------------------------ 1 2 |