使用此选择创建过程或函数

时间:2018-04-05 11:38:26

标签: oracle plsql

我正在试图弄清楚这个选择的最佳解决方案是什么。我需要创建从所有这些联合中返回一个值ODD的函数或过程。

SELECT ODD FROM SOCCER_PREMATCH_ODDS SO WHERE SO.FIXID =:fixid and SO.TYPE = :type and SO.RES = :res 
UNION 
SELECT ODD FROM LIVE_ODDS LO WHERE LO.FIXID =:fixid and LO.TYPE =:type and LO.RES =:res 
UNION
SELECT ODD FROM PREMATCH_BASKETBALL_ODDS BO WHERE BO.FIXID =:fixid and BO.TYPE = :type and BO.RES = :res 
UNION 
SELECT ODD FROM LIVE_BASKETBALL_ODDS LBO WHERE LBO.FIXID =:fixid and LBO.TYPE =:type and LBO.RES =:res
UNION
SELECT ODD FROM PREMATCH_TENIS_ODDS TEO WHERE TEO.FIXID =:fixid and TEO.TYPE = :type and TEO.RES = :res 
UNION 
SELECT ODD FROM LIVE_TENNIS_ODDS LTEO WHERE LTEO.FIXID =:fixid and LTEO.TYPE =:type and LTEO.RES =:res
UNION
SELECT ODD FROM PREMATCH_HANDBALL_ODDS HEO WHERE HEO.FIXID =:fixid and HEO.TYPE = :type and HEO.RES = :res 
UNION 
SELECT ODD FROM LIVE_HANDBALL_ODDS LHEO WHERE LHEO.FIXID =:fixid and LHEO.TYPE =:type and LHEO.RES =:res

所以,如果有人知道请帮助..提前致谢

2 个答案:

答案 0 :(得分:0)

哪个"一个值ODD"? UNION将返回不同的ODD值,但不必是单个值。一旦你得到它们,你打算用这些做什么?

无论如何,这是一个选项:

SQL> CREATE OR REPLACE FUNCTION f_test
  2     RETURN SYS.odcinumberlist
  3  IS
  4     retval   SYS.odcinumberlist;
  5  BEGIN
  6     SELECT odd
  7       BULK COLLECT INTO retval
  8       FROM (SELECT 1 odd FROM DUAL
  9             UNION
 10             SELECT 1 FROM DUAL
 11             UNION
 12             SELECT 2 FROM DUAL);
 13
 14     RETURN retval;
 15  END;
 16  /

Function created.

SQL>
SQL> select * from table(f_test);

COLUMN_VALUE
------------
           1
           2

SQL>

答案 1 :(得分:0)

    create or replace FUNCTION checkOdds(p_fixid in varchar2,p_type in varchar2, p_res in varchar2)
    RETURN varchar2
 AS
     ODDS varchar2(200);
 BEGIN
  select Odd into ODDS 
  from(
     SELECT odd FROM SOCCER_PREMATCH_ODDS SO WHERE SO.FIXID =p_FIXID and SO.TYPE = p_TYPE and SO.RES = p_RES
             UNION
             SELECT odd FROM LIVE_ODDS LO WHERE LO.FIXID =p_FIXID and LO.TYPE =p_TYPE and LO.RES =p_RES
            UNION
            SELECT odd FROM PREMATCH_BASKETBALL_ODDS BO WHERE BO.FIXID =p_FIXID and BO.TYPE = p_TYPE and BO.RES = p_RES
            UNION
            SELECT odd FROM LIVE_BASKETBALL_ODDS LBO WHERE LBO.FIXID =p_FIXID and LBO.TYPE =p_TYPE and LBO.RES =p_RES
            UNION 
            SELECT odd FROM PREMATCH_TENIS_ODDS TEO WHERE TEO.FIXID =p_FIXID and TEO.TYPE = p_TYPE and TEO.RES = p_RES
            UNION 
            SELECT odd FROM LIVE_TENNIS_ODDS LTEO WHERE LTEO.FIXID =p_FIXID and LTEO.TYPE =p_TYPE and LTEO.RES =p_RES
            UNION 
            SELECT odd FROM PREMATCH_HANDBALL_ODDS HEO WHERE HEO.FIXID =p_FIXID and HEO.TYPE = p_TYPE and HEO.RES = p_RES
            UNION
            SELECT odd FROM LIVE_HANDBALL_ODDS LHEO WHERE LHEO.FIXID =p_FIXID and LHEO.TYPE =p_TYPE and LHEO.RES =p_RES);
            RETURN ODDS;
          END;

这是我做了什么,我得到了我需要的东西。