Fault analysis | OceanBase a function error report problem sharing

Author: Yang Taotao

Senior database expert, specializing in MySQL for more than ten years. Good at MySQL, PostgreSQL, MongoDB and other open source database-related backup and recovery, SQL tuning, monitoring operation and maintenance, high-availability architecture design, etc. Currently working in Acson, providing MySQL-related technical support and MySQL-related course training for major operators and banking and financial companies.

Source of this article: original contribution

*Produced by the Aikesheng open source community, the original content is not allowed to be used without authorization, please contact the editor and indicate the source for reprinting.


Today, I encountered a problem with the PLSQL delimiter of Oracle tenants under the OceanBase database, so I would like to share it.

My original intention was to create some random data for a table under the Oracle tenant, and after writing the INSERT statement, it was prompted that there was no function dbms_random.value. So I checked the official documentation of OceanBase and found that the system package dbms_random needs to be imported! The dbms_random system package is stored in the admin subdirectory under the OceanBase installation directory, and contains two SQL files, one is the statement SQL of the package: dbms_random.sql; the other is the definition SQL of the package: dbms_random_body.sql.

I imported these two SQL files under obclient and reported a syntax error directly. How could the official SQL file have grammatical errors? It is estimated that I did not fully follow the document to standardize the operation caused by the problem.

In the end, I extracted the place where the error was reported and organized it into a simple function as follows:

 create or replace function tt return number is
 v1 number;
 v2 number;
 begin
   v1 := 10;
   v2 := sqrt(-2 * ln(v1)/v1);
   return v2;
 end;
 /

Executing this function directly also reports the same error.

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

So I executed this function in my local Oracle environment, and everything is normal: it seems to be an environmental problem of OceanBase itself.

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> 

This function is very simple to write, and finds the square root of a given parameter. At first I thought there was something wrong with the function, so I changed the function to this:

v2 := sqrt(-2 * ln(v1));

It was executed successfully.

<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)

It wasn't until the final comparison with the Oracle environment that I found out that it was a problem with the PLSQL delimiter. The default PLSQL delimiter in OceanBase's Oracle tenant is /, which happens to conflict with the division /, so when encountering the division symbol, it is considered the end of the function definition, so a syntax error is reported.

The correct way to write it should be to change the default delimiter to //: The function after changing the delimiter is created successfully.

<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)

Hereby share it with students who use OceanBase.

Guess you like

Origin blog.csdn.net/ActionTech/article/details/130222078