Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Postgresql中动态创建临时表,并在FOR循环中选择相同的表。但是在管道符号附近获取错误_Postgresql_Plpgsql_Postgresql 9.3_Postgresql 9.4 - Fatal编程技术网

在Postgresql中动态创建临时表,并在FOR循环中选择相同的表。但是在管道符号附近获取错误

在Postgresql中动态创建临时表,并在FOR循环中选择相同的表。但是在管道符号附近获取错误,postgresql,plpgsql,postgresql-9.3,postgresql-9.4,Postgresql,Plpgsql,Postgresql 9.3,Postgresql 9.4,我无法理解为什么错误出现在管道符号处。请帮帮我。我也一直在尝试Oracle db,但同样的错误。我做错什么了吗 在中查询。。。循环语句也必须是动态的,所以应该使用execute两次 与执行一起使用非常方便的功能: do $xyz$ declare y text; i record; begin y := to_char(current_timestamp, 'YYYYMMDDHHMMSS'); raise notice '%',y; execute 'CREATE TEMP TABLE some

我无法理解为什么错误出现在管道符号处。请帮帮我。我也一直在尝试Oracle db,但同样的错误。我做错什么了吗

中查询。。。循环
语句也必须是动态的,所以应该使用
execute
两次

执行
一起使用非常方便的功能:

do
$xyz$
declare
y text;
i record;
begin
y := to_char(current_timestamp, 'YYYYMMDDHHMMSS');
raise notice '%',y;
execute 'CREATE TEMP TABLE someNewTable' 
  ||y
  ||' AS select * from ( VALUES(0::int,-99999::numeric), (1::int,       100::numeric)) as t (key, value)';

    for i in (select * from someNewTable||y) loop
     raise notice '%',i.key;
    end loop;
   end;
  $xyz$ language 'plpgsql'


 ERROR:  syntax error at or near "||"
LINE 13:    for i in (select * from someNewTable||y) loop

请发布Oracle代码以获取有关Oracle的帮助。如果问题只是关于Postgres的,请删除Oracle标签。谢谢Klin。半小时后我在这里发布了答案(format())。非常感谢您的努力。:)
do $xyz$
declare
    y text;
    i record;
begin
    y := to_char(current_timestamp, 'YYYYMMDDHHMMSS');
    raise notice '%', y;
    execute format($ex$
        create temp table somenewtable%s
        as select * from (
            values
                (0::int, -99999::numeric), 
                (1::int, 100::numeric)
            ) as t (key, value)
        $ex$, y);

    for i in 
        execute format($ex$
            select * from somenewtable%s
            $ex$, y)
    loop
        raise notice '%',i.key;
    end loop;
end;
$xyz$ language 'plpgsql';