要修改或更正SQL查询吗
运行此查询时:要修改或更正SQL查询吗,sql,oracle,Sql,Oracle,运行此查询时: select sm.stylename, (select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Name') as "VENDOR NAME", (select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = '
select sm.stylename,
(select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Name') as "VENDOR NAME",
(select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Number') as "VENDOR NUMBER",
(select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Address') as "VENDOR ADDRESS",
(select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Name') as "FACTORY NAME",
(select fieldvalue from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Address') as "FACTORY ADDRESS"
from stylemaster sm order by sm.stylename;
我收到错误消息:
"ORA-01427: single-row subquery returns more than one row
01427. 00000-"single-row subquery returns more than one row"
能否帮助解决此问题?您的一个子查询返回了多个值。您可以通过添加
其中rownum=1
或聚合函数来修复症状:
select sm.stylename,
(select max(fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Name') as "VENDOR NAME",
(select max(fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Number') as "VENDOR NUMBER",
(select max(fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Address') as "VENDOR ADDRESS",
(select max(fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Name') as "FACTORY NAME",
(select max(fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Address') as "FACTORY ADDRESS"
from stylemaster sm
order by sm.stylename;
这将解决问题,但您可能需要调查为什么会出现重复项
编辑:
如果max()
对您的数据类型无效,请使用rownum=1
:
select sm.stylename,
(select (fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Name' and rownum = 1) as "VENDOR NAME",
(select (fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Number' and rownum = 1) as "VENDOR NUMBER",
(select (fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Vendor Address' and rownum = 1) as "VENDOR ADDRESS",
(select (fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Name' and rownum = 1) as "FACTORY NAME",
(select (fieldvalue) from auxiliaryfield af where af.stylename = sm.stylename and fieldlabel = 'Factory Address' and rownum = 1) as "FACTORY ADDRESS"
from stylemaster sm
order by sm.stylename;
当我运行上述查询时,我收到错误消息“ORA-00932:不一致的数据类型:预期的-得到CLOB 00932.00000-“不一致的数据类型:预期的%s得到的%s”*原因:*操作:@omprakashv。将字段值存储为
CLOB
s似乎有些过分,通常是个坏主意。