小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Decode 函數(shù)的用法

 執(zhí)著男孩 2006-09-09
Decode 函數(shù)的用法
作者:無(wú)從考證  來(lái)源:轉(zhuǎn)載  發(fā)布時(shí)間:2005-9-21 16:23:18  發(fā)布人:admin

8){NewaspContentLabel.style.fontSize=(--newasp_fontsize)+"pt";NewaspContentLabel.style.lineHeight=(--newasp_lineheight)+"pt";}‘>減小字體 增大字體

      在數(shù)據(jù)庫(kù)開(kāi)發(fā)的過(guò)程當(dāng)中,有很多時(shí)候需要將行轉(zhuǎn)換成列或者將列轉(zhuǎn)換成行來(lái)顯示數(shù)據(jù),而往往我們?cè)诮⒈斫Y(jié)構(gòu)時(shí)不能根據(jù)顯示的要求來(lái)保存數(shù)據(jù),于是乎只能在保存數(shù)據(jù)之后做一些必要的操作(比方說(shuō):建立視圖等)來(lái)達(dá)到顯示的目的。   
       下面用一個(gè)常見(jiàn)的數(shù)據(jù)顯示來(lái)說(shuō)明decode函數(shù)的用法。就是成績(jī)單的顯示,這個(gè)是教學(xué)管理系統(tǒng)中最常見(jiàn)的。我想做開(kāi)發(fā)的人員都遇到過(guò)這個(gè),而且在大學(xué)期間也是常常接觸成績(jī)單,顯示的是:姓名、語(yǔ)文、數(shù)學(xué)等  
        實(shí)現(xiàn)腳本如下(cjd.sql):  
--建表  
create table stud  
(  
 sid  varchar2(10),  
 kcbm  varchar2(10),  
 cj  int  
);  
--插入測(cè)試數(shù)據(jù)  
insert into stud values(’1’,’語(yǔ)文’,80);  
insert into stud values(’2’,’數(shù)學(xué)’,90);  
insert into stud values(’3’,’英語(yǔ)’,100);  
commit;  
--創(chuàng)建視圖,decode用法  
create or replace view cjd as  
 select sid,  
 decode(kcbm,’語(yǔ)文’,cj,0) 語(yǔ)文,  
 decode(kcbm,’數(shù)學(xué)’,cj,0) 數(shù)學(xué),  
 decode(kcbm,’英語(yǔ)’,cj,0) 英語(yǔ)  
 from stud  
 order by sid;  
--顯示數(shù)據(jù)  
select * from cjd;  
執(zhí)行過(guò)程如下:  
SQL> create table stud(sid varchar2(10),  
  2  kcbm varchar2(10),  
  3  cj int);  
表已創(chuàng)建。  
SQL> insert into stud values(’1’,’語(yǔ)文’,80);  
已創(chuàng)建 1 行。  
SQL> insert into stud values(’2’,’數(shù)學(xué)’,90);  
已創(chuàng)建 1 行。  
SQL> insert into stud values(’3’,’英語(yǔ)’,100);  
已創(chuàng)建 1 行。  
SQL> commit;  
提交完成。  
SQL> create or replace view cjd as  
  2  select sid,  
  3  decode(kcbm,’語(yǔ)文’,cj,0) 語(yǔ)文,  
  4  decode(kcbm,’數(shù)學(xué)’,cj,0) 數(shù)學(xué),  
  5  decode(kcbm,’英語(yǔ)’,cj,0) 英語(yǔ)  
  6  from stud  
  7  order by sid;  
視圖已建立。  

SQL> select * from cjd;   

SID           語(yǔ)文       數(shù)學(xué)       英語(yǔ)                                    
---------- ---------- ---------- ----------                                    
1            80          0           0                                    
2            0           90          0                                    
3            0           0           100        

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多