2017-08-16 119 views
0

親愛的朋友們,我把這些語句存儲在一個表中,我需要執行它們來接收結果。如何執行PL/SQL表語句

DECODE (to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char(NRO_VIA) ||''|| to_char(NRO_PUERTA),'', 'No Disponible', to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char(NRO_VIA) ||' '|| to_char(NRO_PUERTA))',DECODE (to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char(NRO_VIA) ||''|| to_char(NRO_PUERTA),'', 'No Disponible', to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char(NRO_VIA) ||' '|| to_char(NRO_PUERTA)) FROM cliente WHERE NRO_CLIENTE='104631' 

DECODE (observaciones, NULL, 'No Disponible', '', 'No Disponible', observaciones)',DECODE (observaciones, NULL, 'No Disponible', '', 'No Disponible', observaciones) FROM cliente WHERE NRO_CLIENTE='104631' 

to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_DISTRITO))',to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_DISTRITO)) FROM cliente WHERE NRO_CLIENTE='104631' 

to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_PROVINCIA))',to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_PROVINCIA)) FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(correlativo)',to_char(correlativo) FROM cliente WHERE NRO_CLIENTE='104631' 

sed',sed FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(telefono)',to_char(telefono) FROM s_v_cliente WHERE NRO_CLIENTE='104631' 

to_char(numero_medidor)',to_char(numero_medidor) FROM tps.s_v_medid, cliente c WHERE NRO_CLIENTE='104631' 

to_char(d.Consumo)',to_char(d.Consumo) FROM cliente c,(SELECT Id_Cuenta, Consumo FROM (SELECT a.Id_Cuenta, b.ENERGIA_FP Consumo FROM s_NUC_SERVICIO a, s_his_consumo b WHERE UPPER(a.tipo_Servicio) = 'ELECTRICO' AND a.id_servicio=b.id_servicio AND a.Id_Cuenta= %ID_ELEMENTO% ORDER BY fecha_lectura DESC) WHERE ROWNUM <=1) d WHERE NRO_CLIENTE='104631' 

to_char(d.Potencia)',to_char(d.Potencia) FROM cliente c,(SELECT Id_Cuenta, Potencia FROM (SELECT a.Id_Cuenta, (SELECT potencia_cont_fp FROM s_v_cliente WHERE numero_cliente = a.Id_Cuenta) Potencia FROM s_NUC_SERVICIO a, s_his_consumo b WHERE UPPER(a.tipo_Servicio) = 'ELECTRICO' AND a.id_servicio = b.id_servicio AND a.Id_Cuenta = %ID_ELEMENTO% ORDER BY fecha_lectura DESC) WHERE ROWNUM <=1) d WHERE NRO_CLIENTE='104631' 

fase',fase FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(NRO_CLIENTE)',to_char(NRO_CLIENTE) FROM cliente WHERE NRO_CLIENTE='104631' 

nombre',nombre FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(pcr)',to_char(pcr) FROM cliente WHERE NRO_CLIENTE='104631' 

TO_CHAR(DECODE(TIPO,1,'NORMAL',2,'MAXIMETRO',4,'PIMT',7,'HH.UU. Y PP.JJ',8,'ALUMBRADO PUBLICO','No Disponible'))',TO_CHAR(DECODE(TIPO,1,'NORMAL',2,'MAXIMETRO',4,'PIMT',7,'HH.UU. Y PP.JJ',8,'ALUMBRADO PUBLICO','No Disponible')) FROM cliente WHERE NRO_CLIENTE='104631' 

TO_CHAR(DECODE(estado,0,'ACTIVO',1,'ELIMINADO',2,'RETIRADO',3,'NUEVO',4,'PROCESO DE RETIRO','No Disponible'))',TO_CHAR(DECODE(estado,0,'ACTIVO',1,'ELIMINADO',2,'RETIRADO',3,'NUEVO',4,'PROCESO DE RETIRO','No Disponible')) FROM cliente WHERE NRO_CLIENTE='104631' 

cadena',cadena FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(sector)',to_char(sector) FROM cliente WHERE NRO_CLIENTE='104631' 

to_char(zona)',to_char(zona) FROM cliente WHERE NRO_CLIENTE='104631' 
+0

歡迎來到Stack Overflow,@miMescua。要獲得最佳答案,您將有助於編輯您的問題以提供更多信息。具體而言,您希望得到的結果,輸入數據的樣本,以及您當前的嘗試未正確執行的方式。請查看:https://stackoverflow.com/help/how-to-ask – Degan

回答

0

如果,因爲它的出現,這些都是(在開始減關鍵字select,並在許多語法錯誤)返回1行2列的所有SELECT語句,那麼你可以這樣做:

declare 
    l_sql long; 
    l_col1 long; 
    l_col2 long; 
begin 
    for r_sql in (select statement from my_table) loop 
    dbms_output.put_line('Statement: '||r_sql.statement); 
    l_sql := 'select '||r_sql.statement; 
    begin 
     execute immediate l_sql into l_col1, l_col2; 
     dbms_output.put_line('returned: '||l_col1||','||l_col2); 
    exception 
     when no_data_found then 
     -- take appropriate action 
     when too_many_rows then ... 
     -- take appropriate action 
    end; 
    end loop; 
end; 

但是,只有當數據中的語法錯誤得到修復時,它纔會起作用 - 例如

to_char(NRO_CLIENTE)',to_char(NRO_CLIENTE) FROM cliente WHERE NRO_CLIENTE='104631' 

...有to_char(NRO_CLIENTE)後一個假「,這將導致語句失敗運行時。