Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Oracle ¼¸¸ö¹Ø¼ü×ÖÀí½â

/*
--DML´¥·¢Æ÷ÀàÐÍ:
·ÖΪÓï¾ä¼¶´¥·¢Æ÷ºÍÐм¶´¥·¢Æ÷.
Óï¾ä¼¶´¥·¢Æ÷²»ÐèÒª¼Ófor each row¹Ø¼ü×Ö,²¢ÇÒ²»ÄÜʹÓÃ:new ºÍ :old¹Ø¼ü×Ö.¶ÔÕû¸ösqlÓï¾äÖ»Ö´ÐÐÒ»´Î´¥·¢Æ÷.
Ðм¶´¥·¢Æ÷ÐèÒª¼Ófor each row¹Ø¼ü×Ö,¿ÉÒÔʹÓÃ:newºÍ:old¹Ø¼ü×Ö,¶ÔÕû¸ösqlÓï¾äÓ°Ïìµ½µÄÿһÐж¼Ö´ÐÐÒ»´Î´¥·¢Æ÷.
--:newºÍ:old¹Ø¼ü×Ö×ܽá
:newÖ¸µÄÊǵ±Ç°DMLÓï¾ä²Ù×÷Ö®ºóÓ°ÏìµÄijһÐмǼµÄÒýÓÃ.
:oldÖ¸µÄÊǵ±Ç°DMLÓï¾ä²Ù×÷֮ǰӰÏìµÄijһÐмǼµÄÒýÓÃ.(×¢Òâ,:old²»ÄÜËæ±ã¸³Öµ).
DML´¥·¢Æ÷ÖÐ,²»¹ÜÊÇbefore»¹ÊÇafter´¥·¢,:new¡¢:old¶¼»á¸ù¾Ý²Ù×÷µÄ²»Í¬¶ø´æÔÚÖµ.
insert: :newÖдæÔÚÒªinsertµÄÖµ.
update: :newÖдæÔÚÒªupdateµÄÖµ,:old´æÔÚupdate֮ǰµÄÖµ.
delete: :oldÖдæÔÚÒªdeleteµÄÖµ.
--:newºÍ:oldС¼¼ÇÉ
ÔÚbeforeµÄinsertºÍupdate²Ù×÷ÖÐÊÇ¿ÉÒÔͨ¹ý:newÌáÇ°¸üÐÂÒª²Ù×÷ÐеÄÊý¾Ý,ÈÃinsert ºÍupdate¸üеÄÊý¾ÝΪ´¥·¢Æ÷Êý,ÆäËûµÄÔò²»ÐÐ.
:oldÔÚ´¥·¢Æ÷ÖÐÊDz»Äܸ³ÖµµÄ. :old.test01 := '123'; --ÕâÑù»á±¨´í.
*/
--Ìí¼Ó»òɾ³ý»òÐÞ¸ÄÒÔÇ°´¥·¢
create or replace trigger test_biud
before insert or update or delete on test
for each row
begin
    if inserting then
        :new.test01 := '01';
        :new.test02 := '02';
        :new.test03 := '03';
    elsif updating then
        :new.test01 := '001';
        :new.test02 := '002';
        :new.test03 := '003';
    elsif deleting then
       dbms_output.put_line('asd');
    end if;
end;
drop trigger test_biud;
--Ìí¼Ó»òɾ³ý»òÐÞ¸ÄÒÔºó´¥·¢
create or replace trigger test_aiud
after insert or update or delete on test
for each row
begin
    if inserting then
        dbms_output.put_line('new:' ||  :new.test01 || '   old:' || :old.test01);
    elsif updating then
        dbms_output.put_line('new:'


Ïà¹ØÎĵµ£º

OracleÊý¾Ý¿âÌá¸ßÃüÖÐÂʼ°Ïà¹ØÓÅ»¯

1)Library CacheµÄÃüÖÐÂÊ:
.¼ÆË㹫ʽ:Library Cache Hit Ratio = sum(pinhits) / sum(pins)
SQL>SELECT SUM(pinhits)/sum(pins)    from V$LIBRARYCACHE; 
ͨ³£ÔÚ98%ÒÔÉÏ£¬·ñÔò£¬ÐèÒªÒª¿¼ÂǼӴó¹²Ïí³Ø£¬°ó¶¨±äÁ¿£¬ÐÞ¸Äcursor_sharingµÈ²ÎÊý¡£
2)¼ÆËã¹²Ïí³ØÄÚ´æʹÓÃÂÊ:
SQL>SELECT ......

±Ê¼Ç£ºOracle³£Ó÷ÖÎöº¯Êý

Oracle³£Ó÷ÖÎöº¯Êý
ROW_NUMBER
·µ»ØÓÐÐò×éÖÐÒ»ÐеÄÆ«ÒÆÁ¿£¬´Ó¶ø¿ÉÓÃÓÚ°´Ìض¨±ê×¼ÅÅÐòµÄÐкÅ
row_number() over(partition by ... order by ...)
RANK
¸ù¾ÝORDER BY×Ó¾äÖбí´ïʽµÄÖµ£¬´Ó²éѯ·µ»ØµÄÿһÐУ¬¼ÆËãËüÃÇÓëÆäËüÐеÄÏà¶ÔλÖá£×éÄÚµÄÊý¾Ý°´ORDER BY×Ó¾äÅÅÐò£¬È»ºó¸øÿһÐи³Ò»¸öºÅ£¬´Ó¶øÐγÉÒ»¸öÐòÁУ¬¸ÃÐòÁ ......

һЩoracleµÄÃüÁî¼°º¯Êý °üÀ¨decodeµÈ


 1¡¢set linesize 100;  ÉèÖó¤¶È   
 2¡¢set pagesize 30;   ÉèÖÃÿҳÏÔʾÊýÄ¿   
 3¡¢em a.sql  ´ò¿ª¼Çʱ¾     
 4¡¢@ a Ö´ÐÐÎļþaÖеĴúÂ룬¿ÉÖ¸¶¨ÎļþµÄ·¾¶ @d:a.txt ......

³õѧORACLE Á·Ï°Ìâ

ʹÓÃscott/tigerÓû§ÏµÄemp±íºÍdept±íÍê³ÉÏÂÁÐÁ·Ï°£¬±íµÄ½á¹¹ËµÃ÷ÈçÏÂ
¡¡¡¡empÔ±¹¤±í(empnoÔ±¹¤ºÅ/enameÔ±¹¤ÐÕÃû/job¹¤×÷/mgrÉϼ¶±àºÅ/hiredateÊܹÍÈÕÆÚ/salн½ð/commÓ¶½ð/deptno²¿ÃűàºÅ)
¡¡¡¡dept²¿Ãűí(deptno²¿ÃűàºÅ/dname²¿ÃÅÃû³Æ/locµØµã)
¡¡¡¡¹¤×Ê £½ н½ð £« Ó¶½ð
¡¡¡¡1£®ÁгöÖÁÉÙÓÐÒ»¸öÔ±¹¤µÄËùÓв¿ÃÅ
¡¡¡¡ ......

ORACLE ³£ÓÃ×Ö·ûº¯Êý


1.LOWER(str) Ç¿ÖÆСд
2.UPPER(str) Ç¿ÖÆ´óд
3.INITCAP(str) ÿ¸öµ¥´ÊÊ××Öĸ´óд
ʾÀý£º
SQL> select initcap('my_boy') from dual; --·µ»Ø"My_Boy"
×¢Ò⣺µ¥´ÊÖ®¼äÓÃÏ»®Ïߣ¨"_"£©·Ö¸î
4.CONCAT(str1,str2£©Á¬½Óº¯Êý,Á¬½Óstr1ºÍstr2×Ö·û´®
5.SUBSTR(string,a[,b])·µ»ØstringµÄÒ»²¿·Ö£¬aºÍbÒÔ×Ö·ûΪµ¥Î»¡£´Ó× ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ