319: IF get_terr_grp_values.geo_type = 'POSTAL_CODE'
320: THEN
321: select geo_id
322: into L_GEO_ID_FROM
323: from jtf_tty_geographies
324: where geo_type = get_terr_grp_values.geo_type
325: and geo_code = (
326: select min(geo_code)
327: from jtf_tty_geographies
323: from jtf_tty_geographies
324: where geo_type = get_terr_grp_values.geo_type
325: and geo_code = (
326: select min(geo_code)
327: from jtf_tty_geographies
328: where geo_type = get_terr_grp_values.geo_type
329: and geo_code >= get_terr_grp_values.low_value_char
330: and geo_code <= get_terr_grp_values.high_value_char);
331:
331:
332: Begin
333: select geo_id
334: into L_GEO_ID_TO
335: from jtf_tty_geographies
336: where geo_type = get_terr_grp_values.geo_type
337: and geo_code = (
338: select max(geo_code)
339: from jtf_tty_geographies
335: from jtf_tty_geographies
336: where geo_type = get_terr_grp_values.geo_type
337: and geo_code = (
338: select max(geo_code)
339: from jtf_tty_geographies
340: where geo_type = get_terr_grp_values.geo_type
341: and geo_code <= get_terr_grp_values.high_value_char
342: and geo_code >= get_terr_grp_values.low_value_char);
343: EXCEPTION
346: END;
347: ELSE -- not postal code
348: select geo_id
349: into L_GEO_ID_FROM
350: from jtf_tty_geographies
351: where geo_type = get_terr_grp_values.geo_type
352: and geo_code = get_terr_grp_values.low_value_char
353: and rownum < 2;
354:
354:
355: Begin
356: select geo_id
357: into L_GEO_ID_TO
358: from jtf_tty_geographies
359: where geo_type = get_terr_grp_values.geo_type
360: and geo_code = get_terr_grp_values.high_value_char
361: and rownum < 2;
362: EXCEPTION
761: WHERE gtv.geo_territory_id IN
762: (SELECT geo_territory_id FROM jtf_tty_geo_terr
763: where terr_group_id = p_terr_gp_id)
764: AND gtv.geo_id NOT IN
765: (SELECT g.geo_id FROM jtf_tty_geographies g, jtf_tty_geo_grp_values ggv, jtf_tty_geographies g1
766: WHERE ggv.terr_group_id = p_terr_gp_id
767: AND ggv.geo_type = 'COUNTRY'
768: AND ggv.geo_id_from = g1.geo_id
769: AND g.geo_type = 'POSTAL_CODE'
768: AND ggv.geo_id_from = g1.geo_id
769: AND g.geo_type = 'POSTAL_CODE'
770: AND g.country_code = g1.country_code
771: UNION
772: SELECT g.geo_id FROM jtf_tty_geographies g, jtf_tty_geo_grp_values ggv, jtf_tty_geographies g1
773: WHERE ggv.terr_group_id = p_terr_gp_id
774: AND ggv.geo_type = 'STATE'
775: AND ggv.geo_id_from = g1.geo_id
776: AND g.geo_type = 'POSTAL_CODE'
776: AND g.geo_type = 'POSTAL_CODE'
777: AND g.country_code = g1.country_code
778: AND g.state_code = g1.state_code
779: UNION
780: SELECT g.geo_id FROM jtf_tty_geographies g, jtf_tty_geo_grp_values ggv, jtf_tty_geographies g1
781: WHERE ggv.terr_group_id = p_terr_gp_id
782: AND ggv.geo_type = 'PROVINCE'
783: AND ggv.geo_id_from = g1.geo_id
784: AND g.geo_type = 'POSTAL_CODE'
784: AND g.geo_type = 'POSTAL_CODE'
785: AND g.country_code = g1.country_code
786: AND g.province_code = g1.province_code
787: UNION
788: SELECT g.geo_id FROM jtf_tty_geographies g, jtf_tty_geo_grp_values ggv, jtf_tty_geographies g1
789: WHERE ggv.terr_group_id = p_terr_gp_id
790: AND ggv.geo_type = 'CITY'
791: AND ggv.geo_id_from = g1.geo_id
792: AND g.geo_type = 'POSTAL_CODE'
802: AND ggv.geo_type = 'POSTAL_CODE'
803: AND ggv.comparison_operator = '='
804: UNION
805: SELECT g.geo_id
806: FROM jtf_tty_geographies g,
807: jtf_tty_geo_grp_values ggv,
808: jtf_tty_geographies g1,
809: jtf_tty_geographies g2
810: WHERE ggv.terr_group_id = p_terr_gp_id
804: UNION
805: SELECT g.geo_id
806: FROM jtf_tty_geographies g,
807: jtf_tty_geo_grp_values ggv,
808: jtf_tty_geographies g1,
809: jtf_tty_geographies g2
810: WHERE ggv.terr_group_id = p_terr_gp_id
811: AND ggv.geo_type = 'POSTAL_CODE'
812: AND ggv.comparison_operator = 'BETWEEN'
805: SELECT g.geo_id
806: FROM jtf_tty_geographies g,
807: jtf_tty_geo_grp_values ggv,
808: jtf_tty_geographies g1,
809: jtf_tty_geographies g2
810: WHERE ggv.terr_group_id = p_terr_gp_id
811: AND ggv.geo_type = 'POSTAL_CODE'
812: AND ggv.comparison_operator = 'BETWEEN'
813: AND g1.geo_id = ggv.geo_id_from