oracle 常用语句
admin
2023-05-14 09:02:00
0

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 表


相关内容

热门资讯

以军士兵集体丢掉武器抗命,大喊... 据凤凰卫视报道,以色列国防军一军事基地7月30日发生士兵抗命事件,约120名士兵抗议指挥官做法,将武...
蒋成华任商务部副部长 国务院任免国家工作人员。任命蒋成华为商务部副部长。免去蒋成华的商务部国际贸易谈判副代表职务。
伊朗驻华大使:在军事威胁下,不... 新华社北京7月31日电(记者刁慧琳) 伊朗驻华大使法兹里7月28日表示,伊美回到谈判桌的前提是美国必...
伊朗革命卫队在霍尔木兹海峡击中... 当地时间31日,伊朗伊斯兰革命卫队发布声明称,革命卫队海军当天在霍尔木兹海峡击中并扣留了两艘违反禁令...
美媒:特朗普,遇到了一个更强硬... 据《纽约时报》7月29日报道,就在特朗普总统看似放弃战事升级计划几天后,美国再次与伊朗交火。上周末,...
女子做气管镜时不幸身亡,丈夫称... 7月29日,西安刘先生反映妻子在当地医院做支气管镜检查时死亡,看监控时发现医生疑有违规操作。刘先生表...
全网“帮卖西瓜”,然后呢? 近日,河南部分地区西瓜滞销的消息在网上热度很高。很多地方也伸出援手:有景区收购千斤西瓜、免费赠予游客...
美媒:乌克兰袭击伊朗船只,险引... 据《纽约时报》7月28日报道,据伊朗和西方官员称,伊朗曾考虑攻击乌克兰的一个港口,以报复乌克兰对一艘...
20年里,他只画美女,用东方风... 迈进KIM在上海的工作室,迎面是一整墙的美女们。她们像是刚从一场时髦的沙龙里退场,或倚或立,眉宇间是...
Google在港推出AI代理G... 观点网讯:7月29日,Google在香港推出AI代理Gemini Spark,该代理可全天候在后台运...