---
title: OceanBase 数据库 Oracle 模式如何实现 md5 函数-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于OceanBase 数据库 Oracle 模式如何实现 md5 函数相关的常见问题和使用技巧，帮助您快速解决OceanBase 数据库 Oracle 模式如何实现 md5 函数的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# OceanBase 数据库 Oracle 模式如何实现 md5 函数

更新时间：2026-05-19 08:21

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

本文介绍 OceanBase 数据库 Oracle 模式如何实现 md5 函数。

## 适用版本

OceanBase 数据库 V3.2.x、V4.x 版本

## 详细内容

OceanBase 数据库 V3.x 和 V4.x 兼容 `dbms_crypto` 但暂未兼容较早版本的 `dbms_obfuscation_toolkit`。

`dbms_obfuscation_toolkit` 是在 Oracle 8i 中引入的。

`dbms_crypto` 是 Oracle 10g 中引入的，旨在替换 `dbms_obfuscation_toolkit`。

与 `dbms_crypto` 相比，`dbms_obfuscation_toolkit` 功能有限，Oracle 官方建议使用 `dbms_crypto`。

OceanBase 数据库 Oracle 中实现 md5 方式如下。

**dbms_crypto**

```shell
obclient> SELECT rawtohex(dbms_crypto.hash(utl_raw.cast_to_raw('hello world'),2 /*dbms_crypto.HASH_MD5*/)) md5 FROM dual;
+----------------------------------+
| MD5                              |
+----------------------------------+
| 5EB63BBBE01EEED093CB22BB8F5ACDC3 |
+----------------------------------+
1 row in set (0.16 sec)

```

对比 Oracle 11g 中 md5 结果，两者一致。

```shell
SQL> SELECT rawtohex(dbms_crypto.hash(utl_raw.cast_to_raw('hello world'),2 /*dbms_crypto.HASH_MD5*/)) md5 FROM dual;

MD5
--------------------------------------------------------------------------------
5EB63BBBE01EEED093CB22BB8F5ACDC3

```

**dbms_obfuscation_toolkit (Oracle 官方已不推荐使用)**

```shell
SQL> SELECT utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string => 'hello world')) md5 FROM dual;

```

对比 MySQL 中 md5 结果，两者一致。

```shell
Server version: 5.7.32-log MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> select md5('hello world');
+----------------------------------+
| md5('hello world')               |
+----------------------------------+
| 5eb63bbbe01eeed093cb22bb8f5acdc3 |
+----------------------------------+
1 row in set (0.03 sec)

```

对比 OceanBase MySQL 中 md5 结果，两者一致。

```shell
Server version: 5.7.25 OceanBase 3.2.4.7 (r107000012023113010-30dacb758186c789832a51a3556e3408074b39d3) (Built Nov 30 2023 10:31:16)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

MySQL [oceanbase]> select md5('hello world');
+----------------------------------+
| md5('hello world')               |
+----------------------------------+
| 5eb63bbbe01eeed093cb22bb8f5acdc3 |
+----------------------------------+
1 row in set (0.00 sec)

```

**快速让 OceanBase 数据库支持 dbms_obfuscation_toolkit.md5**

```shell
## 创建包为 DBMS_OBFUSCATION_TOOLKIT
CREATE OR REPLACE PACKAGE DBMS_OBFUSCATION_TOOLKIT
    IS
        FUNCTION MD5(input_string VARCHAR2)
          RETURN varchar2;
    END DBMS_OBFUSCATION_TOOLKIT;
/

```

```shell
## 创建包体为 DBMS_OBFUSCATION_TOOLKIT
CREATE OR REPLACE PACKAGE BODY DBMS_OBFUSCATION_TOOLKIT
 IS
    FUNCTION MD5(input_string VARCHAR2)
        RETURN varchar2
        IS
    BEGIN
        RETURN UTL_RAW.CAST_TO_VARCHAR2(dbms_crypto.hash(utl_raw.cast_to_raw(input_string), 2));
    END MD5;
END DBMS_OBFUSCATION_TOOLKIT;
/

```

上一篇

[OceanBase 支持窗口函数吗？](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000001053)

下一篇

[group_concat 函数错误，错误代码 4016](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000000048) ![有帮助](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) 咨询热线
