用户定义operator的特性:
identified by names, which are in the same namespace as tables, views, types, and standalone functions
bound to functions, which define operator behavior in specified contexts
controlled by privileges, which indicate the circumstances in which each operator can be used
often associated with indextypes, which can be used to define indexes that are not built into the database
operator可以绑定的函数有:
standalone functions
package functions
user-defined type member methods
与operator相关的数据字典:
user_operator_comments
all_operator_comments
dba_operator_comments
operator可以使用的地方(同函数很相似的):
the select list of a select command
the condition of a where clause
the order by and group by clauses
-- (具体语法请参考oracle database sql reference)
-- 创建operator
create operator ordsys.contains
binding(varchar2, varchar2) return number
using text.contains,
(spatial.geo, spatial.geo) return number
using spatial.contains;
-- 删除operator
drop operator contains;
drop operator contains force;
-- alter operator
alter operator ordsys.contains
add binding (music.artist, music.artist) return number
using music.contains;
-- 给operator加注释
comment on operator
ordsys.contains is 'a number indicating whether the text contains the key';
examples
-- 创建operator
create operator ordsys.contains
binding(varchar2, varchar2) return number
using text.contains,
(spatial.geo, spatial.geo) return number
using spatial.contains;
-- operator的使用
select * from employee
where contains(resume, 'oracle')=1 and contains(location, :bay_area)=1;
/*
contains(resume, 'oracle') 实质是使用 text.contains(resume, 'oracle')
contains(location, :bay_area) 实质是使用 spatial.contains(location, :bay_area)
有点象c 中的函数重载噢.
*/
我的示例:
-- 创建函数
create or replace function osm_dml_3sp.osm_func_op_1(a number)
return integer as
begin
if a > 292 then
return (a-95);
else
return (a 63);
end if;
end;
/
create or replace function osm_dml_3sp.osm_func_op_2(s varchar2)
return integer as
begin
if length(s) > 37 then
return (-50);
else
return (91);
end if;
end;
/
create or replace operator osm_dml_3sp.osm_dml_oper
binding (number) return integer
using osm_dml_3sp.osm_func_op_1,
(varchar2) return integer using osm_dml_3sp.osm_func_op_2;
/
begin
insert into osm_dml_3sp.osm_tab_operator select * from osm_dml_3sp.osm_tab_operator
where osm_dml_3sp.osm_dml_oper(col_0) > 40;
insert into osm_dml_3sp.osm_tab_operator select * from osm_dml_3sp.osm_tab_operator
where osm_dml_3sp.osm_dml_oper(col_3) > 0;
commit;
end;
我的示例是通过c自动产生的, 所以看起来有点奇怪, 为了保证通用性的需要!
阅读(3643) | 评论(0) | 转发(0) |