desmeulesj
asked on
Select where in problem
Hi experts!
I have a problem with the following query. This one is made of a principal query and a subquery. As designed so far, the subquery returns a list of ID's seperated by a comma (,) so it's results looks like "1,2,3,4,5,6,7" and this part works.
Now I try to include this "string" of results into a select where in statement so it would look like select * from blabla where xxx in (1,2,3,4,5,6,7) but Oracle triggers an error ORA-01722: invalid number, so I guess something must be wrong with the content of the result of my subquery, probably the datatype or my query is faulty by design.
Do you guys know any solution ?
select BG_USER_07 "Subject",
BG_SUMMARY "Fonction",
BG_USER_14 "Qualification",
BG_SEVERITY "Severity",
BG_BUG_ID "ID",
BG_STATUS "Status"
from bug_db.bug
where BG_BUG_ID IN (
SELECT TO_CHAR(REPLACE(LOWER(SUBS TR(CSET_VA LUE, INSTR(CSET_VALUE,'LogicalF ilter')+24 , (INSTR(CSET_VALUE,'VisualF ilter')-IN STR(CSET_V ALUE,'Logi calFilter' )-27))), ' or ', ','))
FROM bug_db.COMMON_SETTINGS
WHERE CSET_CATEGORY = 'BugViews'
and CSET_NAME = '1.3.5.0'
)
Thanks for the help !
I have a problem with the following query. This one is made of a principal query and a subquery. As designed so far, the subquery returns a list of ID's seperated by a comma (,) so it's results looks like "1,2,3,4,5,6,7" and this part works.
Now I try to include this "string" of results into a select where in statement so it would look like select * from blabla where xxx in (1,2,3,4,5,6,7) but Oracle triggers an error ORA-01722: invalid number, so I guess something must be wrong with the content of the result of my subquery, probably the datatype or my query is faulty by design.
Do you guys know any solution ?
select BG_USER_07 "Subject",
BG_SUMMARY "Fonction",
BG_USER_14 "Qualification",
BG_SEVERITY "Severity",
BG_BUG_ID "ID",
BG_STATUS "Status"
from bug_db.bug
where BG_BUG_ID IN (
SELECT TO_CHAR(REPLACE(LOWER(SUBS
FROM bug_db.COMMON_SETTINGS
WHERE CSET_CATEGORY = 'BugViews'
and CSET_NAME = '1.3.5.0'
)
Thanks for the help !
Can u give one or two sample output rows for the query
SELECT TO_CHAR(REPLACE(LOWER(SUBS TR(CSET_VA LUE, INSTR(CSET_VALUE,'LogicalF ilter')+24 , (INSTR(CSET_VALUE,'VisualF ilter')-IN STR(CSET_V ALUE,'Logi calFilter' )-27))), ' or ', ','));
SELECT TO_CHAR(REPLACE(LOWER(SUBS
Probably you have to put escape sequence for comma i.e. it would be '','' add additional single quote.
I just realized my code didn't post. I was after something similar.
I would like to see the output from:
I would like to see the output from:
SELECT CSET_VALUE
FROM bug_db.COMMON_SETTINGS
WHERE CSET_CATEGORY = 'BugViews'
and CSET_NAME = '1.3.5.0'
There is a chance that each row retrieves comma separated values
ASKER
slightwv, here is what the query you requested returns:
{
grid: \000000C1\1,0;51,BG_BUG_ID ;68,BG_SEV ERITY;66,B G_STATUS;7 0,BG_USER_ 14;70,BG_R ESPONSIBLE ;70,BG_DET ECTION_DAT E;70,BG_DE TECTED_BY; 191,BG_SUM MARY;206,B G_USER_13; 154,BG_USE R_07;133,B G_TARGET_R EL;70,BG_U SER_01;,
filter: \0000032C\[Filter]{
TableName:BUG,
ColumnName:BG_BUG_ID,
LogicalFilter:\0000015c\81 67 OR 8231 OR 8368 OR 8431 OR 8501 OR 8491 OR 8530 OR 8577 OR 7929 OR 8048 OR 8118 OR 8121 OR 8357 OR 7096 OR 8212 OR 4932 OR 8367 OR 8146 OR 8329 OR 8328 OR 8342 or 8148 or 8487 or 8218 or 8342 or 8148 or 8716 or 7096 or 8628 or 8639 or 8750 or 8752 or 8342 or 8717 or 8696 or 8625 or 8148 or 8764 or 8593 or 8741 or 8644 or 8740 or 8593 or 8676,
VisualFilter:\0000015c\816 7 OR 8231 OR 8368 OR 8431 OR 8501 OR 8491 OR 8530 OR 8577 OR 7929 OR 8048 OR 8118 OR 8121 OR 8357 OR 7096 OR 8212 OR 4932 OR 8367 OR 8146 OR 8329 OR 8328 OR 8342 or 8148 or 8487 or 8218 or 8342 or 8148 or 8716 or 7096 or 8628 or 8639 or 8750 or 8752 or 8342 or 8717 or 8696 or 8625 or 8148 or 8764 or 8593 or 8741 or 8644 or 8740 or 8593 or 8676,
NO_CASE:
}
,
show_rdcomment: "y",
show_description: "y",
show_summary: "y",
show_dropdown: "y"
}
The subquery I designed essentially strips everything but the list of id's you can see if the result above
{
grid: \000000C1\1,0;51,BG_BUG_ID
filter: \0000032C\[Filter]{
TableName:BUG,
ColumnName:BG_BUG_ID,
LogicalFilter:\0000015c\81
VisualFilter:\0000015c\816
NO_CASE:
}
,
show_rdcomment: "y",
show_description: "y",
show_summary: "y",
show_dropdown: "y"
}
The subquery I designed essentially strips everything but the list of id's you can see if the result above
ASKER
And for schajukg, here are the current results of the subquery:
8167,8231,8368,8431,8501,8 491,8530,8 577,7929,8 048,8118,8 121,8357,7 096,8212,4 932,8367,8 146,8329,8 328,8342,8 148,8487,8 218,8342,8 148,8716,7 096,8628,8 639,8750,8 752,8342,8 717,8696,8 625,8148,8 764,8593,8 741,8644,8 740,8593,8 676
8167,8231,8368,8431,8501,8
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's a simplified test case that shows the concept.
drop table tab1 purge;
create table tab1(col1 varchar2(500));
drop table tab2 purge;
create table tab2(col1 varchar2(10));
insert into tab1 values('8167,8231,8368,8431,8501,8491,8530,8577,7929,8048,8118,8121,8357,7096,8212,4932,8367,8146,8329,8328,8342,8148,8487,8218,8342,8148,8716,7096,8628,8639,8750,8752,8342,8717,8696,8625,8148,8764,8593,8741,8644,8740,8593,8676');
insert into tab2 values('8167');
insert into tab2 values('8676');
insert into tab2 values('9999');
commit;
select col1 from tab2
where col1 in (
select extractvalue(column_value,'x/text()')
from tab1 t1,
TABLE(XMLSEQUENCE(EXTRACT(xmltype('<root><x>' || replace(col1,',','</x><x>') || '</x></root>'), '/root/*')))
)
/
ASKER
Hehe works like a charm, the query is a bit slow tho :)
>>the query is a bit slow tho
Glad it worked. Now that you know the basic concept you might be able to tweak it a little to eliminate some steps. It's doing a lot of work to massage the data.
I'm sure you can replace some of the replaces to get to the xml a little quicker.
Glad it worked. Now that you know the basic concept you might be able to tweak it a little to eliminate some steps. It's doing a lot of work to massage the data.
I'm sure you can replace some of the replaces to get to the xml a little quicker.
That said, just remove the code that creates the comma-separated list and return the list itself.
To help provide a working example what does the following return: