× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Folks:

I need some advice on a somewhat complex SQL statement (at least complex for me)...

I have an insert statement, with a sub-select statement, that does includes a number of somewhat complex expression's on the same column (REGEXP_SUBSTR). I also want to do some comparison's on the expression results and skip a record if it already exists in the target table.

I thought that a CTE would make things easier.

Here's what I have so far:

insert into myfile (realfield1, realfield2)
with mycte (ctefield1, ctefield2)
as (
select
REGEXP_SUBSTR(otherfield1, :regexp, 1,1,'',1), -- 1st group from expr
REGEXP_SUBSTR(otherfield2, :regexp, 1,1,'',2) -- 2nd group from expr
from otherfile
where otherfield2 = 'somevalue'
)
select ctefield1, ctefield2
from mycte
where ctefield1 <> ' ' and
not exists (
select *
from myfile
where realfield1 = ctefield1 and realfield2 = ctefield2
)
;

The first time I run the statement it works, a record gets inserted.

The second time I run the statement it's not working ... a record gets inserted. The 'not exists' predicate doesn't appear to be identifying that the record already exists in the target file.

Any suggestions on what might be going wrong?

Thanks!

david


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.