1.對日期的比較大小時 :
都使用了一個轉換,前面加了個date 如:
select months_between(date'2005-2-10',date'2007-3-10') from dual; =-25 差25個月 :前面必須加個date.不用函數時的比較也要加個date
select * from books where datetime<date'2001-01-15';
2.對日期的insert操作
若無法正常insert時,則考慮to_date('日期','格式')進行insert,如:
insert into books values(1,to_date(01-01-2001',dd-mm-yyyy'),1000);
3.在sql*plus工具下create table時 第一齣現錯誤 使用ed命令進行編輯時 不要加最後的分號; 否則會提示:
create table b
( id number);
ORA-00911: 無效字符:提示的地方在;處 說明ed編輯時不能加;
Oracle中的反轉:
declare
abc varchar2(10);
begin
--abc :=reverse('&gdg');這種方法不能在pl塊中賦值,要用select
select reverse('&gfg') into abc from dual;
dbms_output.put_line (abc);
end;
自定義的遊標 可以用做變量的類型 例:
declare
cursor c_emp is select empno,ename,sal from emp order by sal desc;
emp1 c_emp%rowtype;--emp1的類型就是遊標的行記錄,這樣可以減少聲明變量數
begin
open c_emp;
loop
fetch c_emp into emp1;
exit when c_emp%notfound;
dbms_output.put_line(emp1.empno||' '||emp1.ename||' '||emp1.sal);
end loop;
close c_emp;
end;
oracle 日期參數:
由於各個地區的日期格式不同,所以在定義數據庫的時間列時建議使用varchar2類型,然後再用to_date進行轉換.
錯誤提示:ORA-01840: 輸入值對於日期格式不夠長:
如輸入的是1982-01-01時就會出現 解決:應該輸入19820101