0
votes

The following simple SQL query generates an ORA-01427 error when searching for certain specific object numbers.

SELECT OBJ

FROM A.TABLEA

WHERE (OBJ ='XXXXXX');

The query works fine except for when you choose an OBJ where there is another OBJ row/s with a corresponding A suffix 'XXXXXXA'. i.e. querying for OBJ = 'XXXXXXA' works fine, but querying for OBJ = 'XXXXXX' produces the error, alternatively querying for OBJ = 'XXXXXY' works fine when there is no corresponding OBJ = 'XXXXXYA'

Is there a way to handle / avoid the error where it will pick the first/last/random single row?

And going a step further instead of searching for specific Objects I want to search within a date range where I have to join another table to get the date, the error will show if there is a 'XXXXXX' with corresponding 'XXXXXXA' within the date range. See code below,

SELECT
t1.*,
t2.OBJ,
t2.DATE

FROM
A.TABLEA t1
LEFT OUTER JOIN
A.TABLEB t2

ON (t1.OBJ = t2.OBJ)

WHERE
(t2.DATE BETWEEN TO_DATE ('2019/04/01', 'yyyy/mm/dd')
AND TO_DATE ('2019/04/30', 'yyyy/mm/dd');

Is there a way to handle / avoid the error in this code to force it to select 1 row?

Thanks in advance.

1
You have shown only a part of your query as I don't see a subquery anywhere in your question.Kaushik Nayak
The queries you have shown can not result in that error.a_horse_with_no_name
Can you provide some sample data?Alessandro Cucina
I don't see a subquery.Eric
Thanks for your help, I understand its a simple query with no subquery. I can't pull data from the problem table that will cause the issue because no matter how I query for it is comes up with this error, whether I search for a specific object number or just grab the x number of rows. I believe the error is caused with the creation of the table through its own sql code (I'm not sure how the table generates its data), which will cause an error when an object gets redone with the A suffix (where extra data gets put in there that isn't in the original object number).Robert

1 Answers

0
votes

I was able to solve this situation by selecting the correct data tables that had the base data (rather than the sql generated table I was originally selecting) and performing the join on the first 12 characters of the object number, (SUBSTR(t1.OBJ,1,12) = SUBSTR(t2.OBJ,1,12)

where the 13 character had the extra A suffix.

Thanks for your help.