溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

iTop中的OQL的語法格式

發(fā)布時(shí)間:2020-05-22 09:56:09 來源:億速云 閱讀:876 作者:Leah 欄目:系統(tǒng)運(yùn)維

iTop中OQL是什么?今天小編給大家分享的是iTop中的OQL的詳細(xì)介紹,相信大部分人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,話不多說,一起往下看吧。

iTop的OQL(object query language)只支持一種類型,即查詢語句,也就是SQL查詢中的Select語句。OQL用于過濾或查詢,可在iTop中用于郵件通知、審計(jì)規(guī)則等。OQL的返回值限于一個(gè)對(duì)象或者一組iTop對(duì)象。iTop將OQL最終翻譯成對(duì)應(yīng)的SQL Select語句,所以可以將OQL看做是SQL Select的一個(gè)子集,功能上不如SQL語句那么靈活,但足以應(yīng)付iTop中各種操作。注意,OQL中的SQL保留字都必須大寫,語法大小寫敏感,所以每個(gè)對(duì)象的大小寫必須準(zhǔn)確。
OQL語法格式非常簡(jiǎn)單,形式如下,

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

其中各項(xiàng)參數(shù)解釋如下,

1. [output_specification FROM] , 此為可選項(xiàng),當(dāng)使用了多個(gè)對(duì)象或者別名時(shí)才需要用到。
如:

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, 查詢的對(duì)象名,如上例中的Person。當(dāng)不使用別名時(shí),可以直接使用如下形式獲取數(shù)據(jù)

>SELECT Person

則iTop自動(dòng)從Person對(duì)象表中獲取數(shù)據(jù)

如果iTop對(duì)象名或要使用的別名與SQL保留字沖突,則對(duì)象名或別名必須用``包裝起來。如,

SELECT `Union`。

3. [class_joined],如上面的例子,描述需要關(guān)聯(lián)的其他對(duì)象。這個(gè)等于SQL語句的JOIN。具體格式為JOIN object2 ON object1.attribute1 [操作符] object2.attirbute1,其中操作符如下,

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

其中BELOW和ABOVE相關(guān)的幾個(gè)操作符用于當(dāng)對(duì)象1和對(duì)象2有從屬關(guān)系時(shí)。比如iTop中的服務(wù)和子服務(wù)。

4. [WHERE expression],與SQL的WHERE語句一樣的功能,expression支持的語法和函數(shù)下面再進(jìn)行描述。

5. [UNION oql_query], 與SQL的UNION的語句一樣的功能。其中oql_query只要符合OQL語法即可。但此處的OQL返回的對(duì)象應(yīng)該與主語句一致。

WHERE表達(dá)式語法,
WHERE表達(dá)式可以由幾個(gè)部分組成,即字符串、操作符、函數(shù),最終形成一個(gè)布爾結(jié)果值,實(shí)現(xiàn)數(shù)據(jù)篩選。這個(gè)跟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 “l(fā)ogical” 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 “l(fā)ogical” 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'

函數(shù)列表如下,

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可以作為兩個(gè)與當(dāng)前登錄用戶相關(guān)的通用變量,從而可以在表達(dá)式中進(jìn)行使用,使用格式如下,

: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')

看完上述內(nèi)容,你們對(duì)iTop中的OQL大概了解了嗎?如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI