·ÖÏíOracle 9iÊý¾Ý¿âÖн¨Á¢×ÔÔö×ֶεÄ×îа취_OracleÊý¾Ý¿â_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

·ÖÏíOracle9iÖн¨Á¢×ÔÔö×ֶεÄ×îа취

×÷ÕߣººÚ¿Í·ÀÏßÍø°²Oracleά»¤»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²Oracleά»¤»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£ºOracleÊý¾Ý¿âOracleÊý¾Ý¿â
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£º¡¡¡¡ºÜ¶àÈ˶¼ÖªµÀÔÚOracleÖв¢Ã»ÓÐÏñÆäËûÊý¾Ý¿âÖеÄ×ÔÔö×ֶΣ¬ÄÇôÎÒÃÇÔõÑù²ÅÄÜʵÏÖOracleµÄ×ÔÔö×ֶι¦ÄÜÄØ£¿ÏÂÃæÎÒÃÇͨ¹ýOracleÖеÄSequenceºÍTriggerÀ´ÊµÏִ˹¦ÄÜ¡£¡¡¡¡1¡¢Ê×ÏȽ¨Á¢Ò»¸ö´´...

¡¡¡¡ºÜ¶àÈ˶¼ÖªµÀÔÚOracleÖв¢Ã»ÓÐÏñÆäËûÊý¾Ý¿âÖеÄ×ÔÔö×ֶΣ¬ÄÇôÎÒÃÇÔõÑù²ÅÄÜʵÏÖOracleµÄ×ÔÔö×ֶι¦ÄÜÄØ£¿ÏÂÃæÎÒÃÇͨ¹ýOracleÖеÄSequenceºÍTriggerÀ´ÊµÏִ˹¦ÄÜ¡£

¡¡¡¡1¡¢Ê×ÏȽ¨Á¢Ò»¸ö´´½¨×ÔÔö×ֶεĴ洢¹ý³Ì

//Written by Sun Zhenfang 20040903
create or replace procedure pr_CreateIdentityColumn
(tablename varchar2,columnname varchar2)
as
strsql varchar2(1000);
begin
       strsql := 'create sequence seq_'||tablename||'
 minvalue 1 maxvalue 999999999999999999
start with 1 increment by 1 nocache';
       execute immediate strsql;
       strsql := 'create or replace trigger trg_'||tablename||'
 before insert on '||tablename||' for each row begin
select seq_'||tablename||'.nextval into :new.'||columnname||'
 from dual; end;';
       execute immediate strsql;
end;

¡¡¡¡2¡¢OracleÖÐÖ´Ðж¯Ì¬SQLʱҪÏÔʾÊÚȨ£¨¼´Ê¹¸ÃÓû§ÓµÓиÃÏà¹ØȨÏÞ£©

GRANT CREATE ANY SEQUENCE TO "UserName";
GRANT CREATE ANY TRIGGER TO "UserName";

¡¡¡¡£¨×¢Ò⣺Êý¾Ý¿âÓû§ÃûÇø·Ö´óСд£©

¡¡¡¡3¡¢ÖØÐÂCompile´æ´¢¹ý³Ìpr_CreateIdentityColumn

¡¡¡¡4¡¢¸ã¶¨£¬ÏÂÃæÎÒÃǾͿÉÒÔÓÃÕâ¸ö´æ´¢¹ý³Ì½¨Á¢×ÔÔö×Ô¶ÎÁË¡£

¡¡¡¡5¡¢µ÷Óô洢¹ý³Ì½¨Á¢×ÔÔö×ֶΣ¨Note: µÚÒ»¸ö²ÎÊýÊDZíÃû£¬µÚ¶þ¸ö²ÎÊýΪ×ÔÔö×ֶεÄÃû×Ö£©

exec pr_createidentitycolumn('sdspdept','deptid');
exec pr_createidentitycolumn('sdspuser','userid');
exec pr_createidentitycolumn('sdspsysrole','sysroleid');
exec pr_createidentitycolumn('sdspfp','sysfpid');
exec pr_createidentitycolumn('sdspphasemodel','phasemodelid');
exec pr_createidentitycolumn('sdspphase','phaseid');
... ...

    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-11774-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-03-23 00:22:47  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer