Oracle相关文档,希望互相学习,共同进步
1.背景
Oracle实用查询SQL、执行处理。主要包括:
1)配置密码有效期
2)数据泵导入导出
3)表空间、用户创建
4)循环调用、死锁、SQL执行进度
2. 配置密码有效期
1)查询密码有效时长
select * from dba_profiles where profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';
2)查询当前用户密码到期日
select username,account_status,expiry_date,profile from dba_users;
3)设置密码永不到期
alter profile default limit password_life_time '90'; --90天到期
alter profile default limit password_life_time unlimited; --永久到期
2.数据泵导入导出
1)expdp 导出
Expdp nh_mcro_collect/xx@orclpdb1 directory=BACKUP dumpfile=x.dmp logfile=x.log compression=all
2)impdp导入
impdp NH_MCRO_COLLECT_MOVE/[email protected]/orclpdb1 dumpfile=x.dmp directory=BACKUP logfile=x.log remap_tablespace=NY_DATA_COLLECT:NH_MCRO_COLLECT_DATA remap_schema=nh_mcro_collect:nh_mcro_collect_move
3.实用执行
3.1 sql执行进度
查询sql执行百分比,很实用。
--sql执行进度: SELECT SE.SID, OPNAME, TRUNC(SOFAR / TOTALWORK * 100, 2) || '%' AS PCT_WORK, ELAPSED_SECONDS ELAPSED, ROUND(ELAPSED_SECONDS * (TOTALWORK - SOFAR) / SOFAR) REMAIN_TIME, SQL_TEXT FROM V$SESSION_LONGOPS SL, V$SQLAREA SA, V$SESSION SE WHERE SL.SQL_HASH_VALUE = SA.HASH_VALUE AND SL.SID = SE.SID AND SOFAR != TOTALWORK ORDER BY SE.SID;
3.2 查询死锁
--死锁 SELECT OBJECT_NAME, SESSION_ID SID, MACHINE, VS.MODULE, 'ALTER SYSTEM KILL SESSION ''' || SESSION_ID || ', ' || SERIAL# || '''; ' KILL_SESSION, VS.STATUS, VS.ACTION, SERIAL#, ORACLE_USERNAME, OS_USER_NAME FROM V$LOCKED_OBJECT VO, V$SESSION VS, ALL_OBJECTS AO WHERE VO.SESSION_ID = VS.SID AND AO.OBJECT_ID = VO.OBJECT_ID AND NVL(VS.ACTION, ' ') <> 'Service Management ' ORDER BY OBJECT_NAME, MACHINE, VS.MODULE;
3.3 循环调用过程-按月份
--月份循环 function day_end_once(pDataIssue in varchar2) return varchar2 is vResult varchar2(10); vData_id varchar2(7); v_date date; begin vResult := '0'; v_date := date '2022-01-01'; loop vData_id := to_char(v_date, 'yyyy-mm'); /*----业务执行过程 2024.7.8 ----*/ IF pg_nh_yw_xx.get_nh_yw_xx(vData_id) = '1' THEN vResult := '1'; END IF; exit when vData_id = pDataIssue; v_date := add_months(v_date, 1); end loop; End;
--循环跑批 test
declare
date_id varchar2(32);
vResult Varchar2(4000);
begin
vResult :='0';
date_id :='2022-01';loop
vResult := pg_mp_szmx.get_mp_szmx(date_id);
exit when date_id = '2022-12' ;
date_id:= to_char(add_months(to_date(date_id,'yyyy-MM'),1),'yyyy-MM') ;
end loop ;end ;
普通调用:
--调用
begin
-- Call the function
:result := pg_as_org_range.get_as_expenditure_range(pDataIssue => :pDataIssue);
end;
begin
-- Call the function
:result := pg_as_org_range.get_as_income_range(pDataIssue => :pDataIssue);
end;
3.4 查询2个月份之间月份清单
sql语句:
--两个月份之间的月份清单: SELECT TO_CHAR(ADD_MONTHS(start_date, LEVEL - 1), 'YYYY-MM') AS month FROM (SELECT TO_DATE('2022-01', 'YYYY-MM') AS start_date, TO_DATE('2024-08', 'YYYY-MM') AS end_date FROM DUAL) CONNECT BY LEVEL <= MONTHS_BETWEEN(end_date, start_date) + 1;
3.5 创建用户
create user NH_MCRO_COLLECT_MOVE identified by xxx
default tablespace NH_MCRO_COLLECT_DATA
temporary tablespace TEMP
profile DEFAULT
quota unlimited on NH_MCRO_COLLECT_data
quota unlimited on ny_data;
grant read, write on directory SYS.BACKUP to NH_MCRO_COLLECT_MOVE;
-- Grant/Revoke role privileges
grant connect to NH_MCRO_COLLECT_MOVE;
grant exp_full_database to NH_MCRO_COLLECT_MOVE;
grant imp_full_database to NH_MCRO_COLLECT_MOVE;
grant resource to NH_MCRO_COLLECT_MOVE;
-- Grant/Revoke system privileges
grant create database link to NH_MCRO_COLLECT_MOVE;
grant create procedure to NH_MCRO_COLLECT_MOVE;
grant create public database link to NH_MCRO_COLLECT_MOVE;
grant create sequence to NH_MCRO_COLLECT_MOVE;
grant create session to NH_MCRO_COLLECT_MOVE;
grant create table to NH_MCRO_COLLECT_MOVE;
grant create view to NH_MCRO_COLLECT_MOVE;
grant debug connect session to NH_MCRO_COLLECT_MOVE;
grant execute any procedure to NH_MCRO_COLLECT_MOVE;
grant select any table to NH_MCRO_COLLECT_MOVE;
3.6 表空间扩展
查询表空间大小:
SELECT TABLESPACE_NAME, SUM(BYTES) / 1024 / 1024 / 1024 AS "TOTAL_GB", SUM(MAXBYTES) / 1024 / 1024 / 1024 AS "MAX_GB", SUM(BYTES - MAXBYTES) / 1024 / 1024 / 1024 AS "FREE_GB"
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME;
创建表空间:
CREATE TABLESPACE tablespace_name DATAFILE '数据文件路径' SIZE 大小 [AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED];
增加表空间:
ALTER TABLESPACE xxx ADD DATAFILE '新数据文件的存储位置' SIZE 数据文件大小;
临时表空间大小和数据文件路径:
SELECT tablespace_name, file_name, bytes/1024/1024 "Size_MB"
maxbytes / 1024 / 1024/1024 AS max_size_Gb,
FROM dba_temp_files;临时表空间扩展:
ALTER TABLESPACE temp ADD TEMPFILE '/u01/app/oracle/oradata/yourdb/temp02.dbf' SIZE 100M AUTOEXTEND ON NEXT 1024M MAXSIZE UNLIMITED;如:ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA/TEMP/TEMP02.DBF'
SIZE 1G AUTOEXTEND ON NEXT 1024M MAXSIZE UNLIMITED
结束:ok
项目管理--相关知识
项目管理-项目绩效域1/2_八大绩效域和十大管理有什么联系-CSDN博客
项目管理-计算题公式【复习】_项目管理进度计算题公式:乐观-CSDN博客
项目管理-相关知识(组织通用治理、组织通用管理、法律法规与标准规范)-CSDN博客
Oracle其他文档,希望互相学习,共同进步
Oracle-找回误删的表数据(LogMiner 挖掘日志)_oracle日志挖掘恢复数据-CSDN博客
oracle 跟踪文件--审计日志_oracle审计日志-CSDN博客
ORA-12899报错,遇到数据表某字段长度奇怪现象:“Oracle字符型,长度50”但length查却没有50_varchar(50) oracle 超出截断-CSDN博客