Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> SQL-Find missing data

SQL-Find missing data

From: Mitchell Loren <mloren_at_home.com>
Date: Sat, 19 Jun 1999 01:23:32 GMT
Message-ID: <376AEED6.B517553D@home.com>


'm writing an integrity checker for our system at work which basically
scans the database tables for any discrepant pieces of data that should
not be there. Anyway, there's one rule which is as follows :

(I've changed the names of tables and columns)

For all names in table_a whose status is 'P', a record should exist in
table_b. I want a list of all names and corresponding status which DO
NOT meet this rule.
I've come up with the following cursor in PL/SQL (Oracle 7.3.3) :

CURSOR     rule_cursor IS
SELECT      a.name, a.status
FROM         table_a   a
WHERE      a.status = 'P'
AND           a.name NOT IN
                   (SELECT   b.name
                    FROM      table_a   a,
                                     table_b   b
                    WHERE    a.name = b.name);

My question is this ... is there an easier, more efficient way of doing
this? I'm fairly new to PL/SQL, and to me, it seems an awful amount of
work to be done for something which seems straight forward.

YES- select a.name
from table_a a, table_b b
where a.name = b.name(+)
and a.status = 'P'
and b.name is null Received on Fri Jun 18 1999 - 20:23:32 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US