在Concatenate(Oracle)中选择语句

时间:2014-11-10 14:15:08

标签: sql oracle concatenation

我在Oracle中有复杂的Select语句,使用Case When条件并选择所有Concatenate值。 所以类似的东西:

END
END
FROM something
...

我需要的是在连接中将其他值中的其他值替换为My Value。 所以我不会(我的价值):

(Select textValue from textView A where A.textID = '395')

如果我单独运行此声明,它将取出我想要的一个确切值。但是,如果我把它代替(我的值)连接到它,它会给我错误:ora-00936缺少表达式 (是' 395'是另一个表中的字符串)

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您可以在Oracle的case子句中使用内联视图。这不是你想要做的吗? “缺少表达式”错误可能是缺少括号或类似的代码错误。

select case object_type
          when 'TABLE' then
             'select * from ' || object_name
          when 'SYNONYM' then
             'describe ' || object_name
          when 'PACKAGE' then
             (select to_char (count (*))
                from user_source s
               where s.type = o.object_type and s.name = o.object_name)
          else
             (select object_type from dual)
       end
          as objects
  from user_objects o

或者只是创建一个返回的函数,为您执行此操作并调用它。

create function gettextval (p_textid in varchar2)
    return varchar2 is
    l_returnval   varchar2 (32767);
begin
    select text_val
      into l_returnval
      from v_texts s
     where s.text_id = p_textid;

    return l_returnval;
exception
    when no_data_found then
        return p_textid;
end;

在这个例子中,我让它返回找不到任何内容的输入字符串。

然后您可以在之前的选择中引用该功能。

' || gettextval('395') || '

答案 1 :(得分:0)

你可以用"选择文字"在里面?

当用例 - >当我喜欢的时候:

SELECT
  CASE A.LIST_TYPE_CD
    WHEN '1' THEN '<A HREF="censured?thresholdId=censured' || GET_SITE_SUFFIX() || chr(38) || 'task=runSQL' || chr(38) || 'parseParams=true' || chr(38) || 'list_id=' ||  A.LIST_ID || chr(38) || 'list_name=' || A.LIST_NAME ||
'">' || (Select textValue from textView A where A.textID = '395') || '</A>'
    WHEN '3' THEN '<A HREF=censured' || GET_SITE_SUFFIX() || chr(38) || 'task=runSQL' || chr(38) || 'parseParams=true' || chr(38) || 'list_id=' || A.LIST_ID ||
    '">' || (Select textValue from textView B where B.textID = '395') || '</A>'
END
FROM something A