故障分析 | OceanBase 一则函数报错问题分享
故障 问题 报错 函数 分析 分享 OceanBase 一则
2023-06-13 09:18:42 时间
今天遇到一个 OceanBase 数据库下 Oracle 租户的 PLSQL 分隔符问题,特来分享下。
我的初衷是对 Oracle 租户下的一张表造点随机数据,写好了 INSERT 语句,却提示没有函数 dbms_random.value 。于是查阅 OceanBase 官方文档,发现需要导入系统包 dbms_random !dbms_random 系统包存放在 OceanBase 安装目录下的 admin 子目录里,包含两个 SQL 文件,一个是包的声明 SQL:dbms_random.sql;另一个是包的定义 SQL:dbms_random_body.sql 。
我在 obclient 下导入这两个 SQL 文件,直接报语法错误。官方给的 SQL 文件怎么可能有语法错误呢?估计是我没有完全按照文档来规范操作而导致的问题。
最终我把报错的地方提取出来,整理成如下简单函数:
create or replace function tt return number is
v1 number;
v2 number;
begin
v1 := 10;
v2 := sqrt(-2 * ln(v1)/v1);
return v2;
end;
/
直接执行这个函数,也是报同样的错误。
<mysql:5.6.25:SYS> create or replace function tt return number is
-> v1 number;
-> v2 number;
-> begin
-> v1 := 10;
-> v2 := sqrt(-2 * ln(v1)/v1);
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'sqlrt(2 * ln(v1)' at line 6
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'v1)' at line 1
<mysql:5.6.25:SYS> return v2;
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'return v2' at line 1
<mysql:5.6.25:SYS> end;
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'end' at line 1
<mysql:5.6.25:SYS> /
-> ;
ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '/' at line 1
<mysql:5.6.25:SYS>
于是我把这个函数在我本地的 Oracle 环境中执行,一切正常:看来是 OceanBase 自身的环境问题。
create or replace function tt return number is
v1 number;
v2 number;
begin
v1 := 10;
v2 := sqrt(-2 * ln(v1)/v1);
return v2;
end;
2 3 4 5 6 7 8 9 /
Function created.
Elapsed: 00:00:00.02
YTT@helowin>
这个函数写的非常简单,求一个给定参数的平方根。刚开始我以为函数写的有问题,于是我把函数改为这样:
v2 := sqrt(-2 * ln(v1));
竟然顺利执行成功了。
<mysql:5.6.25:SYS> create or replace function tt return number is
-> v1 number;
-> v2 number;
-> begin
-> v1 := 10;
-> v2 := sqrt(-2 * ln(v1));
-> return v2;
-> end;
-> /
Query OK, 0 rows affected (0.050 sec)
直到最后经过和 Oracle 环境的对比,我才发现是 PLSQL 分隔符的问题。OceanBase 的 Oracle 租户里默认 PLSQL 的分隔符是/,刚好和除法/冲突,这样遇到除法符号就以为是函数定义结束,所以报语法错误。
那正确的写法应该是改变默认分隔符为//: 改分隔符后的函数创建成功。
<mysql:5.6.25:SYS>delimiter //
<mysql:5.6.25:SYS> create or replace function tt return number is
-> v1 number;
-> v2 number;
-> begin
-> v1 := 10;
-> v2 := sqrt(-2 * ln(v1)/v1);
-> return v2;
-> end;
-> //
Query OK, 0 rows affected (0.114 sec)
特此分享给使用 OceanBase 的同学。
相关文章
- 故障问题处理指南
- ORA-00981: cannot mix table and system auditing options ORACLE 报错 故障修复 远程处理
- ORA-01870: the intervals or datetimes are not mutually comparable ORACLE 报错 故障修复 远程处理
- ORA-30770: Cannot specify storage options for fixed size opaque type ORACLE 报错 故障修复 远程处理
- ORA-38868: warning: the control file may have incorrect data file structure ORACLE 报错 故障修复 远程处理
- ORA-48486: The file [string] exceeds the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-01595: error freeing extent (string) of rollback segment (string)) ORACLE 报错 故障修复 远程处理
- SQLServer 错误 1203 进程 ID %d 尝试对不归它所有的资源进行解锁: %.*ls。 请重试该事务,因为此错误可能是计时条件导致的。 如果该问题仍然存在,请与数据库管理员联系。 故障 处理 修复 支持远程
- SQLServer 错误 3181 还原此备份的尝试可能会遇到存储空间问题。 后续消息将提供详细信息。 故障 处理 修复 支持远程
- SQLServer 错误 8710 必须提供与 CUBE、ROLLUP 或 GROUPING SET 查询一起使用的聚合函数,才能合并子聚合。 若要修复此问题,请删除该聚合函数或在 GROUP BY 子句基础上使用 UNION ALL 编写查询。 故障 处理 修复 支持远程
- ORA-02452: invalid HASHKEYS option value ORACLE 报错 故障修复 远程处理
- ORA-13514: Metric Capture too close to last capture, group string ORACLE 报错 故障修复 远程处理
- ORA-16104: Invalid Logical Standby parameter ORACLE 报错 故障修复 远程处理
- ORA-19051: Cannot use fast path insert for this XMLType table ORACLE 报错 故障修复 远程处理
- Hadoop故障处理在高可用(HA)配置下,8088端口无法访问,resourcemanager进程无法启动问题详解大数据
- MySQL日志查询:轻松解决故障问题(mysqllog查询)
- 服务器问题检测MySQL服务器故障:一个准则(检测mysql)
- 问题解决Oracle XE连接故障的小技巧(oraclexe连接)
- 新版汽车“三包”规定明年起实施:电池故障等质量问题 7 日内可退换
- Linux排除异常问题,故障排除指南(linuxexcept)
- Oracle登录故障解决指南:如何解决无法登录Oracle的问题?(oracle登录不了)
- SQL Server故障排查:快速解决方案(sqlserver问题)
- 深入了解12514故障代码:掌握Oracle数据库的问题排查技巧(12514oracle)
- 排查redis群集故障解决节点深究问题(找到故障的redis节点)
- MySQL安装故障如何解决下载后无法安装问题(mysql下载后无法安装)
- MySQL下载卸载故障排除解决无法卸载MySQL的问题(mysql下载卸载不了了)
- IIS故障(Connections_Refused)问题分析及处理