Oracle_sql-复制表,拼接,函数
Oracle_sql-复制表,拼接,函数
-
选择一张表内容插入到表中 --- 要求目标表存在
INSERT INTO table1 (字段1,字段2,字段3......)SELECT 字段1,字段2,字段3...... FROM table2 ; commit; -
选择一张表内容插入到表中 --- 要求目标表不存在
SELECT v1,v2 INTO table2 FROM table1 ;
commit; -
拼接字符串
变量||'%' -
自定义函数:
先执行 ---> 再编译 -
左外连接 left outer join on 条件
select a.riskcode, a.agentcode, a.standprem, b.rate1, b.startdate
from fsinsureprem a
left outer join labankwagerate b
on a.riskcode = b.riskcode
and a.managecom = b.MANAGECOM
and a.signdate = b.startdateselect a.riskcode, a.agentcode, a.standprem, b.rate1, b.startdate from fsinsureprem a ,labankwagerate b where a.riskcode = b.riskcode(+) and a.managecom = b.MANAGECOM(+) and a.signdate = b.startdate(+) select a.riskcode,a.agentcode, a.standprem, b.rate1, b.startdate from fsinureprem a, labankwagerate b left outer join labankwagerate b where a.riskcode = b.riskcode and a.managecom = b.managecom and a.signdate = b.startdate -
sql函数中的条件判断
if 条件 then XXX elsif 条件 then XXX end if -
sql计算两个字符串日期之间的年数差值
select
trunc(months_between(to_date(substr('20170201',0,6),'yyyymm'),
to_date('201202','yyyymm'))/12)
from dual; -
计算一个月的所有天数
select to_date('200809','yyyymm')+(rownum-1) s_date from dual connect by rownum<=last_day(to_date('200809','yyyymm')) - to_date('200809','yyyymm')+1 -
函数add_months()
TO_CHAR(ADD_MONTHS(TO_DATE(vEmploydate, 'yyyymm'), 1), 'yyyymm') -
判断是不是为空
eg:case when 字段 is null then ... end -
with select from --- 可直接运行
with cr as (select 1 as a, 2 as b from dual), cr2 as (select 3 as c, 4 as d from dual)
select * from cr, cr2

浙公网安备 33010602011771号