set serveroutput on
--fuck
declare
v_name varchar2(50) :=7788;
begin
select ename into v_name from emp where empno = &eno;
dbms_output.put_line('name:'|| initcap(v_name));
exception
when no_data_found then dbms_output.put_line('cant find this person');
end;
set serveroutput on
declare
pp number(38,33);
begin
pp := 100000/3;
dbms_output.put_line((pp));
dbms_output.put_line((pp*3+5/3));
exception
when no_data_found then dbms_output.put_line('cant find this person');
end;
set serveroutput on
declare
v_ename emp.ename%type;
v_deptno dept.deptno%type;
v_dept_row dept%rowtype;
begin
select ename ,deptno into v_ename,v_deptno from emp where empno=&eno;
select * into v_dept_row from dept where deptno=v_deptno;
dbms_output.put_line('您要查找的员工是:'||v_ename||',所在部门信息为:');
dbms_output.put_line('部门编号:'||v_deptno|| ' 部门名称:'||v_dept_row.dname||' 所在地:'||v_dept_row.loc);
end;
set serveroutput on
declare
type emp_record_type is RECORD(
ename emp.ename%type,
sal emp.sal%type,
comm emp.comm%type,
total_sal sal%type
);
v_emp_record emp_record_type;
begin
select ename,sal,nvl(comm,0),sal+nvl(comm,0) into v_emp_record
from emp where empno=7369;
dbms_output.put_line('员工姓名:'|| v_emp_record.ename);
dbms_output.put_line('基本工资:'|| v_emp_record.sal);
dbms_output.put_line('奖金:'|| v_emp_record.comm);
dbms_output.put_line('实发工资:'|| v_emp_record.total_sal);
end;
declare
type dept_table_type is table of dept%rowtype
index by binary_integer;
v_dept_table dept_table_type;
begin
select * into v_dept_table(0) from dept where deptno=10;
select * into v_dept_table(1) from dept where deptno=20;
dbms_output.PUT_LINE('编号:'||v_dept_table(0).deptno||' 名称:'
||v_dept_table(0).dname||' 所在地:'||v_dept_table(0).loc);
dbms_output.PUT_LINE('编号:'||v_dept_table(1).deptno||' 名称:'
||v_dept_table(1).dname||' 所在地:'||v_dept_table(1).loc);
end;
IF 条件表达式1 THEN
语句段1
ELSIF 条件表达式2 THEN
语句段2
ELSIF 条件表达式3 THEN
语句段3
......
ELSIF 条件表达式n
语句段n
END IF;
declare
v_emp emp%rowtype;
begin
v_emp.empno:=&no;
select * into v_emp from emp where empno=v_emp.empno;
dbms_output.PUT_LINE('更新前的奖金'||nvl(v_emp.comm,0));
if v_emp.comm is null then
update emp set comm=v_emp.sal*0.1 where empno=v_emp.empno;
elsIf v_emp.comm<1000 then
update emp set comm=1000 where empno=v_emp.empno;
else
update emp set comm=comm+comm*0.1 where empno=v_emp.empno;
end if;
end;
declare
v_deptno dept.deptno%type:=&deptno;
begin
case v_deptno
when 10 then dbms_output.put_line('部门所在地:纽约');
when 20 then dbms_output.put_line('部门所在地:达拉斯');
when 30 then dbms_output.put_line('部门所在地:芝加哥');
when 40 then dbms_output.put_line('部门所在地:波士顿');
else dbms_output.put_line('不存在该部门');
end case;
end;
declare
v_sal emp.SAL%type;
begin
select sal into v_sal from emp where empno=&empno;
case
when v_sal<2000 then dbms_output.put_line('A级工资');
when v_sal>=2000 and v_sal<3000 then
dbms_output.put_line('B级工资');
else dbms_output.put_line('C级工资');
end case;
exception
when no_data_found then
dbms_output.put_line('员工编号不存在');
end;
LOOP
语句段;
EXIT [WHEN 条件表达式]
END LOOP;
WHILE 条件表达式 LOOP
语句段;
END LOOP;
FOR 循环变量 in [REVERSE] 初值表达式..终值表达式 LOOP
语句段;
END LOOP;
declare
type dept_table_type is table of dept%rowtype
index by binary_integer;
i number(1):=0;
v_dept_table dept_table_type;
begin
v_dept_table(0).deptno:='50';
v_dept_table(0).dname:='研发部';
v_dept_table(0).loc:='北京';
v_dept_table(1).deptno:='60';
v_dept_table(1).dname:='开发部';
v_dept_table(1).loc:='上海';
v_dept_table(2).deptno:='70';
v_dept_table(2).dname:='推广部';
v_dept_table(2).loc:='北京';
loop
if i>2 then exit; end if;
insert into dept values
( v_dept_table(i).deptno,v_dept_table(i).dname,v_dept_table(i).loc);
i:=i+1;
end loop;
end;
while i<=2 loop
insert into dept values( v_dept_table(i).deptno,v_dept_table(i).dname,v_dept_table(i).loc);
i:=i+1;
end loop;
for i in 0..v_dept_table.count-1 loop
insert into dept values
( v_dept_table(i).deptno,v_dept_table(i).dname,v_dept_table(i).loc);
end loop;
EXCEPTION
WHEN 异常错误名称1 [OR 异常错误名称2......] THEN
语句段1;
WHEN异常错误名称3 [OR 异常错误名称4......] THEN
语句段2;
......
WHEN OTHERS THEN
语句段3;
评论区