Re: need sql statement for complex address search



sean nakasone wrote:
we have a database that stores addresses. the address number is stored in a field called MY_NUMBER. Now if the address has two numbers i.e. 12-345, then the 12 will be in a field called MY_PREFIX. I need to come up with 1 SQL statement (and it can't be PL/SQL) that will check if there's a hypen and if so, search in both the MY_PREFIX and MY_NUMBER fields. If there is no hyphen, then it should only search in the MY_NUMBER field. The reason it can't be a PL/SQL statement is because we are using an application that interfaces with oracle and that application will only accept one SQL statement and will not support PL/SQL.

Searches for what?
In what version of Oracle?

Is your intention a query such as this?

create table test (
aid NUMBER(3),
my_prefix VARCHAR2(20),
my_number VARCHAR2(20));

INSERT INTO test VALUES (1, '12','345');
INSERT INTO test VALUES (2, '12',NULL);
INSERT INTO test VALUES (3, NULL,'345');

SELECT aid
FROM test
WHERE (my_prefix || '-' || my_number) = '12-345'
UNION ALL
SELECT aid
FROM test
WHERE my_number = '12-345';
--
Daniel A. Morgan
University of Washington
damorgan@xxxxxxxxxxxxxxxx (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
.



Relevant Pages

  • Buffer Overflow in Oracle 9iAS (#NISR20122001)
    ... NGSSoftware Insight Security Research Advisory ... Name: Oracle PL/SQL Apache Module ...
    (Bugtraq)
  • Re: CBO & different execution plans
    ... a SQL statement in a packaged application that was taking excessively ... long to execute - roughly 3.4 seconds per execution and the packaged ... The problem in this case had to do with Oracle picking ... Providing a hint to Oracle to use ...
    (comp.databases.oracle.server)
  • Re: DBD::Oracle installation - make test failed - ORA-28000: accout locked
    ... tests so no more complaints about the wrong return values from exit. ... But the test 20 and 21 still failed, the errors seem to be Oracle ... SQL statement ... Subject: DBD::Oracle installation - make test failed - ORA-28000: accout ...
    (perl.dbi.users)
  • Re: Receiving email into pl/sql
    ... Users could send stereotyped messages to that account, and the pl/sql routine would read the mail, parse the messages and do the needful. ... In the database you would have to write ... My Oracle server is running on a different box from my email server, so the trick is to get the data from the mail server to the oracle box. ...
    (comp.databases.oracle.tools)
  • Re: formula help please
    ... primary and foreign keys are essentials in solving such problems. ... each of the tables are related to each other with each SQL statement. ... engine like Oracle), the program adds additional lines to the actual ... WHERE clause that describes how the tables are to be linked together. ...
    (comp.databases.oracle.misc)