美文网首页
04.使过的Oracle命令(整理中)

04.使过的Oracle命令(整理中)

作者: 笑着字太黑 | 来源:发表于2021-11-19 08:28 被阅读0次

1.新建Schema:

1.1.Login
sqlplus / as sysdba
alter session set container = 【SN】;
1.2.做成tablespace
create tablespace [tablespace]
datafile '/opt/oracle/oradata/ORCLCDB/【SN】/[tablespace].dbf' size 1000M
autoextend on next 100M
maxsize unlimited
;
1.3.做成temp tablespace
create temporary tablespace  [tmp_tablespace]
tempfile '/opt/oracle/oradata/ORCLCDB/【SN】/[tmp_tablespace].dbf' size 50M
;
1.4.创建schema
create user [schema] identified by [password] default tablespace [tablespace] temporary tablespace [tmp_tablespace];
1.5.赋予shecma权限(赋予用户权限)
grant unlimited tablespace to [schema];

2.sqlplus连接数据库:

sqlplus [user]/[password]@[ip]:[port]/[service_name(node)]

3.执行sql文件(sqlplus 登录后)

@create_table.sql;

4.查看当前seq值

SELECT LAST_NUMBER - INCREMENT_BY 
FROM DBA_SEQUENCES 
WHERE 
  SEQUENCE_OWNER='【schema】'
  and SEQUENCE_NAME = '【seq_name】'
;

5.设定当前seq值

计算设定目标值与当前值的差位gap_val
设定seq增长值为gap_val
执行select seq使其增长
设定seq增长值为原本的值
(注意增长值不能为零,需要判断一下)

alter sequence ${SCHEMA}.${SEQ_NAME} increment by ${gap_val};
select ${SCHEMA}.${SEQ_NAME}.nextval from dual;
alter sequence ${SCHEMA}.${SEQ_NAME} increment by ${increment_by};

6.spool导出csv文件

set markup csv on quote off;
set heading off;
set feedback off;
spool [file_path];
SELECT '“[head]”' FROM DUAL;
SELECT XXXX;
spool off;

7.Load CSV 文件

Load命令

#####7.1.sqlldr userid=${USERNAME}/${PASSWORD}@${HOSTNAME}:${PORT}/${SID} control=${ctlPath} bad=${bad_file_path} log=${log_file_path} >> ${自己想出的其他log文件,>>开始到末尾部分不是oracle命令} 2>&1
7.2.CTL文件

CSV文件中的字段按顺序匹配指定的COL_NAME进行导入
支持filler,函数操作,具体比较复杂这里只做个提示就不整理了

OPTIONS(skip=1)
LOAD DATA INFILE '[CSV_PATH]'
INTO TABLE [SCHEMA].[TABLE]
TRUNCATE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
  [COL_NAME], 
  [COL_NAME]
)

相关文章

网友评论

      本文标题:04.使过的Oracle命令(整理中)

      本文链接:https://www.haomeiwen.com/subject/ywsdtrtx.html