本篇继续PL_SQL知识的积累。
PL-SQL里面的select语句必须返回一条记录且只能返回一条记录。
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
select ename,sal into v_ename,v_sal from emp where empno = 7369;
dbms_output.put_line(v_ename ||' '|| v_sal);
end;
PL-SQL里面的insert into等其他的dml语句与SQL里面类似,只是可能运用变量来执行。
declare
v_deptno dept.deptno%type :=50;
v_dname dept.dname%type := 'aaa';
v_loc dept.loc%type := 'bj';
begin
insert into dept2 values(v_deptno,v_dname,v_loc);
commit;
end;
sql关键字及其rowcount属性
declare
v_deptno emp2.deptno%type :=50;
v_count number;
begin
update emp2 set sal = sal/2 where deptno = v_deptno;
dbms_output.put_line(sql%rowcount || '条记录被影响');
commit
end;
DDL语句:---需要加execute immediate
begin
execute immediate 'create table T(nnn varchar2(20) default ''aaa'')';
end;