PL/SQLѧϰ±Ê¼ÇÎå
ÓαêÊÇ´ÓÊý¾Ý¿âÖÐÌáÈ¡³öÀ´µÄÊý¾Ý£¬ÒÔÁÙʱ±íµÄÐÎʽ´æ·ÅÔÚÄÚ´æÖУ¬ÔÚÓαêÖÐÓÐÒ»¸öÊý¾ÝÖ¸Õ룬ÔÚ³õʼ״̬ÏÂÖ¸ÏòÊ׼Ǽ£¬ ÀûÓÃfetchÓï¾äÒÆ¶¯¸ÃÖ¸Õ룬´Ó¶ø¶ÔÓαêÖеÄÊý¾Ý½øÐи÷ÖÖ²Ù×÷¡£
1.¶¨ÒåÓαê
cursor ÓαêÃû is selectÓï¾ä;
2.´ò¿ªÓαê
open ÓαêÃû;
3.ÌáÈ¡ÓαêÊý¾Ý
fetch ÓαêÃû into ±äÁ¿Ãû1, ±äÁ¿Ãû2, ....;
»ò
fetch ÓαêÃû into ¼Ç¼ÐͱäÁ¿Ãû;
4.¹Ø±ÕÓαê
close ÓαêÃû;
5.ÓαêµÄÊôÐÔ
%isopen
¸ÃÊôÐÔ±êʶÓαêÊÇ·ñ´ò¿ª£¬Èç¹ûûÓдò¿ªÓαê¾ÍʹÓÃfetchÓï¾ä½«Ìáʾ´íÎó¡£
%isfound
¸ÃÊôÐÔ±êʶһ¸öfetchÓï¾äÊÇ·ñÓÐÖµ£¬ÓÐÖµ·µ»Øtrue£¬·ñÔò·µ»Øfalse¡£
%notfound
¸ÃÊôÐÔÓë%isfoundÏà·´¡£
%rowcount
¸ÃÊôÐÔÓÃÓÚ»ñÈ¡ÓαêµÄÊý¾ÝÐÐÊý¡£
ʾÀý£º
set serveroutput on
declare
tempsal scott.emp.sal%type;
cursor mycursor is
select * from scott.emp
where sal>tempsal;
cursorrecord mycursor%rowtype;
begin
tempsal:=800;
open mycursor;
if mycursor%isopen then
fetch mycursor into cursorrecord;
dbms_output.put_line(to_char(cursorrecord.deptno));
dbms_output.put_line(to_char(mycursor%rowcount));
else
dbms_output.put_line('Óα껹δ´ò¿ª');
end if;
end;
Ïà¹ØÎĵµ£º
½ñÌìºÜÓôÃÆ,ʵÑéÊҵķþÎñÆ÷¶«Î÷¶¼Ã»ÓÐÁË,¶øÎÒµÄÊý¾Ý¿âÓÖÔÚÄÄÀï,ÎÒÓÖûÓб¸·Ý,°ÑÎÒÒÖÓôµÄÒªÃü,ÐÒ¿÷ÎÒÓõÄlinq to sql.×ÐϸÏëÏë,ËûµÄdbmlÎļþ»ù±¾°üº¬ÁËÊý¾Ý¿âµÄËùÓÐÄÚÈÝ,ËùÒÔ,Ò»¶¨Óа취´ÓdbmlÎļþÖд´½¨Êý¾Ý¿â!
Ñо¿ÁËÒ»¶ÎÊ ......
sql serverÖÐÈçºÎÅжϱí»òÕßÊý¾Ý¿âµÄ´æÔÚ£¬µ«ÔÚʵ¼ÊʹÓÃÖУ¬ÐèÅжÏStatus״̬λ£º
ÆäÖÐijЩ״̬λ¿ÉÓÉÓû§Ê¹Óà sp_dboption£¨read only¡¢dbo use only¡¢single user µÈ£©½øÐÐÉèÖãº
1 = autoclose£»Ê¹Óà sp_dboption ÉèÖᣠÊý¾Ý¿âÍêÈ«¹Ø±Õ£¬Æä×ÊÔ´ÔÚ×îºóÒ»¸öÓû§×¢ÏúºóÊÍ·Å¡£
4 = select into/bulkcopy£»Ê¹Óà sp_dbopti ......
select Convert( varchar(20) , ʱ¼ä×Ö¶Î , ¸ñʽ ) from ±í È磺select Convert(varchar(20),LOGIN_DATE,112) from dbo.C_PARTY_CLIENT 100£ºJun 22 2009 12:00AM 101£º06/22/2009 102£º2009.06.22 103£º22/06/2009 104£º22.06.2009 105£º22-06-2009 106£º22
select Convert(varchar(20),<ʱ¼ä×Ö¶Î>,<¸ñʽ>) f ......
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
¡¡¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
......