Jak wyświetlić liczby od 1 do 10 w SQL?

0

Dlaczego mi wyskakuje błąd?

 
set serveroutput on
BEGIN
 FOR i in 1..10 LOOP 
    IF i=6 or i=8 THEN null;
    ELSE 
    INSERT INTO messages (results)
    VALUES (i);
  END IF;
  END LOOP;
  COMMIT;
END;

błąd

 
Error starting at line : 2 in command -
BEGIN
 FOR i in 1..10 LOOP 
    IF i=6 or i=8 THEN null;
    ELSE 
    INSERT INTO messages (results)
    VALUES (i);
  END IF;
  END LOOP;
  COMMIT;
END;
Error report -
ORA-06550: linia 5, kolumna 17:
PL/SQL: ORA-00942: tabela lub perspektywa nie istnieje
ORA-06550: linia 5, kolumna 5:
PL/SQL: SQL Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
1

Bo bez sensu insertujesz wartość do tabeli, której w ogóle nie ma:

FOR i IN 1..3 LOOP
    DBMS_OUTPUT.PUT_LINE (i);
END LOOP;

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/controlstatements.htm#BABEFFDC

0

Wyświetlić czy wpisać do bazy?

0

dokładnie to mam takie zadanie
Execute the command in the 6.sql file to create the messages table. Write a PL/SQL block to inseń numbers into the messages table.

a) lnsert the numbers 1 through 10, excluding 6 and 8.
b) commit before the end of the block.
c) Execute a SELECT statement to verify that your PL/SQL block worked.

0
BEGIN
  INSERT INTO messages (results) VALUES (1),(2),(3),(4),(5),(7),(9),(10);
  COMMIT;
END;
0

Właśnie, że nie musiałem robić wcześniej żadnej tabeli "messages". A jakby to zrobić na tymczasowej tabeli? Wystarczy wtedy tylko kolumna na liczby

0

dlaczego nie wyświetla mi wyników?

 
create global temporary table messages(
results integer
);

set serveroutput on
BEGIN
 FOR i IN 1..10 
 LOOP 
    IF i=6 or i=8 THEN 
      null;
    ELSE 
      INSERT INTO messages (results) 
      VALUES (i);
    END IF;  
    COMMIT;
  END LOOP;
END;

PL/SQL procedure successfully completed.
0

Ponieważ zapomniałeś o:

c) Execute a SELECT statement to verify that your PL/SQL block worked.

0

no właśnie nie wyświetla się nic w tabeli.
select * from messages;

1 użytkowników online, w tym zalogowanych: 0, gości: 1