天天看點

oracle 知識學習alter 與update的差別sum() 與count()差別to_char,to_date,to_number

alter 與update的差別

alter 更新的是表的結構(列):

添加一列:

alter   table   A   add( column1  varchar2(20) default 0 not null );
           

删除一列:

alter table A drop column <列名>  
           

update 更新的是表的資料:

update yao_1_qyqd2 a

set a.本月放号量 = 0

where a.本月放号量 is null

sum() 與count()差別

sum()函數 是用來計算某一列的資料和(列)

count()函數 是用來統計 表中 條數和(行)

to_char,to_date,to_number

to_char 将 數值型或者日期型 轉化為 字元型

例 select to_char(sysdate,‘yyyymmdd’) from dual;

to_date 把 string 轉換成 date

例 to_date(‘05 Dec 2000’, ‘DD Mon YYYY’)

to_number 把字元型數值轉換為 數字型

例 有張表a,建表格時為了友善将id編寫成了 varchar2型

資料如下:

id name

1 Y

2 N

3 M

… …

10 B

現在插入一條

11 S

因為更新的原因将順序排亂了,

你使用 select* from a order by id 就會亂序,因為1,10,11,按字元排序都會排在2,3…前面

而使用 select* from a order by to_number(id);就可以