Oracle 常用SQL命令

Oracle 常用SQL命令

1、备份单张表

创建复制表结构

create table employeesbak as select * from cims.employees

如果只复制表结构,只需要在结尾加上 where 1=0

插入数据

insert into employeesbak

select * from cims.employees

删除一条数据

delete from jjl_customersource jc where jc.code='C0000151721' and jc.name='唐';

select * from jjl_customersource j where j.code='C0000151721';

2、Sql代码

--查看所有的用户

select * from all_users;

--查看当前用户信息

select * from user_users;

--查看当前用户的角色

select * from user_role_privs;

--查看当前用户的权限

select * from user_sys_privs;

--查看当前用户的表可操作权限

select * from user_tab_privs;

3、获取星期几

select to_char(sysdate,'day') dayth from dual

5、查看所有被锁的表

select b.owner TABLEOWNER, b.object_name TABLENAME, c.OSUSER LOCKBY,

c.USERNAME LOGINID, c.sid SID, c.SERIAL# SERIAL

from vlocked_object a,dba_objects b, vsession c

where b.object_id = a.object_id AND a.SESSION_ID =c.sid;

6、解锁表

alter system kill session 'SID, SERIAL';

7、查看表空间的使用情况

SELECT a.tablespace_name,

a.bytes total,

b.bytes used,

c.bytes free,

(b.bytes * 100) / a.bytes "% USED ",

(c.bytes * 100) / a.bytes "% FREE "

FROM sys.smts_avail a, sys.smts_used b, sys.sm$ts_free c

WHERE a.tablespace_name = b.tablespace_name

AND a.tablespace_name = c.tablespace_name;

8、查看表空间的路径

select tablespace_name, file_id, file_name,

round(bytes/(1024*1024),0) total_space

from dba_data_files where tablespace_name='SYSAUX'

order by file_name;

9、添加数据文件

alter tablespace SYSAUX add datafile '+DATA01/wyzx/datafile/sysaux_20210430' size 10 G;

给表空间SYSAUX添加10G的数据文件

10、删掉重复项

找出主键为nrcelldu_uk,start_time都重复的数据,只留下一条数据

delete from pm.F_5_C_S_NRCELLDU_PRB_Q a

where (a.nrcelldu_uk,a.start_time) in

(select nrcelldu_uk,start_time from pm.F_5_C_S_NRCELLDU_PRB_Q

group by nrcelldu_uk,start_time having count(*) > 1)

and rowid not in (select max(rowid)

from pm.F_5_C_S_NRCELLDU_PRB_Q group by nrcelldu_uk,start_time having count(*)>1

);

commit;

11、查看归档日志

SELECT A.NAME, A.TOTAL_MB / 1024, A.FREE_MB / 1024 FROM V$ASM_DISKGROUP A

相关推荐
RestCloud15 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud15 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence18 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥1 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud2 天前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术2 天前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug2 天前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom2 天前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试