±¾ÈËдµÄµÚÒ»¸öPL/SQL¹ý³Ì
¿´µ½±ðÈËÔÚÂÛ̳µÄÌáÎÊ£º
Ò»¸ö±íµÄЧÂÊÎÊÌâ
½ñÌìÅöµ½2Õűí
1ÕÅ ÓÐ×Ö¶Î
±íAÓÐ
jtbh(¼ÒÍ¥±àºÅ) hzxm(»§Ö÷ÐÕÃû) hnbh(»§ÄÚ×î´ó±àºÅ)
1000 ÕÅÈý 03
1001 ÕÔÁù..........................
±íBÓÐ
grbh£¨¸öÈ˱àºÅ=¼ÒÍ¥±àºÅ+2λ»§ÄÚ±àºÅ) xm(ÐÕÃû) gz(¹¤×Ê)
100001 ÕÅÈý 1000
100002 ÀîËÄ 1000
100003 ÍõÎå 1000
2ÕűíÊý¾Ý¼¸Ê®W¡£¡£¡£¡£ÏÖÔÚÓÉÓÚ֮ǰά»¤²»ºÃ£¬±íAµÄ×î´ó±àºÅûÓиüУ¬ÀýÈç±íB 1001Õâ»§ÈËÓÐ4¸ö±àºÅ£¬100101£¬100102 £¬100103£¬100105ÕâÑù£¬µ«ÊÇÎÒ±íA»§ÄÚ×î´ó±àºÅ¿ÉÄÜÖ»µ½ÁË04£¬¶øÊµ¼ÊÉÏÒªµ½05£¬ÇëÎʸ÷λ´óÏÀÈçºÎ¸üÐÂÓÐЧÂÊ£¬ÎÒ×Ô¼ºÐ´Á˸öЧÂÊÌ«µÍÁË¡£¡£¡£¡£¡£
ÓÚÊÇдÁËÏÂÃæµÄ¹ý³Ì£¬µÚÒ»´Îд£¬¼Ç¼һÏ¡£
CREATE PROCEDURE update_for_csdner();
CURSOR v_cursor IS SELECT MAX(substr(grbh, 4, 2)) hnbh, substr(grbh, 0, 4) jtbh from b GROUP BY substr(grbh, 0, 4);
v_jtbh VARCHAR2(4);
v_hnbh VARCHAR2(2);
BEGIN
OPEN v_cursor;
LOOP
FETCH v_cursor INTO v_hnbh, v_jtbh;
EXIT WHEN v_cursor%NOTFOUND;
UPDATE A SET hnbh = v_hnbh WHERE jtbh = v_jtbh;
COMMIT;
END LOOP;
CLOSE v_cursor;
END;
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......
-- create by zh
-- n ÊÇ×÷ÎïµÄʱ¼ä,x ÊÇÏ£ÍûÔÚ¼¸µã³ÉÊì,·µ»Ø²¥ÖÖµÄʱ¼ä
with t as
(
select 64 n,9 x from dual union all
select 64 n,13 x from dual union all
select 64 n,17 x from dual union all
select 64 n,20 x from dual
)
select '³ÉÊìʱ¼ä:' || lpad(to_char(n),4,' ' ......
ÔÚÎÒÃÇÈÕ³£Ê¹ÓÃSQL ServerÊý¾Ý¿âʱ£¬¾³£Óöµ½ÐèÒªÔÚʵÀýInstance01ÖпçʵÀý·ÃÎÊInstance02ÖеÄÊý¾Ý¡£ÀýÈçÔÚ×öÊý¾ÝÇ¨ÒÆÊ±£¬ÈçÏÂÓï¾ä:
insert into Instance01.DB01.dbo.Table01
select * from Instance02.DB01.dbo.Table01
ÆÕͨÇé¿öÏ£¬ÕâÑù×öÊDz»ÔÊÐíµÄ£¬ÒòΪSQ ......
½ñÌìÒ»¸öÅóÓÑÎʵ½Õâ¸öÎÊÌ⣬ÆäʵºÜºÃ½â¾ö£º
declare @dbname varchar(50)
declare c_database cursor for
select name from master.dbo.sysdatabas ......
±ÜÃâSQL×¢ÈëµÄ·½·¨ÓÐÁ½ÖÖ£ºÒ»ÊÇËùÓеÄSQLÓï¾ä¶¼´æ·ÅÔÚ´æ´¢¹ý³ÌÖУ¬ÕâÑù²»µ«¿ÉÒÔ±ÜÃâSQL×¢È룬»¹ÄÜÌá¸ßһЩÐÔÄÜ£¬²¢ÇÒ´æ´¢¹ý³Ì¿ÉÒÔÓÉרÃŵÄÊý¾Ý¿â¹ÜÀíÔ±(DBA)±àдºÍ¼¯ÖйÜÀí£¨ÕâÖÖ×ö·¨ÎÒÔÚһЩ¹«Ë¾¼û¹ý£©£¬²»¹ýÕâÖÖ×ö·¨ÓÐʱºòÕë¶ÔÏàͬµÄ¼¸¸ö±íÓв»Í¬Ìõ¼þµÄ²éѯ£¬SQLÓï¾ä¿ÉÄܲ»Í¬£¬ÕâÑù¾Í»á±àд´óÁ¿µÄ´æ´¢¹ý³Ì£¬ËùÒÔÓÐÈËÌá³ ......