Skip to the content.

[TOC]

Oracle

一、介绍

1、锁介绍

移步:https://github.com/ATSJP/note/tree/master/sql/oracle/Oracle锁工作.md

2、事务

移步:https://github.com/ATSJP/note/tree/master/sql/oracle/Oracle之事务.md

二、常用

1、复制表结构,建立新表

-- 建表结构
create table ins.acc_withdraw_info_20190315 as select * from ins.acc_withdraw_info where 1=2

-- 建表结构 数据
create table newtable as select * from oldtable

2、复制其他表的某个数据

insert into tab1 select * from tab2;

3、高级函数

1、语法格式:row_number() over(partition by 分组列 order by 排序列 desc)

**link **: https://blog.csdn.net/qq_25221835/article/details/82762416

其中,row_number得到的是分组的序号

4、恢复表到某个时间点

alter table <tableName> enable row movement;
flashback table <tableName> to timestamp to_timestamp('2019-01-02 10:05:00','yyyy-mm-dd HH24:MI:SS');

5、开启事务

FOR UPDATE

6、查询oracle的版本号

select * from v$version;  

select * from product_component_version;

SET SERVEROUTPUT ON 
EXEC dbms_output.put_line( dbms_db_version.version );  

二、坑

1、时间格式

格式时间 yyyy-mm-dd hh24:mi:ss

2、oracle部分版本不支持 两层以上嵌套自查询(外两层的列,无法识别)

知识加油站: 老外怎么说

3、number和Varchar自动转化的情况

情景一:数据库字段为Varchar2类型,存储字段值都为纯数字字符串。

-- 此时不会报错
select * from table where cloumn = 123

情景二:数据库字段为Varchar2类型,存储字段值为 纯数字字符串,普通带字母英文串 混合。

-- 此时报错
select * from table where cloumn = 123

原因:

oracle在发现查询条件是数字的时候,会将原表的字段进行To_number,当遇到存值为字符串的时候,to_number(‘abc’) 报错。

结论:

切记,保证sql查询类型对应,切勿有此类操作。