为 MariaDB 过程创建自定义类型

Creating a custom type for MariaDB procedure

在 PL/SQL 世界中,我会使用 type field_name is table of number index by VARCHAR2; 创建一个自定义类型,然后像这样使用新类型 v_source_count source_code_ar;

MariaDB 的 documentation 状态 types 可以是任何 MariaDB 类型。不过,它并没有说明任何关于自定义类型的内容。有没有办法实现与上述 PL/SQL 相同的结果,这对 MariaDB 有效?

MariaDB 中没有 "custom" 数据类型(或 MySQL)。

您确实不能在 MariaDB 中创建自定义类型,但是如果您需要模拟该功能,您可以在内存中创建临时 table。请注意,创建临时 table 必须在任何 DECLARE 语句之后。

CREATE TEMPORARY TABLE my_tmp_table (
    <fieldName> <datatype>,
    ...
) ENGINE = MEMORY;

ENGINE = Memory 位可确保 table 仅在内存中创建,因此不会产生不利的副作用。