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

PL/SQLʵÀý·ÖÎö

PL/SQLʵÀý·ÖÎö
µÚÎåÕÂ
1¡¢PL/SQLʵÀý·ÖÎö
1£©ÔÚ¡¾SQLPlus Worksheet¡¿ÖÐÖ±½ÓÖ´ÐÐÈçÏÂSQL´úÂëÍê³ÉÉÏÊö²Ù×÷¡£(´´½¨±í)
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D

CREATE TABLE "SCOTT"."TESTTABLE" ("RECORDNUMBER" NUMBER(4) NOT NULL, "CURRENTDATE" DATE NOT NULL)
TABLESPACE "SYSTEM"
2£©ÒÔadminÓû§Éí·ÝµÇ¼¡¾SQLPlus Worksheet¡¿£¬Ö´ÐÐÏÂÁÐSQL´úÂëÍê³ÉÏòÊý¾Ý±íSYSTEM.testableÖÐÊäÈë100¸ö¼Ç¼µÄ¹¦ÄÜ¡£
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D
set serveroutput on
declare
maxrecords constant int:=100;
i int:=1;
begin
for i in 1..maxrecords loop
insert into SCOTT.testtable(recordnumber,currentdate)
values(i,sysdate);
end loop;
dbms_output.put_line('³É¹¦Â¼ÈëÊý¾Ý£¡');
commit;
end;
2¡¢ÔÚ¡¾SQLPlus Worksheet¡¿ÖÐÖ´ÐÐÏÂÁÐPL/SQL³ÌÐò£¬¸Ã³ÌÐò¶¨ÒåÁËÃûΪageµÄÊý×ÖÐͱäÁ¿£¬³¤¶ÈΪ3£¬³õʼֵΪ26¡£
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D
declare
age number(3):=26;
begin
commit;
end;
3¡¢ÔÚ¡¾SQLPlus Worksheet¡¿ÖÐÖ´ÐÐÏÂÁÐPL/SQL³ÌÐò£¬¸Ã³ÌÐò¶¨ÒåÁËÃûΪpiµÄÊý×ÖÐͳ£Á¿£¬³¤¶ÈΪ9¡£
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D
declare
pi constant number(9):=3.1415926;
begin
commit;
end;
4¡¢¸´ºÏÊý¾ÝÀàÐͱäÁ¿
ÏÂÃæ½éÉܳ£¼ûµÄ¼¸ÖÖ¸´ºÏÊý¾ÝÀàÐͱäÁ¿µÄ¶¨Òå¡£
1). ʹÓÃ%type¶¨Òå±äÁ¿
ΪÁËÈÃPL/SQLÖбäÁ¿µÄÀàÐͺÍÊý¾Ý±íÖеÄ×ֶεÄÊý¾ÝÀàÐÍÒ»Ö£¬Oracle 9iÌṩÁË%type¶¨Òå·½·¨¡£ÕâÑùµ±Êý¾Ý±íµÄ×Ö¶ÎÀàÐÍÐ޸ĺó£¬PL/SQL³ÌÐòÖÐÏàÓ¦±äÁ¿µÄÀàÐÍÒ²×Ô¶¯Ð޸ġ£
ÔÚ¡¾SQLPlus Worksheet¡¿ÖÐÖ´ÐÐÏÂÁÐPL/SQL³ÌÐò£¬¸Ã³ÌÐò¶¨ÒåÁËÃûΪmydateµÄ±äÁ¿£¬ÆäÀàÐͺÍtempuser.testtableÊý¾Ý±íÖеÄcurrentdate×Ö¶ÎÀàÐÍÊÇÒ»Öµġ£
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D
Declare
mydate SYSTEM.testtable.currentdate%type;
begin
commit;
end;
2). ¶¨Òå¼Ç¼ÀàÐͱäÁ¿
ºÜ¶à½á¹¹»¯³ÌÐòÉè¼ÆÓïÑÔ¶¼ÌṩÁ˼ǼÀàÐ͵ÄÊý¾ÝÀàÐÍ£¬ÔÚPL/SQLÖУ¬Ò²Ö§³Ö½«¶à¸ö»ù±¾Êý¾ÝÀàÐÍÀ¦°óÔÚÒ»ÆðµÄ¼Ç¼Êý¾ÝÀàÐÍ¡£
ÏÂÃæµÄ³ÌÐò´úÂ붨ÒåÁËÃûΪmyrecordµÄ¼Ç¼ÀàÐÍ£¬¸Ã¼Ç¼ÀàÐÍÓÉÕûÊýÐ͵ÄmyrecordnumberºÍÈÕÆÚÐ͵Ämycurrentdate»ù±¾ÀàÐͱäÁ¿×é³É£¬srecordÊǸÃÀàÐ͵ıäÁ


Ïà¹ØÎĵµ£º

SQL ͨÅä·û

ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬SQL ͨÅä·û¿ÉÒÔÌæ´úÒ»¸ö»ò¶à¸ö×Ö·û¡£
SQL ͨÅä·û±ØÐëÓë LIKE ÔËËã·ûÒ»ÆðʹÓá£
ÔÚ SQL ÖУ¬¿ÉʹÓÃÒÔÏÂͨÅä·û£º
ͨÅä·ûÃèÊö
%
Ìæ´úÒ»¸ö»ò¶à¸ö×Ö·û
_
½öÌæ´úÒ»¸ö×Ö·û
[charlist]
×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
[^charlist]
»òÕß
[!charlist]
²»ÔÚ×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
ԭʼµÄ±í (ÓÃÔÚÀý×ÓÖ ......

ÔÚSQL ServerÖÐʹÓÃNewID()·½·¨²úÉúËæ»ú¼¯

ÔÚSQL ServerÖÐʹÓÃNewID()·½·¨²úÉúËæ»ú¼¯
ÀýÈ翼ÊÔϵͳÖеÄËæ»ú³öÌâ
¸Õ¿ªÊ¼Ïëµ½µÄÊÇRandomÀà
µ«ÊÇRandomЧÂÊÓеãµÍ
ºóÀ´Ïëµ½ÁËÔÚÊý¾Ý¿âÀïµÄnewid()
ÓÚÊDzÉÓÃÁËϱ߷½·¨£º
select top 5 * from tablename order by newid()
Ôڴ˱ê¼ÇһϠ......

SQLǶÌ××Ó²éѯ


      ʹÓÃ×Ó²éѯµÄÔ­Ôò
      1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
      2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
      ×Ó²éѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ó¾ä,
&nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ