在 PostgreSQL 中分配变量的语句中连接字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19419208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:09:21  来源:igfitidea点击:

Concatenate string in statement that assigns a variable in PostgreSQL

sqlpostgresql

提问by compyutech

I am trying to convert SQL Server procedure to PostgreSQL.

我正在尝试将 SQL Server 过程转换为 PostgreSQL。

In the SQL Server procedure There are statements like below

在 SQL Server 过程中有如下语句

SET @val = '(' + @someval + ')'

SET @val = '(' + @someval + ')'

So in postgresql I wrote as below

所以在postgresql中我写如下

SET val = '(' || someval || ')';

SET val = '(' || someval || ')';

But the above statement giving error at ||

但是上面的语句在 || 处给出了错误

Any body can please tell me where am I making mistake

任何机构都可以告诉我我哪里出错了

回答by Roman Pekar

AFAIK, SET statement in PostgreSQL used for changing configutation parameters, for variable assignment just use :=:

AFAIK,PostgreSQL 中的 SET 语句用于更改配置参数,变量赋值只需使用:=

val := '(' || someval || ')';

sql fiddle demo

sql fiddle demo