-
如何編寫PLSQL面向過程的語言(PLSQL程序體)
IF語句的3中形式
if ?條件 ?then ?語句1;
語句2;
end if;
if ?條件 ?then ?語句序列1:
else ?語句序列2;
end ?if;
if ?條件 ?then ?語句;
elsif ?語句 ?then ?語句;
else ?語句;
end if;
查看全部 -
引用型變量
my_name emp.ename%type;
??--表示my_name這個變量的類型是引用emp這個表的ename列的類型
記錄型變量
emp_rec emp%rowtype
--emp_rec相當(dāng)于一個數(shù)組,存的類型是一條記錄中的類型,打印某一列的時候,直接用emp_rec.列名即可
如:
select * into emp_rec from emp where empno=7389;
dbms_output.put_line(emp_rec.sal);
查看全部 -
PLSQL
declare部分:定義基本變量
類型:char,varchar2,date,number,boolean,long
定義語法:變量名 ? 數(shù)據(jù)類型(長度)
查看全部 -
PLSQL程序設(shè)計
學(xué)習(xí)PLSQL的目的:
PLSQL是sql的擴(kuò)展,操作oracle數(shù)據(jù)庫效率最高,一般通過PLSQL實現(xiàn)簡單的處理業(yè)務(wù),再通過程序接口調(diào)用
是學(xué)習(xí)存儲過程,存儲函數(shù),觸發(fā)器三大數(shù)據(jù)庫對象的重要基礎(chǔ)
第一個PLSQL程序
查看全部 -
declare
說明部分(變量說明、光標(biāo)申明、例外說明)
begin
語句序列(DML語句)
exception
例外處理語句
end;
/
查看全部 -
plsql while循環(huán)
loop循環(huán)
for循環(huán)
查看全部 -
plsql中if語句的使用
查看全部 -
記錄型變量
查看全部 -
引用類型變量
查看全部 -
plsql
查看全部 -
PL/SQL:procedure Language/SQL
PL/SQL是Oracle對sql語言的過程化擴(kuò)展,指在原有的增刪查改的基礎(chǔ)上,對SQL命令語言中增加了過程處理語句(如分支,循環(huán)等),使SQL語言具有過程處理能力。
查看全部 -
set serveroutput on
declare????--(說明部分可以不寫)
????--說明部分(變量,光標(biāo)或者例外)
begin
????--程序體
????dbms_output.put_line('hello world');
查看全部 -
set serveroutput on;
declare
cursor c1 is select dno,dname from dep;
pdno dep.dno%TYPE;
pdname dep.dname%type;
cursor c2(aa varchar2,bb number) is select grade from sc where cno=(select cno from course where cname=aa)
and sno in (select sno from student where dno=bb);
pgrade sc.grade%type;
count1 number;count2 number;count3 number;avgg number;
coursename varchar2(100):='大學(xué)物理';
begin
open c1;
loop
fetch c1 into pdno,pdname;
exit when c1%notfound;
count1 :=0;count2 :=0;count3 :=0;
select avg(grade) into avgg from sc where cno=(select cno from course where cname=coursename)
and sno in (select sno from student where dno=pdno);
open c2(coursename,pdno);
loop
fetch c2 into pgrade;
exit when c2%notfound;
if pgrade <60 then count1:=count1+1;
elsif pgrade >60 and pgrade <=80 then count2:=count2+1;
else count3:=count3+1;
end if;
end loop;
close c2;
insert into msg values (coursename,pdname,count1,count2,count3,avgg);
end loop;
close c1;
dbms_output.put_line('統(tǒng)計完成');
end;
/
查看全部 -
接受鍵盤輸入時需要加地址符
查看全部 -
cursor游標(biāo)有四種屬性 %found %notfound %rowcount %isopen查看全部
舉報