您好,登錄后才能下訂單哦!
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子句功能一致。
操作符表如下,
Operator | Description |
---|---|
AND | Logical AND |
OR | Logical 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 |
LIKE | Simple pattern matching |
NOT LIKE | Negation of simple pattern matching |
IN | List operator |
NOT IN | Negation 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 |
REGEXP | Regular expression |
MATCHES | New 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 name | Description | Examples |
---|---|---|
COALESCE | Return the first non-NULL argument | COALESCE(field1, field2, 'Undefined') |
CONCAT | Return concatenated string | CONCAT(firstname, ' ', lastname) |
CURRENT_DATE | Return the current date | CURRENT_DATE() |
DATE | Extract the date part of a date or datetime expression | DATE() |
DATE_ADD | Add time values (intervals) to a date value. See allowed interval units below | DATE_ADD(NOW(), INTERVAL 1 HOUR) |
DATE_FORMAT | Format date as specified | DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y') |
DATE_SUB | Substract time values (intervals) from a date value. See allowed interval units below | DATE_SUB(NOW(), INTERVAL 5 MINUTE) |
DAY | Return the day of the month (0-31) | DAY(DATE()) |
ELT | Return string at index number | ELT(index, 'string1', 'string2', 'string3') |
FLOOR | Return the largest integer value not greater than the argument | FLOOR(12.356) |
FROM_DAYS | Convert a day number to a date | FROM_DAYS(12345) |
IF | If/else construct | IF(a=b, 'equals', 'differs') |
INET_ATON | Return the numeric value of an IP address | INET_ATON('15.15.121.12') |
INET_NTOA | Return the IP address from a numeric value | INET_NTOA(1231654) |
ISNULL | ISNULL(field1) | |
MONTH | Return the month from the date passed | MONTH(DATE()) |
NOW | Return the current date and time | NOW() |
ROUND | Round the argument | ROUND(12.356, 2) |
SUBSTR | Return the substring as specified | SUBSTR('abcdef', 2, 3) |
TIME | Extract the time portion of the expression passed | TIME() |
TO_DAYS | Return the date argument converted to days | TO_DAYS('2009-05-01') |
TRIM | Remove leading and trailing spaces | TRIM(' blah ') |
YEAR | Return the year from the date passed | YEAR(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大概了解了嗎?如果想了解更多相關文章內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。