尝试声明一个 table 类型的变量,并在 PostgreSQL 中打印它的值

Trying to declare a variable of a table type, and print its value in PostgreSQL

下面是我用过的语法。

 declare
      v_data emp_tab ;
    BEGIN
      select * into v_data from emp_tab where emp_id= 121 limit 1;
      raise notice 'Value: %', v_data.emp_info;
    END;

这是一个错误。 "syntax error at or near emp_tab" 请帮忙。

试试这个:

do $$
    declare
    v_data emp_tab ;
    BEGIN
        select * into v_data from emp_tab where emp_id= 121 limit 1;
        raise notice 'Value: %', v_data.emp_info;
    END;
$$ language plpgsql