Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is the datatype of your timestamp column? </p> <p>If you use <a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#i53219" rel="nofollow"><code>TIMESTAMP</code></a> with a large enough precision, the order should be preserved.</p> <p>For example <code>TIMESTAMP(6)</code> (precision to the micro-second) -- which is the default precision:</p> <pre><code>SQL&gt; CREATE TABLE t_data (ID NUMBER, d VARCHAR2(30)); Table created SQL&gt; CREATE TABLE t_log (ts TIMESTAMP (6), ID NUMBER, action VARCHAR2(1)); Table created SQL&gt; CREATE OR REPLACE TRIGGER trg 2 BEFORE INSERT ON t_data 3 FOR EACH ROW 4 BEGIN 5 INSERT INTO t_log VALUES (systimestamp, :NEW.id, 'I'); 6 END; 7 / Trigger created SQL&gt; INSERT INTO t_data (SELECT ROWNUM, 'x' FROM dual CONNECT BY LEVEL &lt;= 10); 10 rows inserted SQL&gt; SELECT * FROM t_log ORDER BY ts; TS ID ACTION ----------------------------- ---------- ------ 19/06/13 15:47:51,686192 1 I 19/06/13 15:47:51,686481 2 I 19/06/13 15:47:51,686595 3 I 19/06/13 15:47:51,686699 4 I 19/06/13 15:47:51,686800 5 I 19/06/13 15:47:51,686901 6 I ... </code></pre> <hr> <p>In any case, if you really want to distinguish simultaneous events (concurrent inserts for instance), you can always use a sequence in addition, with the <a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_6015.htm#SQLRF54342" rel="nofollow"><code>ORDER</code></a> keyword to guarantee that the rows will be ordered:</p> <pre><code>CREATE SEQUENCE log_sequence ORDER </code></pre> <p>This would allow you to have a reliable sort order, even though the events took place at the same time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload