From 4dfa07349ce67e4a8f4832251204c769c7e7d010 Mon Sep 17 00:00:00 2001 From: Gilles Darold Date: Thu, 1 Apr 2021 22:03:57 +0200 Subject: [PATCH] Extract custom type from a DECLARE section of a procedure to create it as user defined type. Thanks to naveenjul29 for the report. --- lib/Ora2Pg.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Ora2Pg.pm b/lib/Ora2Pg.pm index af9203fe..6a59f31d 100644 --- a/lib/Ora2Pg.pm +++ b/lib/Ora2Pg.pm @@ -14347,6 +14347,13 @@ sub _convert_function $func_return = " AS \$body\$\n"; } + # extract custom type declared in a stored procedure + my $create_type = ''; + while ($fct_detail{declare} =~ s/\s+TYPE\s+([^\s]+)\s+IS\s+RECORD\s*\(([^;]+)\)\s*;//is) + { + $create_type .= "CREATE TYPE $1 AS ($2);\n"; + } + my @at_ret_param = (); my @at_ret_type = (); my $at_suffix = ''; @@ -14392,7 +14399,7 @@ sub _convert_function my $type = $fct_detail{type}; $type = 'FUNCTION' if (!$self->{pg_supports_procedure}); - my $function = "\n${fct_warning}CREATE$self->{create_or_replace} $type $fname$at_suffix $fct_detail{args}"; + my $function = "\n$create_type\n\n${fct_warning}CREATE$self->{create_or_replace} $type $fname$at_suffix $fct_detail{args}"; if (!$pname || !$self->{package_as_schema}) { if ($self->{export_schema} && !$self->{schema})