请帮我做下优化  我不是做DBA的  对SQL不太明白
下面语句查询的时候造成了 01652 错误  又没办法修改临时表空间  请帮下忙 急
select a.formset_inst_id, a.ext1 as 编号, a.ext11 as 申请单位, a.ext7 as 申请人, 
to_char(a.ext27,'yyyy-mm-dd') as 申请日期, b.name as 姓名, b.username as 用户名, b.type as 类别, b.io as 入退  from mv_formset_inst a 
inner join
(
select a.formset_inst_id,a.name,b.username,c.type,d.io from 
(
select a.formset_inst_id,1 as aa, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='姓名1' 
union select a.formset_inst_id,2 as aa, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='姓名2' 
union select a.formset_inst_id,3 as aa, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='姓名3' 
union select a.formset_inst_id,4 as aa, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='姓名4' 
union select a.formset_inst_id,5 as aa, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='姓名5' 
) a
inner join 
(
select a.formset_inst_id,1 as bb, b.value as username from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='用户名1' 
union select a.formset_inst_id,2 as bb, b.value as username from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='用户名2' 
union select a.formset_inst_id,3 as bb, b.value as username from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='用户名3' 
union select a.formset_inst_id,4 as bb, b.value as username from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='用户名4' 
union select a.formset_inst_id,5 as bb, b.value as username from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='用户名5' 
) b on a.formset_inst_id=b.formset_inst_id and a.aa=b.bb
inner join 
(
select a.formset_inst_id,1 as cc, b.value as type from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='类别1' 
union select a.formset_inst_id,2 as cc, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='类别2' 
union select a.formset_inst_id,3 as cc, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='类别3' 
union select a.formset_inst_id,4 as cc, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='类别4' 
union select a.formset_inst_id,5 as cc, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='类别5' 
) c on a.formset_inst_id=c.formset_inst_id and a.aa=c.cc
inner join 
(
select a.formset_inst_id,1 as dd, b.value as io from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='入退1' 
union select a.formset_inst_id,2 as dd, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='入退2' 
union select a.formset_inst_id,3 as dd, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='入退3' 
union select a.formset_inst_id,4 as dd, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='入退4' 
union select a.formset_inst_id,5 as dd, b.value as name from mv_formset_inst a inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id and b.name='入退5' 
) d on a.formset_inst_id=d.formset_inst_id and a.aa=d.dd
) b on a.formset_inst_id=b.formset_inst_id
where a.formset_id=261 and b.name is not null

解决方案 »

  1.   

    select a.formset_inst_id, a.ext1 as 编号, a.ext11 as 申请单位, a.ext7 as 申请人, 
    to_char(a.ext27,'yyyy-mm-dd') as 申请日期, b.name as 姓名, b.username as 用户名, b.type as 类别, b.io as 入退  
    from mv_formset_inst a 
    inner join mv_form_data_inst b on a.formset_inst_id=b.formset_inst_id
    where (b.name like '姓名%' or b.name like '用户%' or b.name like '类别%' or b.name like '入退%')
    and right(b.name,1) between '1' and '5'
      

  2.   

    谢谢你啊   虽然不能直接COPY来用  但我根据你的提示 已经完成