各位先進:
小弟在sql-plus中下以下語法OK,能得到正確資料,
select prd2001
,(select (code_name)
from code_map
where group_id = 'PUR24'
and code_id = prd2002)
,prd2022
,nvl((select sum(sto1105)
from sto11
where sto1102 = prd2001
and sto1103 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(decode(pos1114, 'N',pos1115, 'Y', -pos1115,0))
from pos11
where pos1103 = prd2001
and pos1104 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(sto1913)
from sto19
where sto1902 = prd2001
and sto1903 = prd2002
group by prd2001,prd2002),0)
,nvl((select min(sto1915)
from sto19,bas20
where sto1902 = prd2001
and sto1903 = prd2002
and sto1901 = bas2001
and bas2013 in ('1','2')),0)
,nvl((select sum(decode(sto1406,'H',sto1410,'L',sto1410,
'G',-sto1410,'I',-sto1410,'J',-sto1410,
'M',-sto1410,'K',-sto1410,'U',-sto1410,0))
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 in ('H','L','G','I','J','M','K','U')
group by prd2001,prd2002) ,0)
from prd20
where prd2005 between as_brand_beg and as_brand_end
and prd2006 between as_year_beg and as_year_end
and prd2007 between as_sea_beg and as_sea_end
and prd2008 between as_gtype_beg and as_gtype_end
and prd2015 between as_ptype_beg and as_ptype_end
and prd2009 between as_style_beg and as_style_end
and prd2001 between as_styno_beg and as_styno_end
order by prd2001,prd2002;將其寫入storeprocedure卻出現錯誤:
insert into temp_saar320
select prd2001
,(select (code_name)
from code_map
where group_id = 'PUR24'
and code_id = prd2002)
,prd2022
,nvl((select sum(sto1105)
from sto11
where sto1102 = prd2001
and sto1103 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(decode(pos1114, 'N',pos1115, 'Y', -pos1115,0))
from pos11
where pos1103 = prd2001
and pos1104 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(sto1913)
from sto19
where sto1902 = prd2001
and sto1903 = prd2002
group by prd2001,prd2002),0)
,nvl((select min(sto1915)
from sto19,bas20
where sto1902 = prd2001
and sto1903 = prd2002
and sto1901 = bas2001
and bas2013 in ('1','2')),0)
,nvl((select sum(decode(sto1406,'H',sto1410,'L',sto1410,
'G',-sto1410,'I',-sto1410,'J',-sto1410,
'M',-sto1410,'K',-sto1410,'U',-sto1410,0))
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 in ('H','L','G','I','J','M','K','U')
group by prd2001,prd2002) ,0)
from prd20
where prd2005 between as_brand_beg and as_brand_end
and prd2006 between as_year_beg and as_year_end
and prd2007 between as_sea_beg and as_sea_end
and prd2008 between as_gtype_beg and as_gtype_end
and prd2015 between as_ptype_beg and as_ptype_end
and prd2009 between as_style_beg and as_style_end
and prd2001 between as_styno_beg and as_styno_end
order by prd2001,prd2002;錯誤訊息如下:
[Error] PLS-00103 (11: 23): PLS-00103: 發現了符號 "SELECT" 當您等待下列事項之一發生時: ( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev點開後:
PLS-00103
string Cause: This error message is from the parser. It found a token (language element) that is inappropriate in this context.Action: Check previous tokens as well as the one given in the error message. The line and column numbers given in the error message refer to the end of the faulty language construct.請問為甚麼?
是在storeprocedure中不能使用多重select嗎?
小弟在sql-plus中下以下語法OK,能得到正確資料,
select prd2001
,(select (code_name)
from code_map
where group_id = 'PUR24'
and code_id = prd2002)
,prd2022
,nvl((select sum(sto1105)
from sto11
where sto1102 = prd2001
and sto1103 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(decode(pos1114, 'N',pos1115, 'Y', -pos1115,0))
from pos11
where pos1103 = prd2001
and pos1104 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(sto1913)
from sto19
where sto1902 = prd2001
and sto1903 = prd2002
group by prd2001,prd2002),0)
,nvl((select min(sto1915)
from sto19,bas20
where sto1902 = prd2001
and sto1903 = prd2002
and sto1901 = bas2001
and bas2013 in ('1','2')),0)
,nvl((select sum(decode(sto1406,'H',sto1410,'L',sto1410,
'G',-sto1410,'I',-sto1410,'J',-sto1410,
'M',-sto1410,'K',-sto1410,'U',-sto1410,0))
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 in ('H','L','G','I','J','M','K','U')
group by prd2001,prd2002) ,0)
from prd20
where prd2005 between as_brand_beg and as_brand_end
and prd2006 between as_year_beg and as_year_end
and prd2007 between as_sea_beg and as_sea_end
and prd2008 between as_gtype_beg and as_gtype_end
and prd2015 between as_ptype_beg and as_ptype_end
and prd2009 between as_style_beg and as_style_end
and prd2001 between as_styno_beg and as_styno_end
order by prd2001,prd2002;將其寫入storeprocedure卻出現錯誤:
insert into temp_saar320
select prd2001
,(select (code_name)
from code_map
where group_id = 'PUR24'
and code_id = prd2002)
,prd2022
,nvl((select sum(sto1105)
from sto11
where sto1102 = prd2001
and sto1103 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(decode(pos1114, 'N',pos1115, 'Y', -pos1115,0))
from pos11
where pos1103 = prd2001
and pos1104 = prd2002
group by prd2001,prd2002),0)
,nvl((select sum(sto1913)
from sto19
where sto1902 = prd2001
and sto1903 = prd2002
group by prd2001,prd2002),0)
,nvl((select min(sto1915)
from sto19,bas20
where sto1902 = prd2001
and sto1903 = prd2002
and sto1901 = bas2001
and bas2013 in ('1','2')),0)
,nvl((select sum(decode(sto1406,'H',sto1410,'L',sto1410,
'G',-sto1410,'I',-sto1410,'J',-sto1410,
'M',-sto1410,'K',-sto1410,'U',-sto1410,0))
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 in ('H','L','G','I','J','M','K','U')
group by prd2001,prd2002) ,0)
from prd20
where prd2005 between as_brand_beg and as_brand_end
and prd2006 between as_year_beg and as_year_end
and prd2007 between as_sea_beg and as_sea_end
and prd2008 between as_gtype_beg and as_gtype_end
and prd2015 between as_ptype_beg and as_ptype_end
and prd2009 between as_style_beg and as_style_end
and prd2001 between as_styno_beg and as_styno_end
order by prd2001,prd2002;錯誤訊息如下:
[Error] PLS-00103 (11: 23): PLS-00103: 發現了符號 "SELECT" 當您等待下列事項之一發生時: ( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev點開後:
PLS-00103
string Cause: This error message is from the parser. It found a token (language element) that is inappropriate in this context.Action: Check previous tokens as well as the one given in the error message. The line and column numbers given in the error message refer to the end of the faulty language construct.請問為甚麼?
是在storeprocedure中不能使用多重select嗎?
總是報錯在這個地方:
(select (code_name)
from code_map
where group_id = 'PUR24'
and code_id = prd2002)