Equivalence of the Firebird GEN_ID () function in ORACLE

1

Speak, I'm learning BD Oracle, before I used firebird. But I'm having a problem that I can not solve. I can not add a new country through the system (java), if I enter it through SQLDeveloper, it appears in the query. The error that appears when I try to include it is as follows:

java.sql.SQLException: ORA-00942: a tabela ou view não existe

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
    at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:852)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
    at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1477)
    at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:392)
    at bd.Conexao.pegaGenerator(Conexao.java:50)


(...)

The line that the error tells me is:

public static Integer pegaGenerator(String generator) 
    {
        try 
        {
            Statement st = Conexao.getConexao().createStatement();
            ResultSet rs = st.executeQuery("SELECT GEN_ID(" + generator + ", 1) FROM RDB$DATABASE");
            rs.next();
            return rs.getInt(1);
        } 

        catch (Exception e) 
        {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Não foi possível obter o generator!");
            return null;
        } 
    }   

The table in Oracle I created this way:

CREATE TABLE Pais
(
ID_Pais INTEGER NOT NULL,
Nome_Pais VARCHAR(60) NOT NULL,
Sigla_Pais VARCHAR(3) NOT NULL,
Status_Pais CHAR(1) NOT NULL,
CONSTRAINT ID_Pais PRIMARY KEY (ID_Pais) 
);

and by the tool I made the trigger

    
asked by anonymous 07.03.2017 / 17:55

1 answer

3

In Firebird there are generators . Already in Oracle there are the sequences .

To create it you should do:

create sequence seq_tabela_exemplo;

You can even set various settings:

create sequence seq_tabela_exemplo
   start with 5
   increment by -1
   maxvalue 5
   minvalue 0
   nocache
   cycle;

To get the next value, run:

select seq_tabela_exemplo.nextval from dual;

For more details, see documentation .

    
07.03.2017 / 18:34