oracle ʱ¼ä²î
//¼ÆËãºÁÃë²î(Á½¸ödateÀàÐ͵ÄÏà¼õΪÌìÊý²î±ð£¬È»ºóת»»ÎªºÁÃë)
select ceil(to_date('209-11-17 13:00:12','yyyy-mm-dd hh24:mi-ss')-to_date(2009-11-18 14:00:12','yyyy-mm-dd hh24:mi-ss') )from dual;
//¼ÆËãÏà²îÔ·Ý
select (EXTRACT(year from to_date('209-11-17','yyyy-mm-dd'))-EXTRACT(year from to_date('2009-11-18','yyyy-mm-dd') ))*12+(EXTRACT(month from to_date('209-11-17','yyyy-mm-dd'))-EXTRACT(month from to_date('2009-11-18','yyyy-mm-dd') )) from dual;
//ͨ¹ýʱ¼ä´ÁÔËËã
select to_timestamp('2009-11-17 19:20:12 234','yyyy-mm-dd hh24:mi:ss ff')-to_timestamp('2009-11-16 11:12:34 167','yyyy-mm-dd hh24:mi:ss ff') from dual;
·µ»ØֵΪ+000000010 00:02:24.00000000 ×Ö·û´®Òª×ª»»ÎªºÁÃëÊý×Ö£¬×Ô¶¨Ò庯ÊýʵÏÖ
//×Ô¶¨ÒåÓÃʱ¼ä´ÁÔËË㺯Êý
create or replace function TIME_INTERVAL(endTime varchar2,startTime varchar2)
return number
IS
p_1 varchar2(40);
begin
p_1 := to_timestamp(endTime,'yyyy-mm-dd hh24:mi:ss ff')-to_timestamp(startTime,'yyyy-mm-dd hh24:mi:ss ff');
return trunc(to_number(substr((p_1),1,instr(p_1,' '))))*24*60*60+to_number(substr((p_1),instr((p_1),' ')+1,2))*60*60+to_number(substr((p_1),instr((p_1),' ')+4,2))*60+to_number(substr((p_1),instr((p_1),' ')+7,2));
end;
Ïà¹ØÎĵµ£º
1. Ñ¡ÓÃÊʺϵÄOracleÓÅ»¯Æ÷
¡¡¡¡OracleµÄÓÅ»¯Æ÷¹²ÓÐ3ÖÖ£º
¡¡¡¡a. RULE (»ùÓÚ¹æÔò)
¡¡¡¡b. COST (»ùÓڳɱ¾)
¡¡¡¡c. CHOOSE (Ñ¡ÔñÐÔ)
¡¡¡¡ÉèÖÃȱʡµÄÓÅ»¯Æ÷£¬¿ÉÒÔͨ¹ý¶Ôinit.oraÎļþÖÐOPTIMIZER_MODE²ÎÊýµÄ¸÷ÖÖÉùÃ÷£¬ÈçRULE£¬COST£¬CHOOSE£¬ALL_ROWS£¬FIRST_ROWS . Ä㵱ȻҲÔÚSQL¾ä¼¶»òÊǻỰ(session)¼¶¶ÔÆä½øÐи²¸Ç¡£ ......
¡¡¡¡decode()º¯ÊýÊÇORACLE PL/SQLÊǹ¦ÄÜÇ¿´óµÄº¯ÊýÖ®Ò»£¬Ä¿Ç°»¹Ö»ÓÐORACLE¹«Ë¾µÄSQLÌṩÁ˴˺¯Êý£¬ÆäËûÊý¾Ý¿â³§É̵ÄSQLʵÏÖ»¹Ã»Óд˹¦ÄÜ¡£
DECODEº¯ÊýÊÇORACLE PL/SQLÊǹ¦ÄÜÇ¿´óµÄº¯ÊýÖ®Ò»£¬Ä¿Ç°»¹Ö»ÓÐORACLE¹«Ë¾µÄSQLÌṩÁ˴˺¯Êý£¬ÆäËûÊý¾Ý¿â³§É̵ÄSQLʵÏÖ»¹Ã»Óд˹¦ÄÜ¡£DECODEÓÐÊ²Ã´Ó ......
½éÉÜÒ»ÏÂÄÚÁª¡¢×óÁª¡¢ÓÒÁª
Ò».ÏÈ¿´Ò»Ð©×î¼òµ¥µÄÀý×Ó
Àý×Ó
Table A
aid adate
1 a1
2 a2
3 a3
TableB
bid bdate
1 b1
2 b2
4 b4
Á½¸ö±ía,bÏàÁ¬½Ó,Ҫȡ³öidÏàͬµÄ×Ö¶Î
select * from a inner join b on a.aid = b.bidÕâÊǽöÈ¡³öÆ¥ÅäµÄÊý¾Ý.
´ËʱµÄÈ¡³öµÄÊÇ:
1 a1 b1
2 a2 b2
ÄÇôleft join Ö¸:
select * ......
Ò»,INSERT
1.ΪÁ˲»´òÂÒÔÀ´µÄ±íµÄÊý¾Ý,ËùÒÔ±¸·ÝÔÀ´µÄÊý¾Ý.
create table emp2 as select * from emp
create table emp3 as select * from emp
create table dept2 as select * from dept
create table salgrade2 as select * from salgrade
2.²é¿´±íµÄÉè¼ÆÇé¿ö:desc dept2;±íʾ²é¿´±ídept2µÄÉè¼ÆÇé¿ö.
3.²åÈëÊý¾Ýµ ......
1. ASCII: ·µ»ØÓëÖ¸¶¨µÄ×Ö·û¶ÔÓ¦µÄÊ®½øÖÆÊý;
SQL> select ascii('A') A,ascii('a') a,ascii(0) zero,ascii('') space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48
2. CHR:¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQ ......