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

相关推荐
_大学牲17 小时前
Flutter 之魂 Dio🔥:四两拨千斤的网络库
前端·数据库·flutter
方二华17 小时前
7 mysql对order by group by join limit count的实现
数据库·mysql
SelectDB17 小时前
更高效的数据处理解决方案:基于 MinIO 部署 Apache Doris 存算分离版本实践
数据库·数据分析·apache
寒月霜华18 小时前
JavaWeb后端-MySQL
数据库·mysql
Fuly102418 小时前
大模型的记忆与管理及长期记忆实现方式
数据库·人工智能·rag
weixin_3077791318 小时前
C#程序实现将Teradata的存储过程转换为Azure Synapse Dedicated SQL pool的存储过程
数据库·数据分析·c#·云计算·azure
vortex519 小时前
在 Windows 系统中安装 Oracle、SQL Server(MSSQL)和 MySQL
windows·oracle·sqlserver
折翼的恶魔19 小时前
SQL 189 统计有未完成状态的试卷的未完成数和未完成率
数据库·sql
yangmf204019 小时前
如何使用 INFINI Gateway 增量迁移 ES 数据
大数据·数据库·elasticsearch·搜索引擎·gateway
运维李哥不背锅20 小时前
Ansible 的条件语句与循环详解
数据库·ansible