views:

102

answers:

3

I am investigating the possibility of updating our application to work with database servers other than Firebird. We rely on "STARTING WITH" for accessing our hierarchical data. Without it, I don't see how we can migrate to another database without some serious redesign.

If you are not familiar with STARTS WITH, it simply checks to see if a string field starts with a particular string e.g. ... WHERE 'This is a test' STARTS WITH 'This is' ... would return true. If a column is indexed, the index will be used for the comparison.

Do other database servers (especially Oracle/MSSQL) support "STARTING WITH" (or "STARTS WITH")?

+5  A: 

The standard SQL to achieve that is something like ... WHERE 'This is a test' like 'This is%';

Kentaree
Will "... LIKE 'This is%' ..." use a column index if it is available? In Firebird it will, but "... LIKE '% is %' ...", wont.
norgepaul
That sounds very RDBMS dependent. In Oracle it would depend on the estimated cardinality of the result set, and there would still be less conventional index access methods such as a fast full index scan as options.
David Aldridge
where name like 'norge%' will probably use an index.
tuinstoel
A: 

Some DB's also support WHERE LEFT('This is a test', 7) = 'This is' (although I don't remember whether this is part of the SQL standard).

chiccodoro
A: 

Oracle's Select has a "Start With" http://www.oracle.com/pls/db10g/db10g.show_toc?which=main&partno=b10759&maxlevel=2&section=&expand=41274">Oracle Documentation 10g for hierarchial queries. It's been part of Oracle for many years (Oracle 8 at least).

Not sure about SQL Server.

Aussie Craig
Oracles "START WITH" and Firebirds "STARTS WITH" do not have the same functionality. Oracles specifies a root row, Firebirds is a string comparator.
norgepaul