温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

oracle 常用语句

发布时间:2020-06-01 10:27:38 来源:网络 阅读:342 作者:116923470 栏目:关系型数据库

1.decode 函数(小版本的case when)

select  decode(pd.discount_id,null,'','购买'||pd.product_count||'个,'||pd.product_discount_rate||'折优惠') as discount 
from b2b_product d right join b2b_product_hot ph on d.product_id = ph.product_id  left join b2b_dictionary a
on d.RRO_MARQUE = a.CODE  left join b2b_dictionaryindex b on d.RRO_BRAND = b.INDEXCODE
left join b2b_company c on d.COMPANY_ID = c.COMPANY_ID
left join b2b_product_discount pd on pd.product_id = d.product_id
order by ph.sort, ph.pro_type;

2.varchar排序

select p.code,
      
 case
        
 when p.state =
 '0' then
          decode(b.state,
 '1', '1', '0' )
        
 when p.state =
 '1' then
          decode(b.state,
 '0', '0', '1' )
      
 end as 
 
 from b2b_paytype_dic p, b2b_buyer_paytype b
where p.code = b.paytype_code(+)
  
 and (b.buyer_id =
 ' ' or b.id is null)
  
 order by to_number(p.code) 

3.case  then 语句

select case when order_state= 2 then '已兑换' when order_state= 3 then '交易成功' end ORDER_STATE , sum(order_count) as cnt from t_report_order t where 1=1 

4.手机号的显示sql 例如 (158****2640)

select  substr(r.mobile,1,3)||'****'||substr(r.mobile,8) as mobile from t_prize_record r;

5.给某个表备份
select * into xyq_college_20120301(表的别名) from xyq_college(表名)
6.convert 截取时间
  select *  from vas_mt_viewmt where phone ='15966605352' and convert(nvarchar  (10),createtime,121)='2011-09-14'
7.--将 字符串时间列,统一转化为时间,并减一
  update wfjs_useStats_woman
  set createdate=convert(varchar(10),cast(createdate as datetime)-1,120)
8.只复制表结构的sql
  create table b as select * from a where 1<>1 
9.即复制表结构又复制表中数据的sql
  create table b as select * from a 
10、将多个表数据插入一个表中
   insert into 目标表test(字段1。。。字段n) (select 字段1.。。。。字段n) from 表 union all select 字段1.....字段n from 表


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI