Oracle 使用指北

一、 常用Query

# 查看表名称
select table_name, tablespace_name from user_tables;

二、 sqlplus的使用

2.1 简介

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 简介

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 简介

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 这个默认的域名是可以访问的。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容