0

I have a set of results that I query with connect by prior, now I need to check in the where clause of a query if ONE of those results is IN some other set of values(a select * from another table). I'm trying to use 'IN' but I think that that only works when I have one unique value to check for, and not a group of values.

SELECT COUNT('X')
INTO V_COUNT 
FROM SIC_NEA_CATFRU
WHERE (SELECT cod_nivel_estr_art
       FROM niveles_estr_art
       CONNECT BY PRIOR cod_nivel_estr_art_P = cod_nivel_estr_art
       START WITH cod_nivel_estr_art = V_COD_NIVEL_eSTR_ART) IN ( SELECT COD_NIVEL_eSTR_ART FROM SIC_NEA_CATFRU);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Golan_trevize
  • 2,353
  • 5
  • 22
  • 22

1 Answers1

1

Would the intersect set operator do? Something like this: first query is your hierarchical query, while the second returns values from the sic_nea_catfru table. If there are any matches, you'll know how many:

SELECT COUNT (*)
  INTO v_count
  FROM (    SELECT cod_nivel_estr_art
              FROM niveles_estr_art
        CONNECT BY PRIOR cod_nivel_estr_art_p = cod_nivel_estr_art
        START WITH cod_nivel_estr_art = v_cod_nivel_estr_art
        INTERSECT
        SELECT cod_nivel_estr_art FROM sic_nea_catfru)
Littlefoot
  • 131,892
  • 15
  • 35
  • 57