Ich versuchte unter Code, um die 1000 Zeilen abzurufen und Schleife um 100 Zeilen gleichzeitig zu löschen.PLSQL Loop Through 100 Zeile zu einem Zeitpunkt zu löschen
DECLARE
COUNTER INTEGER :=0;
v_delstr varchar2(2000);
v_countstr varchar2(2000);
SchemaName Varchar2(40):='Staging';
TableName Varchar2(100):='History';
BEGIN
LOOP
COUNTER := COUNTER + 1;
DBMS_OUTPUT.PUT_LINE('Counter: ');
v_delstr:= 'Delete FROM ' ||SchemaName ||'.'||TableName|| ' where rownum <= 1000 And startdate>=sysdate-731 and startdate<=sysdate-730';
execute immediate v_delstr;
dbms_output.put_line(v_delstr);
v_countstr:= 'BEGIN
DECLARE CANT INTEGER;
SELECT COUNT(*) INTO CANT FROM ' ||SchemaName ||'.'||TableName|| ' where rownum <= 1000 And startdate>=sysdate-731 and startdate<=sysdate-730;
EXIT WHEN CANT <= 100;
COMMIT;
END;';
execute immediate v_countstr;
dbms_output.put_line(v_countstr);
--dbms_output.put_line(v_delstr);
--dbms_output.put_line(v_countstr);
END LOOP;
END;
DECLARE
COUNTER INTEGER :=0;
v_delstr varchar2(2000);
v_countstr varchar2(2000);
SchemaName Varchar2(40):='Staging';
TableName Varchar2(100):='History';
BEGIN
LOOP
COUNTER := COUNTER + 1;
DBMS_OUTPUT.PUT_LINE('Counter: ');
v_delstr:= 'Delete FROM ' ||SchemaName ||'.'||TableName|| ' where rownum <= 10 And startdate>=sysdate-731 and startdate<=sysdate-730';
execute immediate v_delstr;
dbms_output.put_line(v_delstr);
v_countstr:= 'BEGIN
DECLARE CANT INTEGER;
SELECT COUNT(*) INTO CANT FROM ' ||SchemaName ||'.'||TableName|| ' where rownum <= 10 And startdate>=sysdate-731 and startdate<=sysdate-730;
EXIT WHEN CANT <= 1;
COMMIT;
END;';
execute immediate v_countstr;
dbms_output.put_line(v_countstr);
--dbms_output.put_line(v_delstr);
--dbms_output.put_line(v_countstr);
END LOOP;
END;
Got Fehler
Error report -
ORA-06550: line 3, column 23:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
The symbol "begin" was substituted for "SELECT" to continue.
ORA-06550: line 6, column 18:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
(begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
ORA-06512: at line 22
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Warum brauchen Sie hier eine Schleife? Sie löschen eine einzelne Tabelle richtig? –
ist das eine Endlosschleife? –
Sie müssen die hier verwendete Logik überprüfen https://stackoverflow.com/questions/47017028/how-to-select-200-record-for-e-ach-loop-iteration-in-oracle/47018055#47018055 – XING