我在 Oracle 中有复杂的 Select 语句,带有 Case When 条件,并且它们选择所有连接值。 所以类似这样的东西:
END
END
FROM something
...
我需要的是将其他表中的其他值而不是“我的值”连接起来。 所以我会:而不是(我的值(value)):
(Select textValue from textView A where A.textID = '395')
如果我单独运行这个语句,它会取出一个我想要的精确值。但是,如果我将它而不是(我的值)放入连接中,则会出现错误:ora-00936 缺少表达式 (是的,“395”是另一个表中的字符串)
请问有什么想法吗?
最佳答案
您可以在 Oracle 的 case 子句中使用内联 View 。这不是你想做的吗? “缺少表达式”错误可能是缺少括号或一些类似的代码错误。
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') || '
关于sql - Concatenate 中的 Select 语句 (Oracle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26845819/