Oracle常用的 sql语句

---创建表空间SQL:

create tablespace xxx
datafile 'xxx/datafile/xxx.DBF' size 200M
autoextend on next 40M maxsize unlimited
default storage(initial 128k next 128k minextents 2 maxextents unlimited);

---创建临时表空间SQL:

create temporary tablespace xxx
tempfile 'xxx/datafile/xxx.dbf ' size 100M
autoextend on next 20m maxsize unlimited;

---查询表空间和临时表空间

SELECT d.tablespace_name "Name", d.status "Status",
TO_CHAR (NVL (a.BYTES / 1024 / 1024, 0), '99,999,990.90') "Size (M)",
TO_CHAR (NVL (a.BYTES - NVL (f.BYTES, 0), 0) / 1024 / 1024,
'99999999.99'
) USE,
TO_CHAR (NVL ((a.BYTES - NVL (f.BYTES, 0)) / a.BYTES * 100, 0),
'990.00'
) "Used %"
FROM SYS.dba_tablespaces d,
(SELECT tablespace_name, SUM (BYTES) BYTES
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM (BYTES) BYTES
FROM dba_free_space
GROUP BY tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)

----查询表空间文件位置

SELECT tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
FROM dba_data_files
ORDER BY tablespace_name;

----增加表空间

alter tablespace NHIP_DC
add datafile '+DATA/PTORCL/TABLESPACE/NHIP_DC1.dbf' size 30g autoextend on ;

---修改表空间和临时表空间

Alter user test1 default tablespace tbs_test1;  --修改 test1用户的默认表空间是tbs_test1
Alter user ptjob temporary tablespace ptjob_temp;  --修改 test1用户的临时表空间是temp_tbs_test1

---创建用户

-- Create the user
create user YKT_ODS
identified by YKT_ODS
default tablespace YKTODS
temporary tablespace YKTODS_TEMP
profile DEFAULT
quota unlimited on users;
-- Grant/Revoke role privileges
grant connect to YKT_ODS;
grant exp_full_database to YKT_ODS;
grant imp_full_database to YKT_ODS;
grant resource to YKT_ODS;
-- Grant/Revoke system privileges
grant create any job to YKT_ODS;
grant create any sequence to YKT_ODS;
grant create any synonym to YKT_ODS;
grant create any table to YKT_ODS;
grant create any trigger to YKT_ODS;
grant create any view to YKT_ODS;
grant create database link to YKT_ODS;
grant debug any procedure to YKT_ODS;
grant debug connect session to YKT_ODS;
grant insert any table to YKT_ODS;
grant select any table to YKT_ODS;
grant select any transaction to YKT_ODS;
grant unlimited tablespace to YKT_ODS;
grant update any table to YKT_ODS;

--查看用户信息

select * from dba_users;

---设置口令期限为永久

select username,account_status,expiry_date,profile from dba_users;
select * from dba_profiles s where s.profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
alter profile default limit password_life_time unlimited;

---导入表结构

imp system/123456@127.0.0.1/orcl file= E:\ptjob.dmp fromuser=ptjob touser=ptjob ignore=y  ;

imp nhip_empi/nhip_empi@172.29.241.3:1521/orcl file=e:/empi.dmp full=y

---数据库导出

exp system/manager@test file=d:daochu.dmp full=y

---数据库修改新密码

sqlplus /nolog
conn /as sysdba
alter user 用户名 identified by 新密码;

---身份证号转生日

case when t.birthday is null then substr(t.idenno,7,8)
else to_char(t.birthday,'yyyyMMdd')
end as Birthday

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值