一、 常用Query
# 查看表名称
select table_name, tablespace_name from user_tables;
二、 sqlplus的使用
2.1 简介
- sqlplus 是oracle下的命令行工具,可以直接执行sql命令。
- https://blog.csdn.net/chinabestchina/article/details/118771794
2.2 用法
# 连接数据库
sqlplus username/password@hostname/dbname
# 执行sql(sql文件末尾要加exit)
sqlplus username/password@hostname/dbname @schema.sql
# 执行简易的sql命令
sql="
drop table t1;
drop table t2;
exit
"
echo "${sql}" | sqlplus username/password@hostname/dbname
三、sqlldr的使用
3.1 简介
- sqlldr结合spool命令可以对数据进行导出。
- https://blog.csdn.net/chinabestchina/article/details/118771794
3.2 用法
# 需要首先准备item.ctl文件,示例如下
# table name一定要大写
options(skip=1,BINDSIZE=20971520, ROWS=10000, READSIZE=20971520, ERRORS=10)
load data
infile '/home/katsura/data/item.csv'
append into table "ITEM"
fields terminated by ';'
TRAILING NULLCOLS
(
item_sk ,
current_price ,
wholesale_cost ,
brand_id ,
class_id ,
category_id ,
manufact_id
)
sqlldr username/password@hostname/dbname control=item.ctl direct=true parallel=true
四、Explain用法
4.1 简介
- Oracle支持使用explain命令显示执行的plan,使用explain后,plan detail会被存在一个专门的表plan_table中,如需查看需要另写sql查询。
- https://docs.oracle.com/cd/B10501_01/server.920/a96533/ex_plan.htm#838
4.2 用法
-- explain sql命令
explain plan set statement_ID='plan1' for select * from item;
--- 控制输出格式
column Rows format 99999999
column Plan format a50
-- 从plan_table中查询plan
SELECT cardinality "Rows",
lpad(' ',level-1)||operation||' '||
options||' '||object_name "Plan"
FROM PLAN_TABLE
CONNECT BY prior id = parent_id
AND prior statement_id = statement_id
START WITH id = 0
AND statement_id = 'plan1'
ORDER BY id;
五、Oracle Linux 8 的一些小问题
使用podman 或者 docker 安装 Oracle Linux 8 的时候,sudo yum update 或者 sudo yum install 的时候会有一些小问题,这个可能是源的问题。
源链接在/etc/yum.repos.d/ 下的oracle-linux-ol8.repo 文件与 oraclelinux-developer-ol8.repo 文件里。
可以看到 oracle-linux-ol8.repo 里面是大概类似这样的:
# file: /etc/yum.repos.d/oracle-linux-ol8.repo
[ol8_baseos_latest]
name=Oracle Linux 8 BaseOS Latest ($basearch)
baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL8/baseos/latest/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
[ol8_appstream]
name=Oracle Linux 8 Application Stream ($basearch)
baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL8/appstream/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
里面这个变量 ociregion 与 ocidomain 变量的值在 /etc/yum/vars/下的两个文件 ociregion 与 ocidomain 里。
ociregion 的值可能是-us-phoenix-1,ocidomain 的值是oracle.com。不过这个默认值也就是域名yum-us-phoenix-1.oracle.com 我试了很多次是访问不了的,后面尝试把ociregion的值置空就能访问了,也就是 yum.oracle.com 这个默认的域名是可以访问的。