Postgresql 尝试在sql中声明变量并使用if else语句时出现语法错误。-“VARCHAR”处或附近出现语法错误

Postgresql 尝试在sql中声明变量并使用if else语句时出现语法错误。-“VARCHAR”处或附近出现语法错误,postgresql,if-statement,variables,Postgresql,If Statement,Variables,下面的代码显示了数据类型Varchar附近的错误以及if语句附近的错误—Varchar处或附近的语法错误 我已尝试检查区分大小写和赋值 Declare Userstate VARCHAR := 'Active' ; begin if u.disabled_at is null then Userstate = 'Inactive'; else Userstate = 'Active'; end if end 我必须声明一个变量并在if-else语句中使用它。其中u.disabled_at是表用

下面的代码显示了数据类型Varchar附近的错误以及if语句附近的错误—Varchar处或附近的语法错误

我已尝试检查区分大小写和赋值

Declare
Userstate VARCHAR := 'Active' ;
begin
if u.disabled_at is null
then
Userstate = 'Inactive';
else
Userstate = 'Active';
end if
end
我必须声明一个变量并在if-else语句中使用它。其中u.disabled_at是表用户中的一列。
接下来,我将尝试连接我的表,以在select语句中获得输出,并从if else语句中获取变量。

这里根本不需要任何plsql,不需要变量声明和赋值。在查询中,只需使用:


这需要更多的背景。你从哪里来?发布一个.u-users表,并在表中禁用_at-列。您需要一个块来完成此操作
select o.id as Organisationid,o.name as OrganisationName, orl.user_id as "UserID", u.username as "UserName" ,
Userstate as "Active/Inactive" ,orl.role as "UserType"
from org_user_roles orl
Full outer join orgs o on
o.id = orl.org_id 
Full outer join users u on
orl.user_id  = u.id
select
  o.id as "OrganisationID",
  o.name as "OrganisationName",
  u.id as "UserID",
  u.username as "UserName",
  (case when u.disabled_at is null
    then 'Inactive'
    else 'Active'
  end) as "Active/Inactive",
  orl.role as "UserType"
from
  org_user_roles orl
  full outer join orgs o on o.id = orl.org_id 
  full outer join users u on orl.user_id = u.id