---
title: 使用 tee 命令来保存SQL交互式执行的完整记录-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于使用 tee 命令来保存SQL交互式执行的完整记录相关的常见问题和使用技巧，帮助您快速解决使用 tee 命令来保存SQL交互式执行的完整记录的难题。
---
切换语言

- 简体中文
- English

划线反馈

# 使用 tee 命令来保存SQL交互式执行的完整记录

更新时间：2026-05-29 08:46

适用版本： V1.4.x、V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x、V4.3.x 内容类型：TechNote  

原生 Oracle 的 sqlplus 客户端工具提供了一个 spool 命令，可以用来将 SQL*Plus 会话中的所有屏幕输出保存到文件，特别适用于数据库管理员和开发人员生成报告、导出数据或记录操作日志。OceanBase 数据库的 OBClient 客户端工具提供了一个跟 MySQL 客户端工具的 tee 命令同名的命令，也可以实现同样的功能。

## 详细说明

### 可以使用 `tee file_name` 和 `notee` 命令来开始和停止捕获输出到文件

```shell
[root@observer1 ~]# obclient -h127.0.0.1 -usys@oracle -P2881 -pxxx
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221501759
Server version: OceanBase 4.2.5.4 (r104000082025052817-2e9399047c72ee074510f39a687426e4c5649964) (Built May 28 2025 18:36:07)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient(SYS@oracle)[SYS]> tee /tmp/test.txt
Logging to file '/tmp/test.txt'
obclient(SYS@oracle)[SYS]> select now() from dual;
ORA-00600: internal error code, arguments: -5055, FUNCTION NOW does not exist
obclient(SYS@oracle)[SYS]> select systimestamp from dual;
+-------------------------------------+
| SYSTIMESTAMP                        |
+-------------------------------------+
| 05-JUN-25 11.19.15.003430 PM +08:00 |
+-------------------------------------+
1 row in set (0.001 sec)

obclient(SYS@oracle)[SYS]> notee
Outfile disabled.
obclient(SYS@oracle)[SYS]> Bye

```

对应捕获的 `/tmp/test.txt` 文件内容如下。

```shell
[root@observer1 ~]# cat /tmp/test.txt
obclient(SYS@oracle)[SYS]> select now() from dual;
ORA-00600: internal error code, arguments: -5055, FUNCTION NOW does not exist
obclient(SYS@oracle)[SYS]> select systimestamp from dual;
+-------------------------------------+
| SYSTIMESTAMP                        |
+-------------------------------------+
| 05-JUN-25 11.19.15.003430 PM +08:00 |
+-------------------------------------+
1 row in set (0.001 sec)

obclient(SYS@oracle)[SYS]> notee

```

### `tee` 命令目前都是以追加的模式将内容写入到输出文件的

```shell
[root@observer1 ~]# obclient -h127.0.0.1 -usys@oracle -P2881 -pxxx
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221512992
Server version: OceanBase 4.2.5.4 (r104000082025052817-2e9399047c72ee074510f39a687426e4c5649964) (Built May 28 2025 18:36:07)

obclient(SYS@oracle)[SYS]> tee /tmp/test.txt
Logging to file '/tmp/test.txt'
obclient(SYS@oracle)[SYS]>
obclient(SYS@oracle)[SYS]>
obclient(SYS@oracle)[SYS]> select systimestamp from dual;
+-------------------------------------+
| SYSTIMESTAMP                        |
+-------------------------------------+
| 05-JUN-25 11.20.16.074102 PM +08:00 |
+-------------------------------------+
1 row in set (0.000 sec)

obclient(SYS@oracle)[SYS]> Bye

```

obclient(SYS@oracle)[SYS]> notee
obclient(SYS@oracle)[SYS]>
obclient(SYS@oracle)[SYS]>
obclient(SYS@oracle)[SYS]> select systimestamp from dual;
+-------------------------------------+
| SYSTIMESTAMP                        |
+-------------------------------------+
| 05-JUN-25 11.20.16.074102 PM +08:00 |
+-------------------------------------+
1 row in set (0.000 sec)

```

**说明：如果想以覆盖的模式将屏幕输出写入到文件，可以先手工清空该文件。** 示例如下。

```shell
[root@observer1 ~]# :> /tmp/test.txt
或者：
obclient(SYS@oracle)[SYS]> system :> /tmp/test.txt

```

### 也可以将 `--tee=file_name` 作为 OBClient 命令的附加选项直接使用

```shell
[root@observer1 ~]# obclient -h127.0.0.1 -usys@oracle -P2881 -pxxx --tee=/tmp/test.txt
Logging to file '/tmp/test.txt'
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221546363
Server version: OceanBase 4.2.5.4 (r104000082025052817-2e9399047c72ee074510f39a687426e4c5649964) (Built May 28 2025 18:36:07)

obclient(SYS@oracle)[SYS]> select systimestamp from dual;
+-------------------------------------+
| SYSTIMESTAMP                        |
+-------------------------------------+
| 05-JUN-25 11.21.35.762387 PM +08:00 |
+-------------------------------------+
1 row in set (0.000 sec)

```

obclient(SYS@oracle)[SYS]> Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221546363
Server version: OceanBase 4.2.5.4 (r104000082025052817-2e9399047c72ee074510f39a687426e4c5649964) (Built May 28 2025 18:36:07)

```

## 适用版本

- OceanBase 数据库所有版本。
 - OBClient 所有版本。

Previous

[oceanbase jar 包和 oracle jar 包列长参数标准不同](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000270694)

Next

[SQL 执行出现 check_column_in_current_level_stmt get unexpected expr 异常](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000988446) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
