截斷表:truncate table 表名 sql
時間操做oracle
一個月的第一天函數
SELECT to_date(to_char(SYSDATE,'yyyy-mm')||'-01','yyyy-mm-dd') FROM dualcode
一年的第一天table
SELECT to_date(to_char(SYSDATE,'yyyy')||'-01-01','yyyy-mm-dd' ) FROM dualast
季度的第一天date
SELECT to_date(to_char(SYSDATE,'yyyy-')||lpad(floor(to_number(to_char(SYSDATE,'mm'))/3)*3+1,2,'0')||'-01','yyyy-mm-dd') FROM dualselect
上個月的最後一天循環
SELECT trunc(last_day(add_months(SYSDATE,-1)))+1-1/24/60/60 FROM dualnext
本年的最後一天
SELECT trunc(last_day(to_date(to_char(SYSDATE,'yyyy')||'-12-01','yyyy-mm-dd')))+1-1/24/60/60 FROM dual
本月的最後一天
select trunc(last_day(sysdate))+1-1/24/60/60 from dual
本月的第一個星期一
SELECT next_day( to_date(to_char(SYSDATE,'yyyy-mm')||'-01','yyyy-mm-dd'),'星期一') FROM dual
去掉時分秒
SELECT trunc(sysdate) FROM dual
顯示星期幾
SELECT to_char(SYSDATE,'Day') FROM dual
取得某個月的天數
SELECT trunc(last_day(SYSDATE))-to_date(to_char(SYSDATE,'yyyy-mm')||'-01','yyyy-mm-dd')+1 FROM dual
判斷是否閏年
SELECT decode(to_char(last_day(to_date(to_char(SYSDATE,'yyyy')||'-02-01','yyyy-mm-dd')),'dd'),'28','平年','閏年') FROM dual
一個季度多少天
SELECT last_day(to_date(to_char(SYSDATE,'yyyy-')||lpad(floor(to_number(to_char(SYSDATE,'mm'))/3)*3+3,2,'0')||'-01','yyyy-mm-dd'))-to_date(to_char(SYSDATE,'yyyy-')||lpad(floor(to_number(to_char(SYSDATE,'mm'))/3)*3+1,2,'0')||'-01','yyyy-mm-dd')+1FROM dual
create table example
(
ID NUMBER(10) NOT NULL PRIMARY KEY,
USERNAME VARCHAR2(20),
PHONE VARCHAR2(20),
ADDRESS VARCHAR2(50)
);
--創建一個序列
CREATE SEQUENCE emp_sequence
INCREMENT BY 1 --每次加幾
START WITH 1 --從幾開始計數
NOMAXVALUE --不設置最大值
NOCYCLE --一直累加,不循環
NOCACHE --不建緩衝區
;
INSERT INTO example (USERNAME,PHONE,ADDRESS)VALUES('KXD','88888888','KXDSOFT')
INSERT INTO example VALUES(emp_sequence.nextval,'KXD','88888888','KXDSOFT')
insert into example (id ) values (emp_sequence.nextval)
oracle sql (2)函數 ..........................................15.ABS 返回指定值的絕對值 SQL> select abs(100),abs(-100) from dual; ABS(100) ABS(-100) --------- --------- 100 100 16.ACOS 給出反餘弦的值 SQL> select acos(-1) from dual; ACOS(-1) --------- 3.1415927 17.ASIN 給出反正弦的值 SQL> select asin(0.5) from dual; ASIN(0.5) --------- .52359878 18.ATAN 返回一個數字的反正切值 SQL> select atan(1) from dual; ATAN(1) --------- .78539816 19.CEIL 返回大於或等於給出數字的最小整數 SQL> select ceil(3.1415927) from dual; CEIL(3.1415927) --------------- 4 20.COS 返回一個給定數字的餘弦 SQL> select cos(-3.1415927) from dual; COS(-3.1415927)