LEFT function in Oracle

There is no documented LEFT() function in Oracle. Find the full set here. Probably what you have is a user-defined function. You can check that easily enough by querying the data dictionary: But there is the question of why the stored procedure works and the query doesn’t. One possible solution is that the stored procedure is … Read more

How to create id with AUTO_INCREMENT on Oracle?

There is no such thing as “auto_increment” or “identity” columns in Oracle as of Oracle 11g. However, you can model it easily with a sequence and a trigger: Table definition: Trigger definition: UPDATE: IDENTITY column is now available on Oracle 12c: or specify starting and increment values, also preventing any insert into the identity column … Read more

DATEDIFF function in Oracle

In Oracle, you can simply subtract two dates and get the difference in days. Also note that unlike SQL Server or MySQL, in Oracle you cannot perform a select statement without a from clause. One way around this is to use the builtin dummy table, dual:

Oracle: If Table Exists

The best and most efficient way is to catch the “table not found” exception: this avoids the overhead of checking if the table exists twice; and doesn’t suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller: ADDENDUM For reference, … Read more

How do I use CREATE OR REPLACE?

This works on functions, procedures, packages, types, synonyms, trigger and views. Update: After updating the post for the third time, I’ll reformulate this: This does not work on tables 🙂 And yes, there is documentation on this syntax, and there are no REPLACE option for CREATE TABLE.

‘NOT LIKE’ in an SQL query

You have missed out the field name id in the second NOT LIKE. Try: The AND in the where clause joins 2 full condition expressions such as id NOT LIKE ‘1%’ and can’t be used to list multiple values that the id is ‘not like’.

Hibernate dialect for Oracle Database 11g?

Use the Oracle 10g dialect. Also Hibernate 3.3.2+ is required for recent JDBC drivers (the internal class structure changed – symptoms will be whining about an abstract class). Dialect of Oracle 11g is same as Oracle 10g (org.hibernate.dialect.Oracle10gDialect). Source: http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/session-configuration.html#configuration-optional-dialects