Archive | Oracle RSS feed for this section

Oracle date handling and ColdFusion on INSERT TO

To issue a “INSERT TO” with a “SELECT” statement is a common practice to copy records from one table to another. A statement like this might look like;

[code]

<cfquery datasource="mydb">

INSERT INTO mytable

(id, somefield)

SELECT '1', thefield

FROM demo

WHERE id = 1

</cfquery>

[/code]

No big deal. Al right, now many times one also adds the current date to the table. Now as ColdFusion developers you might me inclined to write this code;

[code]

<cfquery datasource="mydb">

INSERT INTO mytable

(id, somefield, thedate)

SELECT '1', thefield, '#now()#'

FROM demo

WHERE id = 1

</cfquery>

[/code]

But what a surprise the code above will not work since Oracle is not able to interpret the “#now()#’ field (yes, we are on a CFM page, but it still does not work).Simple solution is to use the Oracle timestamp with;

[code]

<cfquery datasource="mydb">

INSERT INTO mytable

(id, somefield, thedate)

SELECT '1', thefield, systimestamp

FROM demo

WHERE id = 1

</cfquery>

[/code]

The “systimestamp” will insert the current date and time for you.

Comments { 48 }

Installing a Oracle database is so difficult

I mean we all know how hard and difficult it is to install the Oracle database, right? I mean there is no way that you could install the Oracle database with only using your nose, right?

False.

Comments { 42 }

The Oracle Database Order by syntax is case sensitive

We just came across a issue that took one of our developers a longer time to figure out and is regarding the "order by" syntax in use with a Oracle Database 10g R2.

When using a:

SELECT myname FROM mydb ORDER BY myname

and you have different cases in the "myname" field (Example: Oracle, oranges, adventure, Business) then the above query would give you a result that would look like this:

Business

Oracle
adventure
oranges

As you can see the word "adventure" is at the "end" of all the values that are writing in upper case. The reason for this is because as by default the Oracle Database is case sensitive.

To get the correct order you will have to wrap the "Order By" with the lower() function, like:

SELECT myname FROM mydb ORDER BY lower(myname)

 

Comments { 23 }

Oracle Database 11g for Linux available

Start your update engine and head over to Oracle. Oracle Database 11g for Linux is available for download. As always, other platforms will follow soon.

Comments { 2 }