久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Oracle中Decode()函數使用技巧

瀏覽:137日期:2023-11-15 14:19:25
decode()函數使用技巧·軟件環(huán)境: 1、Windows NT4.0+Oracle 8.0.42、ORACLE安裝路徑為:C:ORANT·含義解釋: decode(條件,值1,翻譯值1,值2,翻譯值2,...值n,翻譯值n,缺省值)該函數的含義如下: IF 條件=值1 THENRETURN(翻譯值1)ELSIF 條件=值2 THENRETURN(翻譯值2)......ELSIF 條件=值n THENRETURN(翻譯值n)ELSERETURN(缺省值)END IF· ; ; 使用方法: 1、比較大小select decode(sign(變量1-變量2),-1,變量1,變量2) from dual; --取較小值sign()函數根據某個值是0、正數還是負數,分別返回0、1、-1例如:變量1=10,變量2=20則sign(變量1-變量2)返回-1,decode解碼結果為“變量1”,達到了取較小值的目的。2、表、視圖結構轉化現有一個商品銷售表sale,表結構為:month  char(6)  --月份sellnumber(10,2) --月銷售金額現有數據為:2000011000200002110020000312002000041300200005140020000615002000071600200101110020020212002003011300想要轉化為以下結構的數據:year char(4)  --年份month1number(10,2) --1月銷售金額month2number(10,2) --2月銷售金額month3number(10,2) --3月銷售金額month4number(10,2) --4月銷售金額month5number(10,2) --5月銷售金額month6number(10,2) --6月銷售金額month7number(10,2) --7月銷售金額month8number(10,2) --8月銷售金額month9number(10,2) --9月銷售金額month10number(10,2) --10月銷售金額month11number(10,2) --11月銷售金額month12number(10,2) --12月銷售金額結構轉化的SQL語句為:create or replace viewv_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)asselect substrb(month,1,4),sum(decode(substrb(month,5,2),'01',sell,0)),sum(decode(substrb(month,5,2),'02',sell,0)),sum(decode(substrb(month,5,2),'03',sell,0)),sum(decode(substrb(month,5,2),'04',sell,0)),sum(decode(substrb(month,5,2),'05',sell,0)),sum(decode(substrb(month,5,2),'06',sell,0)),sum(decode(substrb(month,5,2),'07',sell,0)),sum(decode(substrb(month,5,2),'08',sell,0)),sum(decode(substrb(month,5,2),'09',sell,0)),sum(decode(substrb(month,5,2),'10',sell,0)),sum(decode(substrb(month,5,2),'11',sell,0)),sum(decode(substrb(month,5,2),'12',sell,0))from salegroup by substrb(month,1,4);
標簽: Oracle 數據庫
主站蜘蛛池模板: 邵阳市| 朝阳县| 和龙市| 呼和浩特市| 麟游县| 探索| 黎城县| 商水县| 天等县| 商洛市| 中卫市| 阿克陶县| 霍山县| 县级市| 滦南县| 淳化县| 杨浦区| 且末县| 西平县| 鄂托克旗| 大港区| 治多县| 宣威市| 清涧县| 闸北区| 安丘市| 周口市| 新民市| 伊宁县| 景谷| 修水县| 海门市| 什邡市| 安陆市| 堆龙德庆县| 嘉鱼县| 霸州市| 前郭尔| 罗城| 大厂| 什邡市|