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´æ´¢¹ý³Ì·ÖÒ³Ëã·¨Ñо¿(Ö§³ÖǧÍò¼¶)
1.“¶íÂÞ˹´æ´¢¹ý³Ì”µÄ¸ÄÁ¼°æ
CREATE procedure pagination1
(@pagesize int, --Ò³Ãæ´óС£¬Èçÿҳ´æ´¢20Ìõ¼Ç¼
@pageindex int --µ±Ç°Ò³Âë)
as set nocount on
begin
declare @indextable table(id int identity(1,1),nid int) --¶¨Òå±í±äÁ¿
declare @PageL ......
SQL*LOADERÊÇORACLEµÄÊý¾Ý¼ÓÔع¤¾ß£¬Í¨³£ÓÃÀ´½«²Ù×÷ϵͳÎļþǨÒƵ½ORACLEÊý¾Ý¿âÖС£SQL*LOADERÊÇ´óÐÍÊý¾Ý
²Ö¿âÑ¡ÔñʹÓõļÓÔØ·½·¨¡£
¡¡¡¡ÔÚNTÏ£¬SQL*LOADERµÄÃüÁîΪSQLLDR£¬ÔÚUNIXÏÂÒ»°ãΪsqlldr/sqlload¡£
¡¡¡¡ÈçÖ´ÐУºd:\oracle>sqlldr
SQL*Loader: Release 8.1.6.0.0 - Production on ÐÇÆÚ¶þ 1ÔÂ 8 11:06:42 2 ......
Àý×Ó1) Ò»¸ö±íTable_1 ÓÐÁ½¸ö×Ö¶Î
id number£¬
name varchar2£¨7£©
& ......
SQLÊý¾Ý¿âÖÐÓÃimageÀ´´æ´¢Îļþ,µ«SQLûÓÐÌṩֱ½ÓµÄ´æÈ¡ÎļþµÄÃüÁî.
/*--bcp ʵÏÖ¶þ½øÖÆÎļþµÄµ¼Èëµ¼³ö
Ö§³Öimage,text,ntext×ֶεĵ¼Èë/µ¼³ö
imageÊʺÏÓÚ¶þ½øÖÆÎļþ,°üÀ¨:WordÎĵµ,ExcelÎĵµ,ͼƬ,ÒôÀÖµÈ
text,ntextÊʺÏÓÚÎı¾Êý¾ÝÎļþ
×¢Òâ:µ¼Èëʱ,½«¸²¸ÇÂú×ãÌõ¼þµÄËùÓÐÐÐ
µ¼³öʱ,½ ......
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_movefile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_movefile]
GO
/*--Òƶ¯·þÎñÆ÷ÉϵÄÎļþ
²»½èÖú xp_cmdshell ,ÒòΪÕâ¸öÔÚ´ó¶àÊýʱºò¶¼±»½ûÓÃÁË
--×Þ½¨ 2004.08(ÒýÓÃÇë±£Áô´ËÐÅÏ¢)--*/
/*--µ÷ÓÃʾÀý ......