Many sources use the term timestamp to refer specifically to Unix time, the number of seconds since 00:00:00 UTC on
January 1, 1970. In Oracle you can compute this number very easily. For example, the following query computes the
number of seconds between 00:00:00 UTC on January 1, 1970 and October 9, 2007.
The result of the preceding query should be 1191888000.
How it works:
The subtraction between two dates returns the number of days between them. Multiplying this number by
60 * 60 * 24–the number of seconds in one day–you obtain the number of seconds between those dates.
Eclipse is a great IDE. When you hover your mouse over a class name or method of the Java SE API you get a contextual help for that class or method. However if you do the same thing over a Java EE class, such as HttpServletRequest you might not get the same effect. This is because there’s is no source or Javadoc attached to that class. To attach the documentation to your J2EE class as well you can follow these steps:
Right click on servlet-api.jar in your project.
Choose Properties from the menu.
In Javadoc location path put the URL where the Java EE documentation is located (e.g. http://java.sun.com/j2ee/1.4/docs/api/) or, alternatively, indicate the path where the Javadoc is located in your disk, such as file:/c:/path/to/your/documentation.
Many Java developers already know that Ant is a great build tool. Besides a build tool you also need a good version control system to manage the various versions of your code. For this purpose I often use Subversion. Now, there might be time when you need to exclude the Subversion hidden directories from, for example, a backup Ant target you built. To do that you just need to use the following attribute to your zipfileset or other directory-based task:
Sometimes you might need to commit a single INSERT, UPDATE or DELETE statement and not the whole main transaction.
In such a case you can use an AUTONOMOUS TRANSACTION which is a feature available since Oracle 8i.
The trick is to encapsulate the statement in a procedure and use the pragma AUTONOMOUS_TRANSACTION. Here is an example, suppose you have a table, your_table, which has just one column of type NUMBER and you want to insert the value 1, irrespective of the state of the main transaction:
CREATEORREPLACEPROCEDUREp_insertASPRAGMAAUTONOMOUS_TRANSACTION;BEGIN-- Main transaction suspends here.INSERTINTOyour_tableVALUES(1);-- Autonomous transaction begins here.COMMIT;-- Autonomous transaction ends here.END;-- Main transaction resumes here.
After calling this proc from another transaction (main transaction) your_table will have another row with 1 as the
value of its only column. If, after calling p_insert, you call ROLLBACK in your main transaction you will
have that the changes made within p_insert will be permanent. However the changes made in your main transaction will be rollbacked.
A tipical scenario where you need an autonomous transaction is a table used to log errors and/or other info.
For example if something goes wrong you might want to log the reason into a table before rollbacking the main transaction.
In such a case you would write a procedure using the pragma AUTONOMOUS_TRANSACTION and call this proc before rollbacking.
In Oracle you can execute hierarchical queries using some cool operators–CONNECT BY PRIOR, START WITH and
the pseudocolumn SYS_CONNECT_BY_PATH, namely. However, using your fantasy you can exploit these operators
to put in a single row–with each item separated by the next through a separator, such as a comma–what you have
in multiple rows. For example if you have more than one telephone number in different rows and you want to put them
in a single comma-separated row you could use a query similar to the following:
SELECTltrim(sys_connect_by_path(telephone,', '),', ')telFROM(SELECTtelephone,rownumnum_of_rowsFROM(-- Select the first 9 rows (1)SELECTds_numbertelephoneFROMtelephonestWHEREcd_customer=50ANDrownum<=9))xWHEREnum_of_rows=(-- Count the # of rows selected in (1)SELECTCOUNT(*)FROMtelephonestWHEREcd_customer=50ANDrownum<=9)STARTWITHnum_of_rows=1CONNECTBYPRIORx.num_of_rows=(x.num_of_rows-1);
The previuos query selects all the telephone numbers for the customer with cd_customer = 50 and put them in a
single comma-separated row.
When you create a table, by default, the number of bytes used to represent a character in a VARCHAR2 type is 1,
irrespective of the characterset of the DB. This may be fine if the characterset is such that it uses just one byte per
character. However, if the characterset of the DB is such that there might take more than one byte to represent a
character (for example for characterset = AL32UTF8) you might run into troubles, such as the error:
ORA-01401: inserted value too large for column. However you can specify, at creation time, that the size of
characters is expressed in CHARs instead of bytes. For example:
The previous code creates a table with just one column. The column will be able to contain 10 characters irrespective
of the number of bytes used to represent the characters internally.