oracle中condition和operator的区别

 我来答
千锋教育
2016-08-15 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
用户定义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;
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式