温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iTop中的OQL的语法格式

发布时间:2020-05-22 09:56:09 来源:亿速云 阅读:852 作者:Leah 栏目:系统运维

iTop中OQL是什么?今天小编给大家分享的是iTop中的OQL的详细介绍,相信大部分人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,话不多说,一起往下看吧。

iTop的OQL(object query language)只支持一种类型,即查询语句,也就是SQL查询中的Select语句。OQL用于过滤或查询,可在iTop中用于邮件通知、审计规则等。OQL的返回值限于一个对象或者一组iTop对象。iTop将OQL最终翻译成对应的SQL Select语句,所以可以将OQL看做是SQL Select的一个子集,功能上不如SQL语句那么灵活,但足以应付iTop中各种操作。注意,OQL中的SQL保留字都必须大写,语法大小写敏感,所以每个对象的大小写必须准确。
OQL语法格式非常简单,形式如下,

          SELECT
          [output_specification FROM]
          class_reference
          [class_joined]
          [WHERE expression]
          [UNION oql_query]

其中各项参数解释如下,

1. [output_specification FROM] , 此为可选项,当使用了多个对象或者别名时才需要用到。
如:

SELECT p1 FROM Person as p1, 此处p1为Person的别名。

或者类似于:

SELECT p1,t1 FROM Person JOIN lnkPersonToTeam AS t1 ON t1.person_id=p1.id

2. class_reference, 查询的对象名,如上例中的Person。当不使用别名时,可以直接使用如下形式获取数据

>SELECT Person

则iTop自动从Person对象表中获取数据

如果iTop对象名或要使用的别名与SQL保留字冲突,则对象名或别名必须用``包装起来。如,

SELECT `Union`。

3. [class_joined],如上面的例子,描述需要关联的其他对象。这个等于SQL语句的JOIN。具体格式为JOIN object2 ON object1.attribute1 [操作符] object2.attirbute1,其中操作符如下,

=, BELOW, BELOW STRICT, ABOVE or ABOVE STRICT.

其中BELOW和ABOVE相关的几个操作符用于当对象1和对象2有从属关系时。比如iTop中的服务和子服务。

4. [WHERE expression],与SQL的WHERE语句一样的功能,expression支持的语法和函数下面再进行描述。

5. [UNION oql_query], 与SQL的UNION的语句一样的功能。其中oql_query只要符合OQL语法即可。但此处的OQL返回的对象应该与主语句一致。

WHERE表达式语法,
WHERE表达式可以由几个部分组成,即字符串、操作符、函数,最终形成一个布尔结果值,实现数据筛选。这个跟SQL的WHERE子句功能一致。

操作符表如下,

OperatorDescription
ANDLogical AND
ORLogical OR
/Division operator
=Equality operator
>=Greater than or equal operator
>Greater than operator
<=Less than or equal operator
<Less than operator
-Substraction operator
!=, <>Non-equality operator
LIKESimple pattern matching
NOT LIKENegation of simple pattern matching
INList operator
NOT INNegation of list operator
&New in 2.0.1 Bitwise operator “and”. This operator is different from the “logical” operator “AND” since it operates on every bit of each number.
New in 2.0.1 Bitwise operator “or”. This operator is different from the “logical” operator “OR” since it operates on every bit of each number.
^New in 2.0.1 Bitwise operator “xor”.
<<New in 2.0.1 Bitwise left shift
>>New in 2.0.1 Bitwise right shift
REGEXPRegular expression
MATCHESNew in 2.6.0 Fulltext match against a string. This operator only works with attributes of type TagSet. The supported syntax is attribute MATCHES 'code1 code2'

函数列表如下,

Function nameDescriptionExamples
COALESCEReturn the first non-NULL argumentCOALESCE(field1, field2, 'Undefined')
CONCATReturn concatenated stringCONCAT(firstname, ' ', lastname)
CURRENT_DATEReturn the current dateCURRENT_DATE()
DATEExtract the date part of a date or datetime expressionDATE()
DATE_ADDAdd time values (intervals) to a date value. See allowed interval units belowDATE_ADD(NOW(), INTERVAL 1 HOUR)
DATE_FORMATFormat date as specifiedDATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y')
DATE_SUBSubstract time values (intervals) from a date value. See allowed interval units belowDATE_SUB(NOW(), INTERVAL 5 MINUTE)
DAYReturn the day of the month (0-31)DAY(DATE())
ELTReturn string at index numberELT(index, 'string1', 'string2', 'string3')
FLOORReturn the largest integer value not greater than the argumentFLOOR(12.356)
FROM_DAYSConvert a day number to a dateFROM_DAYS(12345)
IFIf/else constructIF(a=b, 'equals', 'differs')
INET_ATONReturn the numeric value of an IP addressINET_ATON('15.15.121.12')
INET_NTOAReturn the IP address from a numeric valueINET_NTOA(1231654)
ISNULLISNULL(field1)
MONTHReturn the month from the date passedMONTH(DATE())
NOWReturn the current date and timeNOW()
ROUNDRound the argumentROUND(12.356, 2)
SUBSTRReturn the substring as specifiedSUBSTR('abcdef', 2, 3)
TIMEExtract the time portion of the expression passedTIME()
TO_DAYSReturn the date argument converted to daysTO_DAYS('2009-05-01')
TRIMRemove leading and trailing spacesTRIM('  blah  ')
YEARReturn the year from the date passedYEAR(DATE())

其他说明,
current_contact和current_user可以作为两个与当前登录用户相关的通用变量,从而可以在表达式中进行使用,使用格式如下,

:current_contact→attribute  where 'attribute' is any code attribute of the Contact class
:current_user→attribute where 'attribute' is any code attribute of the User class

如:
SELECT UserRequest WHERE agent_id = :current_contact->id AND status NOT IN ('closed', 'resolved')

看完上述内容,你们对iTop中的OQL大概了解了吗?如果想了解更多相关文章内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI