<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 14.9\. 表達式 在`where`子句中允許使用的表達式包括 大多數你可以在SQL使用的表達式種類: * 數學運算符`+, -, *, /` * 二進制比較運算符`=, &gt;=, &lt;=, &lt;&gt;, !=, like` * 邏輯運算符`and, or, not` * `in`, `not in`, `between`, `is null`, `is not null`, `is empty`, `is not empty`, `member of` and `not member of` * "簡單的" case, `case ... when ... then ... else ... end`,和 "搜索" case, `case when ... then ... else ... end` * 字符串連接符`...||...` or `concat(...,...)` * `current_date()`, `current_time()`, `current_timestamp()` * `second(...)`, `minute(...)`, `hour(...)`, `day(...)`, `month(...)`, `year(...)`, * EJB-QL 3.0定義的任何函數或操作:`substring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length(), mod()` * `coalesce()` 和 `nullif()` * `str()` 把數字或者時間值轉換為可讀的字符串 * `cast(... as ...)`, 其第二個參數是某Hibernate類型的名字,以及`extract(... from ...)`,只要ANSI `cast()` 和 `extract()` 被底層數據庫支持 * HQL `index()` 函數,作用于join的有序集合的別名。 * HQL函數,把集合作為參數:`size(), minelement(), maxelement(), minindex(), maxindex()`,還有特別的`elements()` 和`indices`函數,可以與數量詞加以限定:`some, all, exists, any, in`。 * 任何數據庫支持的SQL標量函數,比如`sign()`, `trunc()`, `rtrim()`, `sin()` * JDBC風格的參數傳入 `?` * 命名參數`:name`, `:start_date`, `:x1` * SQL 直接常量 `'foo'`, `69`, `6.66E+2`, `'1970-01-01 10:00:01.0'` * Java `public static final` 類型的常量 `eg.Color.TABBY` 關鍵字`in`與`between`可按如下方法使用: ``` from DomesticCat cat where cat.name between 'A' and 'B' ``` ``` from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' ) ``` 而且否定的格式也可以如下書寫: ``` from DomesticCat cat where cat.name not between 'A' and 'B' ``` ``` from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' ) ``` 同樣, 子句`is null`與`is not null`可以被用來測試空值(null). 在Hibernate配置文件中聲明HQL“查詢替代(query substitutions)”之后, 布爾表達式(Booleans)可以在其他表達式中輕松的使用: ``` <property name="hibernate.query.substitutions">true 1, false 0</property> ``` 系統將該HQL轉換為SQL語句時,該設置表明將用字符 `1` 和 `0` 來 取代關鍵字`true` 和 `false`: ``` from Cat cat where cat.alive = true ``` 你可以用特殊屬性`size`, 或是特殊函數`size()`測試一個集合的大小。 ``` from Cat cat where cat.kittens.size > 0 ``` ``` from Cat cat where size(cat.kittens) > 0 ``` 對于索引了(有序)的集合,你可以使用`minindex` 與 `maxindex`函數來引用到最小與最大的索引序數。 同理,你可以使用`minelement` 與 `maxelement`函數來 引用到一個基本數據類型的集合中最小與最大的元素。 ``` from Calendar cal where maxelement(cal.holidays) > current_date ``` ``` from Order order where maxindex(order.items) > 100 ``` ``` from Order order where minelement(order.items) > 10000 ``` 在傳遞一個集合的索引集或者是元素集(`elements`與`indices` 函數) 或者傳遞一個子查詢的結果的時候,可以使用SQL函數`any, some, all, exists, in` ``` select mother from Cat as mother, Cat as kit where kit in elements(foo.kittens) ``` ``` select p from NameList list, Person p where p.name = some elements(list.names) ``` ``` from Cat cat where exists elements(cat.kittens) ``` ``` from Player p where 3 > all elements(p.scores) ``` ``` from Show show where 'fizard' in indices(show.acts) ``` 注意,在Hibernate3種,這些結構變量- `size`, `elements`, `indices`, `minindex`, `maxindex`, `minelement`, `maxelement` - 只能在where子句中使用。 一個被索引過的(有序的)集合的元素(arrays, lists, maps)可以在其他索引中被引用(只能在where子句中): ``` from Order order where order.items[0].id = 1234 ``` ``` select person from Person person, Calendar calendar where calendar.holidays['national day'] = person.birthDay and person.nationality.calendar = calendar ``` ``` select item from Item item, Order order where order.items[ order.deliveredItemIndices[0] ] = item and order.id = 11 ``` ``` select item from Item item, Order order where order.items[ maxindex(order.items) ] = item and order.id = 11 ``` 在`[]`中的表達式甚至可以是一個算數表達式。 ``` select item from Item item, Order order where order.items[ size(order.items) - 1 ] = item ``` 對于一個一對多的關聯(one-to-many association)或是值的集合中的元素, HQL也提供內建的`index()`函數, ``` select item, index(item) from Order order join order.items item where index(item) < 5 ``` 如果底層數據庫支持標量的SQL函數,它們也可以被使用 ``` from DomesticCat cat where upper(cat.name) like 'FRI%' ``` 如果你還不能對所有的這些深信不疑,想想下面的查詢。如果使用SQL,語句長度會增長多少,可讀性會下降多少: ``` select cust from Product prod, Store store inner join store.customers cust where prod.name = 'widget' and store.location.name in ( 'Melbourne', 'Sydney' ) and prod = all elements(cust.currentOrder.lineItems) ``` _提示:_ 會像如下的語句 ``` SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order FROM customers cust, stores store, locations loc, store_customers sc, product prod WHERE prod.name = 'widget' AND store.loc_id = loc.id AND loc.name IN ( 'Melbourne', 'Sydney' ) AND sc.store_id = store.id AND sc.cust_id = cust.id AND prod.id = ALL( SELECT item.prod_id FROM line_items item, orders o WHERE item.order_id = o.id AND cust.current_order = o.id ) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看