oracle 常用语句

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 表

oracle 常用语句

时间: 2024-08-07 04:33:58

oracle 常用语句的相关文章

Oracle 常用语句整理

Oracle 常用语句整理 最近做了份大型数据库作业.遇到了一些问题,在网上找的很是辛苦,于是,将一些常用的语句记录下来,方便大家学习.都是一些基本的东西.如果忘了,可以来看看. 1.创建临时表空间 create temporary tablespace car_data //car_data,表空间名 tempfile 'C:\Users\Administrator\Desktop\car_data.dbf'//表空间路径 size 50m autoextend on next 50m max

整理的Oracle常用语句

3个默认用户 sys change_on install [as sysdba] system manager scott tiger创建用户 create user 用户名 identified by 密码 defaul tablespace 表空间(Users) temporary tablespace 表空间(Temp) quota 整数 on 表空间(Users);--quota(限额) 临时表空间不能使用限额修改密码 alter user scott identified by tig

oracle 常用语句3

- oracle 函数 select sign(-3),sign(3), sign(0) from dual; select ceil(3.7) from dual; select floor(3.7) from dual; -- 四舍五入 select round(123.456, 2) from dual; select round(183.456, -2) from dual; select round(183.556) from dual; select trunc(123.456, 2

Oracle 常用语句1

-- 我是注释信息 sql语句 -- 创建用户: create user 用户名 identified by 密码; create user jack identified by j123; -- lacks CREATE SESSION priviledge 用户没有权限连接数据库 -- 授权用户: grant 权限1,权限2 to 用户名; -- 管理员 dba -- 普通用户 connect,resource grant connect,resource to jack; -- 收回权限:

Oracle常用语句

1.查看某个字段在哪张表 select owner, table_name from dba_tab_columns where lower(column_name)='字段名'; 2.导出序列 SELECT ' create sequence username.' || SEQUENCE_NAME ||          ' minvalue ' || MIN_VALUE ||         ' maxvalue ' || MAX_VALUE ||         ' start with

ORACLE常用语句合集

查询库中所有表空间: select tablespace_name from dba_tablespaces; select tablespace_name from user_tablespaces; 查询使用过的表空间: select distinct tablespace_name from dba_all_tables; select distinct tablespace_name from user_all_tables; 查询表空间中所有表名: select table_name

oracle 常用语句2

-- number(38) -- char(2000) -- varchar(4000) create table student( sno number(3) primary key, sname varchar2(40) default ('佚名'), sex char(2) check(sex in('男', '女', '中')), age number(2) check( age between 20 and 30 ), birthday date, sclass varchar2(10

oracle 常用相关sql 语句

一.oracle 常用相关sql 语句 1. 连接数据库       su - oracle -c " sqlsplus 用户/密码     注:首次登陆用  sqlplus / as sysdba            注: 关闭数据库:注:shutdown可加关闭选项,从最温和到最粗暴的行为选项为(shutdown.shutdown transactional.shutdown immediate.shutdown abort)                 shutdown:关闭,等待每

oracle常用SQL语句(汇总版)

Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象 一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSERT INTO 表名(字段名1, 字段名2, ……) SELECT (字段名1, 字段名2, ……) FROM 另外的表名; 字符串类型的字段值必须用单引号括起来, 例如: ’GOOD DAY’ 如果字段值里包含单引号’ 需要