细致杂项-未能注意的细节(需要多实践)

1、通配符 _ 是不是只能是以为

SQL> 
SQL> with a as
  2  (select 'ABCDE' aa from dual   --ABC后面2位
  3  union all
  4  select 'ABCD' aa from dual     --ABC后面1位
  5  union all
  6  select 'ABC' aa from dual      --ABC后面没有
  7  )
  8  select * from a
  9  where a.aa like 'ABC_';
AA
-----
ABCD
结论,_ 表示有且仅只能有一位。


2、存储过程定义时参数是否可以定义长度

create or replace procedure p_test_num as
  num_1 number(10);
begin
  num_1 := 100;
  dbms_output.put_line(num_1);
end;
--调用
begin
p_test_num;
end;

--语句块
declare num_1 number(10);
begin
num_1 := 100; dbms_output.put_line(num_1);
end;
证实 参数不能定义长度,定义(declare)里可以定义

此处注:sqlplus里调用有传出参数的存储过程(exec 不太好用),begin p_test_num; end; 好用


3、存储过程里或者语句块中是否可以 A++

declare
  num_1 number; --输出参数
begin
  num_1 := 1; -- 初始化值
  for i in 1 .. 10 loop
    dbms_output.put_line(num_1);
    num_1 ++;
  end loop;
end;
证实不行 可以用 num_1:=num_1+1;



4、简答递归及小注意点

with config as
 (select 261 config_id,
         '107569;1006952;200000001;200000002;200000003;0;' conifg_value
    from dual
  union
  select 262, '10685'
    from dual)
select a.config_id,regexp_substr(a.conifg_value,'[^;]+',1,level) cn
from config  a 
connect by  level<=regexp_count(a.conifg_value,'[^;]+')
and   prior config_id = config_id  --去重复(仅自我递归)
and prior dbms_random.value is not null  --防循环
;



5、DBMS_output put 与 put_line 区别

DBMS_OUTPUT.put不带换行符,DBMS_OUTPUT.put_line带换行符,
单纯用DBMS_OUTPUT.put的话看不到输出结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值