I Tischvergleichen i und i + 1 Element oracle
CREATE table table_x
(
id NUMBER, -- ID
NUMBER_history NUMBER, -- consecutive number
start_date date, -- start_date of next id=end_date of previous
end_date date -- should be >=start_date
);
INSERT INTO table_x VALUES (14 , 1, '13-NOV-92' ,'14-NOV-92');
INSERT INTO table_x VALUES (15 , 2, '14-NOV-92' ,'16-NOV-92');
INSERT INTO table_x VALUES (19 , 3, '16-NOV-92' ,'18-NOV-92');
INSERT INTO table_x VALUES (11 , 4, '18-NOV-92' ,'14-NOV-93');
INSERT INTO table_x VALUES (17 , 5, '15-NOV-93' ,'16-NOV-93');
INSERT INTO table_x VALUES (151 , 6, '16-NOV-93' ,'17-NOV-93');
INSERT INTO table_x VALUES (139 , 7, '17-NOV-93' ,'18-NOV-93');
INSERT INTO table_x VALUES (121 , 8, '19-NOV-93' ,'20-DEC-93');
INSERT INTO table_x VALUES (822 , 9, '20-DEC-93' ,'20-DEC-93');
ich Abfrage schreiben möchte, wo ich wo start_date der nächsten Zeile> end_date früherer finden. sie müssen gleich sein.
Ich versuche, etwas wie NUMBER_history als Zähler zu tun. C-Weg, wo I Zyklus durch variable organisieren i und vergleichen i und i + 1 (NUMBER_history und NUMBER_history + 1)
select * INTO row_tblx from table_x where NUMBER_history=NUMBER_history and end_date<(select start_date from table_x where NUMBER_history=NUMBER_history+1);
aber ich muß Schleife durch n_counter von 1 bis letzten NUMBER_history Wert organisieren und Daten in mehrere Zeilenabruf . Wie kann ich es tun?
Ich versuche
set serveroutput on
DECLARE
CURSOR cur IS
SELECT * FROM table_x;
TYPE row_tblx_type
IS
TABLE OF cur%ROWTYPE;
row_tblx row_tblx_type;
rowx cur%ROWTYPE;
nh_count NUMBER;
BEGIN
FOR NUMBER_history IN cur LOOP
select * INTO row_tblx from table_x where NUMBER_history=NUMBER_history and end_date<(select start_date from table_x where NUMBER_history=NUMBER_history+1);
DBMS_OUTPUT.PUT_LINE (row_tblx(NUMBER_history).id);
END LOOP;
END;
/
wie ich es für oder eine andere Schleife, mehrere Datensätze oder Tabelle von Aufzeichnungen, Cursor, einer Tabellenzeile als Zähler (NUMBER_history) unter Verwendung tun? Wie kann ich es ohne Cursor machen?
Normalerweise benötigt Ich versuche, schlechtes Englisch zu verstehen (nicht jeder ist ein englischer Sprecher). Allerdings kann so etwas nicht durch schlechtes Englisch entschuldigt werden: "wo Startdatum finden ...> Enddatum. ** Sie müssen gleich sein **." Ernsthaft, können Sie bitte überprüfen, was Sie schreiben, bevor Sie es veröffentlichen? Ich hörte auf, über diesen Punkt hinaus zu lesen. Du hast Glück, dass andere mehr vergeben, aber beim nächsten Mal bist du vielleicht nicht so glücklich. – mathguy