· 8 years ago · Jun 29, 2018, 03:22 AM
1create trigger mytable_trg
2before insert on mytable
3for each row
4when (new.id is null)
5begin
6 select myseq.nextval into :new.id from dual;
7end;
8
9insert into mytable (id, data) values (myseq.nextval, 'x');
10
11mytable_pkg.insert_row (p_data => 'x');
12
13CREATE TABLE xxx ( ID RAW(16) DEFAULT SYS_GUID() )
14
15create sequence seq;
16
17insert into table (id, other1, other2)
18values (seq.nextval, 'hello', 'world');
19
20Statement stmt = null;
21ResultSet rs = null;
22
23stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
24 java.sql.ResultSet.CONCUR_UPDATABLE);
25
26stmt.executeUpdate("DROP TABLE IF EXISTS autoIncTable");
27
28stmt.executeUpdate("CREATE TABLE autoIncTable ("
29 + "priKey INT NOT NULL AUTO_INCREMENT, "
30 + "dataField VARCHAR(64), PRIMARY KEY (priKey))");
31
32stmt.executeUpdate("INSERT INTO autoIncTable (dataField) "
33 + "values ('data field value')",
34 Statement.RETURN_GENERATED_KEYS);
35
36int autoIncKeyFromApi = -1;
37
38rs = stmt.getGeneratedKeys();
39
40if (rs.next()) {
41 autoIncKeyFromApi = rs.getInt(1);
42}
43else {
44 // do stuff here
45}
46
47rs.close();