Entries Tagged as 'sql'

Saturday, January 16th, 2010

Oracle Delete Taking a Long Time

It may look like your delete statement is hung, but ff your table has foreign keys in another table without indexes on that column Oracle will full table scan that other table for every row that you’re deleting. Hopefully this saves someone some time. Bookmark to:

Tuesday, October 6th, 2009

Luhn Digit Generation Oracle PL/SQL Implementation

Here's how to generate a Luhn Mod-10 Check Digit. It's implemented as a function in oracle PL/SQL. I spent 2 hours looking for this online, then decided to implement it myself since it's not that hard. Anyway, I thought I'd post it here for the next person trolling google for it. This is useful for [...]

Wednesday, January 2nd, 2008

Postgres select replace with regular expression

Postgres seriously kicks ass, here's a quick way to do a substring based on a regular expression. A Co-worker wanted to get the first word out of a column that contained a sentence. If we were using something lame like oracle we'd have to do gymnastics to do that. It's a one-liner in postgres. SELECT [...]

Wednesday, June 20th, 2007

Randomizing Query Results in Oracle

I was doing some work this afternoon, and I needed some sample id's from a database query, however all the data ended up being related to the same person because of the ordering of the results. There must be a better way, i want random results in my resultset. Here's how (in oracle), order by [...]

Friday, March 16th, 2007

Accessing main query aliases from subquery

I am stupid, I never fully understood Oracle Subqueries. Let me give you an example, I had a really big view where I wanted to access stats of child tables based on a parent table. For example, let's call that table checks, I wanted to know how many responses were linked to each check. We [...]

Monday, October 9th, 2006

Formatting Numbers in Oracle and Postgres

When dealing with large numbers in oracle sometimes it can be hard to read the results from a query with no formatting in the results. I know I have misread numbers from a query many times. Well, I finally got around to looking up how to format numbers in oracle. And who knew -- TO_CHAR [...]