oracle開發常用到的函式
Purpose
DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
The arguments can be any of the numeric types (NUMBER, BINARY_FLOAT, or BINARY_DOUBLE) or character types.
-
If expr and search are character data, then Oracle compares them using nonpadded comparison semantics. expr, search, and result can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. The string returned is ofVARCHAR2 datatype and is in the same character set as the first result parameter.
-
If the first search-result pair are numeric, then Oracle compares all search-result expressions and the first expr to determine the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype.
The search, result, and default values can be derived from expressions. Oracle Database uses short-circuit evaluation. That is, the database evaluates each search value only before comparing it to expr, rather than evaluating allsearch values before comparing any of them with expr. Consequently, Oracle never evaluates a search if a previous search is equal to expr.
Oracle automatically converts expr and each search value to the datatype of the first search value before comparing. Oracle automatically converts the return value to the same datatype as the first result. If the first result has the datatype CHAR or if the first result is null, then Oracle converts the return value to the datatype VARCHAR2.
In a DECODE function, Oracle considers two nulls to be equivalent. If expr is null, then Oracle returns the result of the first search that is also null.
The maximum number of components in the DECODE function, including expr, searches, results, and default, is 255.
Examples
This example decodes the value warehouse_id. If warehouse_id is 1, then the function returns 'Southlake'; if warehouse_id is 2, then it returns 'San Francisco'; and so forth. If warehouse_id is not 1, 2, 3, or 4, then the function returns 'Non domestic'.
SELECT product_id, DECODE (warehouse_id, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic') "Location of inventory" FROM inventories WHERE product_id < 1775;
2.oracle本月、上月、去年同月第一天,最後一天
select trunc(sysdate, 'month') 本月第一天,trunc(last_day(sysdate)) 本月最後一天,trunc(add_months(sysdate, -1), 'month') 上月第一天,trunc(last_day(add_months(sysdate, -1))) 上月最後一天,trunc(add_months(sysdate, -12), 'month') 去年本月第一天,trunc(last_day(add_months(sysdate, -12))) 去年本月最後一天from dual
3.行專列函式wm_concat
SELECT
UUGR_UURR.USERID,to_char(wm_concat(ROLENAME))
FROM
(SELECT UUGR.USERID,UURR.ROLEID FROM UC_USERINFO_GROUP_REF UUGR,UC_GROUP_ROLE_REF UURR WHERE UUGR.GROUPID=UURR.GROUPID) UUGR_UURR,UC_ROLE UR
WHERE UUGR_UURR.ROLEID=UR.ID GROUP BY UUGR_UURR.USERID
在用到wm_concat之後如果是字串型別則要進行一次to_char轉換,否則會返回
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29802484/viewspace-1259443/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 27個Asp.Net經常會用到的函式集ASP.NET函式
- oracle經常使用到的hintOracle
- Oracle常見數字函式Oracle函式
- PHP經常用到的函式大全PHP函式
- SQL查詢中用到的函式SQL函式
- matlab中用到的randperm函式Matlab函式
- 開發中經常使用到的Xcode快捷鍵XCode
- Oracle開發專題之:分析函式的使用Oracle函式
- oracle的分析函式over 及開窗函式Oracle函式
- 在專案開發中經常用到的全域性函式、正則(持續更新)函式
- oracle的分析函式over(Partition by...) 及開窗函式Oracle函式
- matlab 濾波器中用到的函式Matlab函式
- python strip()函式 爬蟲用到Python函式爬蟲
- pandas 將函式應用到列(qbit)函式
- Presto 函式開發REST函式
- Oracle分析函式之開窗函式over()詳解Oracle函式
- 開發常用的輔助函式函式
- python開發的range()函式Python函式
- 常見函式之單行函式函式
- 開發hive UDF函式Hive函式
- iOS開發常用函式iOS函式
- 【函式】ORACLE函式大全函式Oracle
- ABAP/4程式設計中用到的系統函式程式設計函式
- ORACLE ERP維護與開發中常用到的變數Oracle變數
- 【開發篇sql】 分析函式(一) 評級相關的函式SQL函式
- flutter開發之——Dart中的函式FlutterDart函式
- C++ 常物件和常函式C++物件函式
- 【函式】oracle視窗函式over()的理解函式Oracle
- Oracle的dump函式Oracle函式
- Oracle的日期函式Oracle函式
- Oracle常用的函式Oracle函式
- Oracle聚合函式/分析函式Oracle函式
- Oracle 中異常處理函式 - SQLCODE和SQLERRMOracle函式SQL
- PHP經常使用的字串函式PHP字串函式
- php常見的危險函式PHP函式
- 【開發篇sql】 分析函式(二) 行篩選相關的函式SQL函式
- 【函式】Oracle EXTRACT()函式與to_char() 函式函式Oracle
- oracle 函式Oracle函式