teradata CAST
1)、數值型截位或四捨五入
SEL CAST(50500.75 AS INTEGER) AS "Truncated”
,CAST(50500.75 AS DECIMAL(6,0)) AS "Rounded";
Truncated Rounded
----------- ----------
50500 50501.
SEL CAST(6.74 AS DECIMAL(2,1)) AS "Drop Precision”
,CAST(6.75 AS DECIMAL(2,1)) AS "Round Up”
,CAST(6.85 AS DECIMAL(2,1)) AS "Round Down to Even";
Drop Precision Round Up Round Down to Even
----------------- ------------ ------------------------
6.7 6.8 6.8
2)、字元型截位
SEL 'Teradata'(char(4)) as "Truncate with CAST”
,'Teradata'(char(4),UPPERCASE) as "Truncate and UPPERCASE";
Truncate with CAST Truncate and UPPERCASE
---------------------- ------------------------------
Tera TERA
3)、數值型進行格式變換
Numeric formatting symbols:
$ Fixed or floating dollar sign
9 Decimal digit (no zero suppress)
Z Zero-suppressed decimal digit
, Comma – inserted where specified
. Decimal point position
- Dash character – inserted where specified
/ Slash character – inserted where specified
% Percent character – inserted where specified
SELECT 123 (FORMAT '99999999'), 123 (FORMAT '9(8)')
,000005 (FORMAT 'Z(5)9'), 1234.56 (FORMAT '$$$,$$9.99')
,5 (FORMAT 'Z9%'), 2225551212 (FORMAT '999/999-9999');
123 123 5 1234.56 5 2225551212.
-------- -------- ------ ---------- --- ------------
00000123 00000123 5 $1,234.56 5% 222/555-1212
將DECIMAL型轉成字元型:
不要用這種辦法:
TRIM(TRAILING '.' FROM TRIM(CAST(P1.Acct_Item_Type_Id AS CHAR(20)))
要採取這種辦法:
CAST(cast(P1.Acct_Item_Type_Id AS format ‘z(18)') as CHAR(20))
日期型進行格式變換
Date formatting symbols:
Y Year as YYYY/Y4 (2004) or YY (04)
M Month as MMMM/M4 (August), MMM/M3 (Aug) or MM (08)
D Day as DDD/D3 (day of the year) or DD (day of the month)
E Day of the week as EEEE/E4 (Monday) or EEE/E3 (Mon)
, Comma – inserted where specified
. Decimal point position
- Dash character – inserted where specified
/ Slash character – inserted where specified
B Blank position – inserted where specified
SELECT CAST(current_date AS FORMAT 'YYYYMMDD')
,CAST(current_date AS FORMAT 'MMMBDD,BYYYY')
,CAST(current_date AS FORMAT 'M4BDD,BY4')
,CAST(current_date AS FORMAT 'YYDDD');
Date Date Date Date
----------- ---------------- ------------------- -----
20040814 Aug 14, 2004 August 14, 2004 04227
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16723161/viewspace-1018477/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- C++之static_cast,dynamic_cast,const_castC++AST
- teradata limitsMIT
- 7.41 CASTAST
- C++強制型別轉換:static_cast、dynamic_cast、const_cast、reinterpret_castC++型別AST
- oracle cast 用法OracleAST
- dynamic_castAST
- Teradata SQL調優SQL
- Teradata基礎教程
- Teradata時間操作
- static_cast與dynamic_cast到底是什麼?AST
- reinterpret_cast 和 static_cast 的區別AST
- C++中static_cast, dynamic_cast, const_cast用法/使用情況及區別解析C++AST
- Teradata 時間函式函式
- Teradata資料壓縮
- Laravel 5 Eloquent cast arrayLaravelAST
- Oracle的Cast的用法OracleAST
- oracle function函式castOracleFunction函式AST
- 型別轉換(cast)型別AST
- 如何殺掉Teradata的sessionSession
- Teradata物件簡寫對照物件
- Teradata自定義函式Replace函式
- Teradata的資料保護
- C++中dynamic_cast與static_cast淺析與例項演示C++AST
- static_cast和dynamic_cast的區別,看完這篇你就懂了!AST
- SQL中的cast()函式SQLAST函式
- const_cast的用法AST
- Oracle CAST函式不生效OracleAST函式
- 關於Teradata PI的總結
- Teradata 之top n與sample n
- Teradata TPT處理Unicode方法Unicode
- Teradata新特性之reset when使用
- Teradata的資料保護策略
- Golang 型別轉換庫 castGolang型別AST
- cannot be cast to java.lang.ComparableASTJava
- substr,substrb,cast的使用、比較AST
- oracle 特殊SQL(TABLE( CAST( MULTISET()[zt]OracleSQLAST
- cast函式的用法案例AST函式
- (轉)Go 每日一庫之 castGoAST