如何在 PostgreSQL 中创建 TYPE?
How to create TYPE in PostgreSQL?
如何在 plpgsql 中创建数据类型?我是 PostgreSQL 的新手,我正在将 oracle 过程转换为 postgresql 函数。他们在 oracle 中创建了一个类似这样的类型:
TYPE t_array IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
然后在如下过程中声明并使用它:
strings t_array;
strings(1) := lv_str;
我想在 plpgsql 中创建 t_array type
并在函数中使用它,我如何创建这种类型或者是否有任何内置类型可以在 plpgsql 中实现此功能?
您不需要为 PL/pgSQL 中的那个创建类型,只需声明一个 array 变量:
declare
l_strings text[];
begin
l_string[1] := 'This is the first string';
l_string[2] := 'This is the second string';
end;
数组也可以用作参数:
create function do_something(p_some_number integer, p_strings text[])
returns ..
as
...
使用do_something(42, array['one', 'two'])
调用
如何在 plpgsql 中创建数据类型?我是 PostgreSQL 的新手,我正在将 oracle 过程转换为 postgresql 函数。他们在 oracle 中创建了一个类似这样的类型:
TYPE t_array IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
然后在如下过程中声明并使用它:
strings t_array;
strings(1) := lv_str;
我想在 plpgsql 中创建 t_array type
并在函数中使用它,我如何创建这种类型或者是否有任何内置类型可以在 plpgsql 中实现此功能?
您不需要为 PL/pgSQL 中的那个创建类型,只需声明一个 array 变量:
declare
l_strings text[];
begin
l_string[1] := 'This is the first string';
l_string[2] := 'This is the second string';
end;
数组也可以用作参数:
create function do_something(p_some_number integer, p_strings text[])
returns ..
as
...
使用do_something(42, array['one', 'two'])