数据库:替代变量笔记

     
 
 
 
替代变量
 
 
 
 
基本概念:
 替代变量的操作就类似键盘代替输入的操作。
 
set define on --打开替代变量功能。
set define off --关闭替代变量功能。
 
一、  &  和  && 来定义替代变量

select * 
from t_hr_crew t 
where 
t.p_code = &input;--input接收变量的标记

select * 
from t_hr_crew t 
where 
t.c_name = upper('&input');--upper()


select * 
from t_hr_crew t 
where 
t.c_name = '&input';--字符串


select * 
from t_hr_crew t 
where 
t.c_name like '%&input%';--like


select t.birth_date,t.* 
from t_hr_crew t 
where 
t.birth_date >to_date('&input','yyyy-mm-dd');--日期。当然不实用to_date()的话,输入日月年  也可以的


 
--多个变量
select * 
from t_hr_crew t 
where 
t.c_name like '%&inputlike%'--like
and t.birth_date >to_date('&inputbirth','yyyy-mm-dd');--日期。当然不实用to_date()的话,输入日月年  也可以的
 
--当然替代变量也可以用在select子句当中
select &input1,&input2
from t_hr_crew t
where t.c_name like '%&inputlike%'
and t.birth_date > to_date('&inputbirth', 'yyyy-mm-dd');


 
--代变量也可以用在from,orderby子句当中
select &input1, &input2
from &inputtablename t
where t.c_name like '%&inputlike%'
and t.birth_date > to_date('&inputbirth', 'yyyy-mm-dd')
order by &inputorderby


--group by 中。。。。。。。 
select &inputgroupby,sum(tall)
from t_hr_crew t
where t.c_name like '%&inputlike%'
and t.birth_date > to_date('&inputbirth', 'yyyy-mm-dd')
group by  &inputgroupby 
 
--group by 中 也可以两个&& 
select &&inputgroupby,sum(tall)
from t_hr_crew t
where t.c_name like '%&inputlike%'
and t.birth_date > to_date('&inputbirth', 'yyyy-mm-dd')
group by  &inputgroupby 


 
 
undefine input --取消替代变量的值   即:清楚替代变量的值 一般用在某个替代变量的值保持之前值的时候
 
 
 























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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值