oracle plsql 常用命令

1 查看oracle的版本信息

(1)用客户端连接到数据库,执行select * from v$instance
查看version项

(2)select * from product_component_version

(3)或查询V$VERSION查看组件级信息

2 merge into


1,变量类型

binary_integer
number
date
boolean
varchar2
char


2 声明变量
declare
v_num number := 0;
begin
v_num := 2/v_num;
dbms_output.put_line(v_num);
exception
when others then
dbms_output.put_line('error');
end ;

/

3、dbms_output.put_line('error'); 不能打印boolean false true null(默认)

4、rowtype
declare
v_temp lifztest3%rowtype;
begin
v_temp.xh := 'rp';
dbms_output.put_line(v_temp.xh);
end;
/


5、type
declare
v_temp lifztest3.xh%type;
begin
v_temp.xh := 'rp';
dbms_output.put_line(v_temp.xh);
end;
/

6
declare
i binary_integer :=1 ;
begin
loop
dbms_output.put_line(i);
i := i+1;
exit when ( i>=11 );
end loop;
end;
/

7 SQLCODE
8 SQLERRM

9游标

declare
cursor c is
select * from lifztest3;
v_xh c%rowtype;
begin
open c;
loop
fetch c into v_xh;
exit when ( c%notfound );
if(v_xh.xh in ('1','2')) then
dbms_output.put_line(v_xh.xh);
else
dbms_output.put_line('aaa'||v_xh.xh);
end if;
end loop;
close c;
end;

10 for 循环游标

declare
cursor c is
select * from lifztest3;
begin
for v_xh in c loop
dbms_output.put_line(v_xh.xh);
end loop;
end;
/


11 游标更新数据

declare
cursor c is
select * from lifztest3 for update;
begin
for v_xh in c loop
if(v_xh.xh = '1001') then
update lifztest3 set xh = '00001' where current of c;
else
update lifztest3 set xh = '1111' where current of c;
end if;
end loop;
commit;
end;
/

12 elsif

declare
cursor c is
select * from lifztest3 for update;
begin
for v_xh in c loop
if(v_xh.xh = '1001') then
update lifztest3 set xh = '00001' where current of c;
elsif(v_xh.xh <> '1111') then
update lifztest3 set xh = '100' where current of c;
end if;
end loop;
commit;
end;
/


13 存储过程

create or replace procedure lifzprot
is
cursor c is
select * from lifztest3 for update;
begin
for v_xh in c loop
if(v_xh.xh = '1001') then
update lifztest3 set xh = '00001' where current of c;
elsif(v_xh.xh <> '1111') then
update lifztest3 set xh = '111' where current of c;
end if;
end loop;
commit;
end;
/

14计算一个表字段数


select a.tname,count(*) field_count from tab a,user_col_comments b
where a.tabtype='TABLE' and a.tname=b.table_name and a.tname='表名' group by a.tname
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值