set serveroutput on
declare
name VARCHAR2(20):='faafaf';
begin
dbms_output.put_line(name);
end;
/
一定就单引号,多个空格也不行。
select ... into 语句赋值,其结果必须是一行,不能多行或无纪录。
select ename from scott.emp where empno=7934;
declare
name varchar2(50) default 'null';
begin
select ename into name from scott.emp where empno='7934';
dbms_output.put_line(name);
end;
/
课本P193
declare
m number;
n number;
begin
m:=10;
n:=20;
if m-n>=0 then
dbms_output.put_line(m||'>'||n);
end if;
dbms_output.put_line(m||'<'||n);
end;
课本P195
case 语句
declare
xf number;
begin
select sal into xf from scott.emp where empno=7934;
case
when xf>2500 then
dbms_output.put_line('你的钱好多啊');
when xf>1500 then
dbms_output.put_line('你的钱好多啊2');
else
dbms_output.put_line('你的钱好多啊3');
end case;
dbms_output.put_line('wc');
end;
/
create table scott.temp(id number);
declare
i integer:=1;
begin
loop
insert into scott.temp values (i);
exit when i=10;
i:=i+1;
end loop;
end;
select * from scott.tmep;
declare
name VARCHAR2(20):='faafaf';
begin
dbms_output.put_line(name);
end;
/
一定就单引号,多个空格也不行。
select ... into 语句赋值,其结果必须是一行,不能多行或无纪录。
select ename from scott.emp where empno=7934;
declare
name varchar2(50) default 'null';
begin
select ename into name from scott.emp where empno='7934';
dbms_output.put_line(name);
end;
/
课本P193
declare
m number;
n number;
begin
m:=10;
n:=20;
if m-n>=0 then
dbms_output.put_line(m||'>'||n);
end if;
dbms_output.put_line(m||'<'||n);
end;
课本P195
case 语句
declare
xf number;
begin
select sal into xf from scott.emp where empno=7934;
case
when xf>2500 then
dbms_output.put_line('你的钱好多啊');
when xf>1500 then
dbms_output.put_line('你的钱好多啊2');
else
dbms_output.put_line('你的钱好多啊3');
end case;
dbms_output.put_line('wc');
end;
/
create table scott.temp(id number);
declare
i integer:=1;
begin
loop
insert into scott.temp values (i);
exit when i=10;
i:=i+1;
end loop;
end;
select * from scott.tmep;
本文通过几个具体的示例介绍了PL/SQL的基础用法,包括变量声明与赋值、条件判断、循环操作及简单的数据库操作等。这些示例涵盖了基本的编程结构,并展示了如何在Oracle数据库环境下使用PL/SQL进行数据处理。
4万+

被折叠的 条评论
为什么被折叠?



