PL/SQL编程基本概念
发布日期:2021-05-14 13:05:34 浏览次数:18 分类:精选文章

本文共 3770 字,大约阅读时间需要 12 分钟。

PL/SQL������������������������������������������������������������������������������PL/SQL���������������������������������������������������������������������PL/SQL������������������������������������������������������������������������������������������������������������������������������

1. ���������������������

���PL/SQL������������������������������������������������������������������������������������������������������������������������������������

  • number������������������������������������������������ number(5,2) ���������������������������
  • varchar2���������������������������������������������������������������������
  • date���������������������������������

������������������������������

declare
v_name varchar2(20); -- ���������������
v_price number; -- ������������
v_rate constant number(7,2) := 1.10; -- ������
BEGIN
-- ������������������������������������������
-- ������������������SELECT INTO������
select ename, sal * v_rate into v_name, v_price from employee where empno = '7788';
-- ������������������������
v_name := '������';
END;

2. ������������

���������PL/SQL���������������������������������������PL/SQL������������������������������������������������

������������������������������������������������������������������������

declare
v_comm employee.comm%type;
e_comm_is_null exception;
begin
select comm into v_comm from employee where empno = 7788;
if v_comm is null then
raise e_comm_is_null;
end if;
exception
when no_data_found then
dbms_output.put_line('������������������������������' || sqlcode || sqlerrm);
when e_comm_is_null then
dbms_output.put_line('������������������');
when others then
dbms_output.put_line('������������������������');
end;

3. ���������

PL/SQL������������if���case���loop���for������������������������������������������������������������

���������������if������������������

if v_counter >= 10 then
null; -- ���������������������������������null���������������������
else
v_counter := v_counter + 10;
end if;

4. ������������

PL/SQL���������������������������������������������������������������������������

���������������������������������������

insert into toys values(1, '������', 525, sysdate);

5. ���������������

���������PL/SQL������������������������������������������������������������������������

������������������������������������������������������

declare
v_ename employee.ename%type;
v_sal employee.sal%type;
emp_cursor is cursor for select ename, sal from employee;
begin
open emp_cursor;
loop
fetch emp_cursor into v_ename, v_sal;
exit when emp_cursor%notfound;
dbms_output.put_line('���'|| emp_cursor%rowcount ||'������������' || v_ename || '������������:' || v_sal);
end loop;
close emp_cursor;
end;

6. ������������������

���������������������������������������������������������������������������������������������������������������������������������������������

insert into toys (id, name) values(1, '������');

������������������

��������� Pell������ violated ������ ������������ 15, 2023 12:34:56 ������
ORA-01581: ������������ - UNIQUE���������������������������������

7. ��������� PL/SQL ������������

������������������������������������������������������

declare
v_id number;
begin
select id into v_id from toys where id = 1;
dbms_output.put_line('������������������������:'||v_id||'���������');
end;

������

PL/SQL������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Maintainability���

上一篇:PL/SQL经典练习
下一篇:oracle基本笔记整理及案例分析2

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年05月01日 20时18分55秒