¹Û²ì½üÀ´µÄһЩ°²È«Ê¼þ¼°Æäºó¹û£¬°²È«×¨¼ÒÃÇÒѾµÃµ½Ò»¸ö½áÂÛ£¬ÕâЩÍþвÖ÷ÒªÊÇͨ¹ýSQL×¢ÈëÔì³ÉµÄ¡£ËäȻǰÃæÓÐÐí¶àÎÄÕÂÌÖÂÛÁËSQL×¢È룬µ«½ñÌìËùÌÖÂÛµÄÄÚÈÝÒ²Ðí¿É°ïÖúÄã¼ì²é×Ô¼ºµÄ·þÎñÆ÷£¬²¢²ÉÈ¡ÏàÓ¦·À·¶´ëÊ©¡£
SQL×¢Èë¹¥»÷µÄÖÖÀà
Öª±ËÖª¼º£¬·½¿Éȡʤ¡£Ê×ÏÈÒªÇå³þSQL×¢Èë¹¥»÷ÓÐÄÄЩÖÖÀà¡£
1.ûÓÐÕýÈ·¹ýÂËתÒå×Ö·û
ÔÚÓû§µÄÊäÈëûÓÐΪתÒå×Ö·û¹ýÂËʱ£¬¾Í»á·¢ÉúÕâÖÖÐÎʽµÄ×¢Èëʽ¹¥»÷£¬Ëü»á±»´«µÝ¸øÒ»¸öSQLÓï¾ä¡£ÕâÑù¾Í»áµ¼ÖÂÓ¦ÓóÌÐòµÄÖÕ¶ËÓû§¶ÔÊý¾Ý¿âÉϵÄÓï¾äʵʩ²Ù×Ý¡£±È·½Ëµ£¬ÏÂÃæµÄÕâÐдúÂë¾Í»áÑÝʾÕâÖÖ©¶´£º
statement := "SELECT * from users WHERE name = '" + userName + "'; "
ÕâÖÖ´úÂëµÄÉè¼ÆÄ¿µÄÊǽ«Ò»¸öÌض¨µÄÓû§´ÓÆäÓû§±íÖÐÈ¡³ö£¬µ«ÊÇ£¬Èç¹ûÓû§Ãû±»Ò»¸ö¶ñÒâµÄÓû§ÓÃÒ»ÖÖÌض¨µÄ·½Ê½Î±Ô죬Õâ¸öÓï¾äËùÖ´ÐеIJÙ×÷¿ÉÄܾͲ»½ö½öÊÇ´úÂëµÄ×÷ÕßËùÆÚÍûµÄÄÇÑùÁË¡£ÀýÈ磬½«Óû§Ãû±äÁ¿(¼´username)ÉèÖÃΪ£º
a' or 't'='t£¬´ËʱÔʼÓï¾ä·¢ÉúÁ˱仯£º
SELECT * from users WHERE name = 'a' OR 't'='t';
Èç¹ûÕâÖÖ´úÂë±»ÓÃÓÚÒ»¸öÈÏÖ¤¹ý³Ì£¬ÄÇôÕâ¸öÀý×Ó¾ÍÄܹ»Ç¿ÆÈÑ¡ÔñÒ»¸öºÏ·¨µÄÓû§Ãû£¬ÒòΪ¸³Öµ't'='tÓÀÔ¶ÊÇÕýÈ·µÄ¡£
ÔÚһР......
create proc [dbo].[GenerateDataDictionary] as
begin
--»ñÈ¡Êý¾Ý±íÃû
declare @tableid int
declare mycursor Cursor
for select object_id from sys.objects where type='U' and name<>'dtproperties'
--»ñÈ¡×Ö¶ÎÃû³Æ¡¢±êʶ¡¢×Ö¶ÎÐòºÅ¡¢Õ¼ÓÃ×Ö½ÚÊý¡¢Ð¡ÊýλÊý¡¢ÔÊÐí¿ÕµÈ
open mycursor
fetch next from mycursor into @tableid
while(@@fetch_status=0)
begin
print '±íÃû£º'+object_name(@tableid)
select
col.colorder ×Ö¶ÎÐòºÅ,
col.name ×Ö¶ÎÃû,
t.name ÀàÐÍ,
col.length Õ¼ÓÃ×Ö½ÚÊý,
COLUMNPROPERTY(col.id,col.name,'PRECISION') as ³¤¶È,
isnull(COLUMNPROPERTY(col.id,col.name,'Scale'),0) as СÊýλÊý,
(case when
(S ......
ÓÃÏÂÃæµÄÊÓͼ£º
SQL> desc user_col_comments;
Name Null? Type
------------------------------- -------- ----
TABLE_NAME NOT NULL VARCHAR2(30)
COLUMN_NAME NOT NULL VARCHAR2(30)
COMMENTS VARCHAR2(4000)
²éѯ±í×Ö¶ÎÁеı¸×¢ÐÅÏ¢¡£
±ÈÈçÔÚ´´½¨±íTEST µÄʱºò£¬ÎªNAMEÁÐдÁ˱¸×¢“ÐÕÃû£º”ÏÖÔÚ¿ÉÒÔÖ±½Ó°ÑNAMEÁеı¸×¢¶Á³öÀ´Ð´µ½³ÌÐòµÄ¿Ø¼þÖУ¬»ñÈ¡·½·¨ÈçÏ£º
select comments
from user_col_comments
where table_name = 'TEST'
and column_name = 'NA ......
Èç¹ûÔÚSQL Server
ÀïÐèÒª¶¨Ê±»òÕßÿ¸ôÒ»¶Îʱ¼äÖ´ÐÐij¸ö´æ´¢¹ý³Ì»ò3200×Ö·ûÒÔÄÚµÄSQLÓï¾äʱ,¿ÉÒÔÓùÜÀí->SQL Server´úÀí->×÷ÒµÀ´ÊµÏÖ¡£
¡¡¡¡1¡¢¹ÜÀí->SQL Server´úÀí->×÷Òµ(°´Êó±êÓÒ¼ü)->н¨×÷Òµ->
¡¡¡¡2¡¢Ð½¨×÷ÒµÊôÐÔ(³£¹æ)->Ãû³Æ[×Ô¶¨Òå±¾´Î×÷ÒµµÄÃû³Æ]->Æô
Óõķ½¿òÄÚÊǹ´ºÅ->·ÖÀà´¦¿ÉÑ¡ÔñÒ²¿ÉÓÃĬÈϵÄ[δ·ÖÀà
(±¾µØ)]->ËùÓÐÕßĬÈÏΪµÇ¼SQL ServerÓû§[Ò²¿ÉÑ¡ÆäËüµÄµÇ¼]->ÃèÊö[Ìîд±¾´Î¹¤×÷ÏêϸÃèÊöÄÚÈÝ];
¡¡¡¡[ ´´½¨×÷Òµ·ÖÀàµÄ²½Öè:SQL Server´úÀí->×÷Òµ->ÓÒ¼üÑ¡ËùÓÐÈÎÎñ->Ìí¼Ó¡¢Ð޸ġ¢É¾³ý ]
¡¡¡¡3¡¢Ð½¨×÷ÒµÊôÐÔ(²½Öè)->н¨->²½ÖèÃû[×Ô¶¨ÒåµÚÒ»²½ÖèÃû³Æ]->ÀàÐÍ[Transact-SQL
(TSQL)½Å±¾]->Êý¾Ý¿â[Òª²Ù×÷µÄÊý¾Ý¿â]->ÃüÁî[ Èç¹ûÊǼòµ¥µÄSQLÖ±½Óд½øÈ¥¼´¿É£¬Ò²¿ÉÓôò¿ª°´Å¥ÊäÈëÒ»¸öÒÑдºÃµÄ*.sqlÎļþ
¡¡¡¡Èç¹ûÒªÖ´Ðд洢¹ý³Ì£¬Ìîexec p_procedure_name v_parameter1,[ v_parameter2…v_parameterN]]->È·¶¨(Èç¹ûÓжà¸ö²½Ö裬¿ÉÒÔÔٴε÷ÓÃÏÂÃæµÄн¨°´Å¥;Ò²¿ÉÒÔ¶ÔÒÑÓеĶà¸ö²½Öè²åÈë¡¢±à¼¡¢É¾³ý);
¡¡¡¡4¡¢½¨×÷ÒµÊôÐÔ(µ÷¶È)->н¨µ÷¶È->Ãû³Æ[×Ô¶¨Òåµ÷¶ÈÃû³Æ]->ÆôÓõķ½¿òÄÚÊǹ´º ......
×÷Õß: ÈýÊ®¶øÁ¢Ê±¼ä£º2009Äê10ÔÂ15ÈÕ 21:59:51±¾Îijö×Ô ¡°inthirties£¨ÈýÊ®¶øÁ¢£©¡±²©¿Í£¬×ªÔØÇëÎñ±Ø×¢Ã÷×÷Õߺͱ£Áô³ö´¦http://blog.csdn.net/inthirties/archive/2009/10/15/4673268.aspx °Ñ´ÎÐò²»¶ÔµÄÁÐÕÒ³öÀ´ ÇëÎÊ ÏÂÃæµÄ±í¸ÃÈçºÎÅÅÐò£¿ÎÒÓÐÏÂÃæµÄ±í¡£´ÎÐòÈçÏ ÆäÖеÚ5¸ö¼Ç¼ºÍµÚ6Ìõ¼Ç¼´ÎÐòµßµ¹ÁË¡£Õâ¸ö±íÊý¾ÝÁ¿±È½Ï´ó¡£ ÓÃʲô·½·¨¿ÉÒÔ¶ÔÕâ¸ö±íÖÐµÄ bÁÐÅÅÐò¡£Ê¹ÆäÄܹ»°´ÕÕÉýÐòÅÅÁС£
a b
1 #1¸ËËþ
2 #2¸ËËþ
3 #3.1¸ËËþ
4 #3.2¸ËËþ
5 #5¸ËËþ
6 #4¸ËËþ
7 #6¸ËËþ
8 #7¸ËËþ
9 #9¸ËËþ
10 #8¸ËËþ
ÏÖÔÚÒª×öµÄÊÂÇé¾ÍÊÇ°Ñ ´ÎÐò²»¶ÔµÄÁÐÕÒ³öÀ´¡£ ²»ÊÇÅÅÐò¡£±ÈÈçÉÏÁÐÖÐbÁеÚ5£¬µÚ6ÁС£µÚ9£¬10´ÎÐò²»¶Ô¡£ ÏÖÔÚÒª°ÑÆäÖеÄÁÐÕÒ³öÀ´¡£
5 #5¸ËËþ
6 #4¸ËËþ
9 #9¸ËËþ
10 #8¸ËËþ
¾ÍÊÇ°ÑÕâÑùµÄÁÐÄܹ»ÕÒ³öÀ´¡£ SQL> with temp as(
2 select 1 a, '#1¸ËËþ' b from dual union all
3 select 2 a, '#2¸ËËþ' b from dual union all
4 select 3 a, '#3.1¸ËËþ' b from dual union all
5 select 4 a, '#3.2¸ËË ......
×÷Õß: ÈýÊ®¶øÁ¢Ê±¼ä£º2009Äê10ÔÂ15ÈÕ 19:21:13±¾Îijö×Ô ¡°inthirties£¨ÈýÊ®¶øÁ¢£©¡±²©¿Í£¬×ªÔØÇëÎñ±Ø×¢Ã÷×÷Õߺͱ£Áô³ö´¦http://blog.csdn.net/inthirties/archive/2009/10/15/4673331.aspx ѧϰÊÇ¿ÝÔïµÄ£¬ËùÒÔ×÷Ϊһ¸öѧϰÕߣ¬ÒªÑ§»áÔÚѧϰÖÐÕÒµ½¿ìÀÖ£¬ÕâÑù²ÅÄܼ¤·¢ÐËȤ£¬ÐËȤÊÇ×îºÃµÄÀÏʦ£¬ÕâÑù£¬Ñ§Ï°¾ÍÂýÂýµÄ±ä³ÉÁËÒ»¼þ¿ìÀÖµÄÊÂÇéß·¡£Ô±¾Ò»Ö±×öOracleµÄ¹ÜÀíºÍά»¤£¬¶ÔPLSQL²»ÊǺܸÐÐËȤ£¬ÔÚCSDNÀï¾³£ÓÐЩÅóÓÑÎʵ½¿ª·¢µÄÎÊÌ⣬¿ªÊ¼ÊÇͨ¹ýgoogleÕÒµ½´ð°¸£¬ºóÀ´ÔÚÕÒÑ°µÄ¹ý³ÌÖУ¬Ñ§Ï°µ½ÁË֪ʶµã£¬Ò²¾ÍÂýÂýµÄ¿ªÊ¼°ïÖú±ðÈ˽øÐÐsqlµÄ¿ª·¢°ïÖú£¬ÕâÖÖ°ïÖúÒ²¸øÎÒÁËѧϰµÄ¶¯Á¦£¬ËùÒÔPLSQLµÄ¿ª·¢µÄ»ù±¾¶«Î÷Ò²¾ÍÕÆÎÕÁ˲»ÉÙÁË£¬¶øÇÒÓÉÓÚÊÇ¿ìÀÖµÄѧϰ£¬ËùÒÔÒ²±È½ÏÇáËÉ£¬ÕâÀï¾ÍÊÇÓøöÒ»¸öÍøÓѵÄÎÊÌâµÄÍêÕû½âÌâ¹ý³ÌÀ´¿´¿´ÎÒµ±Ê±¶ÔOverµÄѧϰ¡£ ÕâÊÇÒ»¸ö±È½ÏÓÐȤµÄSQLÌ⣬
ÓÐÒ»¸ö±í£¬½á¹¹ÈçÏ£º
±àºÅ£¬ÐÕÃû£¬Ê±¼ä£¬»ù±¾¹¤×Ê£¬½±½ð£¬¿Û¿î
1 ÕÅÈý 8-20 1000 1000 5
2 ÀîËÄ 8-20 1100 900 10
3 ÕÅÈý 9-20 900 1000 10
4 ÀîËÄ 9-20 1100 900 13
5 ÍõÎå 9-20 900 100 0 Èç¹ûÎÒ¶Ô8-20 ºÍ 9-20 µÄ»ù±¾¹¤×Ê×öÒ춯Êý¾Ý²éѯ ÎÒÒ ......