2012-11-22 11:24:06噗噗

Oracle/PLSQL: Trunc

 

 

 

有時候我們會需要清除一個表格中的所有資料。要達到者個目的,一種方式是我們在 上一頁看到DROP TABLE 指令。不過這樣整個表格就消失,而無法再被用了。另一種方式就是運用 TRUNCATE TABLE 的指令。在這個指令之下,表格中的資料會完全消失,可是表格本身會繼續存在。 TRUNCATE TABLE 的語法為下:

TRUNCATE TABLE "表格名"

所以,我們如果要清除在 SQL Create Table 那一頁建立的顧客表格之內的資料,我們就鍵入:

TRUNCATE TABLE customer.

For Example

trunc(to_date('22-AUG-03'), 'YEAR')would return '01-JAN-03'
trunc(to_date('22-AUG-03'), 'Q')would return '01-JUL-03'
trunc(to_date('22-AUG-03'), 'MONTH')would return '01-AUG-03'
trunc(to_date('22-AUG-03'), 'DDD')would return '22-AUG-03'
trunc(to_date('22-AUG-03'), 'DAY')would return '17-AUG-03'