Para obtener el rango de tablas utilizo un cursor.
Luego realizo un insert as select, sobre el registro obtenido del cursor.
El problema es que creo que tengo algo mal en la sentencia sql.
te paso el código:
Código:
Al ejecutar me sale el error:create or replace procedure update_potencia as CURSOR from_table IS SELECT table_name FROM user_tables WHERE table_name LIKE '%AVE'; v_from_table from_table%ROWTYPE; FROM_REC USER_TABLES.TABLE_NAME%TYPE; source_cursor INTEGER; ignore INTEGER; BEGIN OPEN from_table; LOOP FETCH from_table INTO FROM_REC; EXIT WHEN from_table%NOTFOUND; source_cursor := DBMS_SQL.OPEN_CURSOR ; DBMS_SQL.PARSE(source_cursor, 'INSERT INTO noa_ave_max_pot (Pointnumber, hora_max_rtc, valor_max_rtc, hora_noa, valor_noa, hora_max_noa, valor_max_noa ) (SELECT a.pointnumber pointnumber, a.utctimemax hora_max_rtc, valor_max_rtc a.value, b.utctime hora_ave, b.VALUE valor_ave, c.utctime hora_max_ave, c.VALUE value_max_ave FROM rtc_estaciones a, ' || v_from_table.table_name ||' b, ' || v_from_table.table_name ||' c WHERE A.value IN (SELECT MAX (VALUE) FROM rtc_estaciones ) AND C.VALUE IN (SELECT MAX (VALUE) FROM ' || v_from_table.table_name ||' WHERE utctime BETWEEN SYSDATE - 3 AND SYSDATE - 2) AND A.utctimemax BETWEEN SYSDATE - 3 AND SYSDATE - 2 AND B.utctime BETWEEN SYSDATE - 3 AND SYSDATE - 2 AND C.utctime BETWEEN SYSDATE - 3 AND SYSDATE - 2 AND a.utctimemax = b.utctime)',DBMS_SQL.NATIVE ); DBMS_OUTPUT.put_line ('Last Error: ' || DBMS_SQL.LAST_ERROR_POSITION ()); DBMS_OUTPUT.put_line (FROM_REC); ignore := DBMS_SQL.EXECUTE (source_cursor); DBMS_SQL.CLOSE_CURSOR (source_cursor); END LOOP; CLOSE from_table; END;
SQL> exec update_potencia;
BEGIN update_potencia; END;
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
ORA-06512: at "SYS.DBMS_SYS_SQL", line 909
ORA-06512: at "SYS.DBMS_SQL", line 39
ORA-06512: at "TEST.UPDATE_POTENCIA", line 22
ORA-06512: at line 1
Podrás darme un tip para resolver esto?, no puedo ver los paquetes de sys dele error, ya que estan wrappeados.
muchas gracias!