替代变量
基本概念:
替代变量的操作就类似键盘代替输入的操作。
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 --取消替代变量的值 即:清楚替代变量的值 一般用在某个替代变量的值保持之前值的时候