sql >> Database teknologi >  >> RDS >> Oracle

oracle vælg fra flere borde

Dette er bestemt et problem med datamodellen, hvad angår dette krav. Jeg kan foreslå to muligheder:

Mulighed # 1: Opret en enkelt tabel SPORTS ved at kombinere alle tabeller og have en kolonne sport_type. Dette vil gøre det muligt at bruge én udvalgt forespørgsel i funktionen.

select  HOME,AWAY,COMP_NAME, M_TIME from SPORTS s
where s.HOME LIKE (:p_search_string) or s.AWAY LIKE (:p_search_string)
  and sport_type in 
(
'SOCCER',
'BASKETBALL',
'HANDBALL',
'ICE_HOCKEY',
'TENIST',
'VOLLEYBALL'
)

Mulighed # 2:

Create a view by combining all these tables and select from that view in this function.
CREATE OR REPLACE VIEW VW_SPORTS
AS
select HOME,AWAY,COMP_NAME, M_TIME, 'SOCCER' SPORT_TYPE from SOCCER
union all
select  HOME,AWAY,LISTS,M_TIME,'BASKETBALL' SPORT_TYPE from BASKETBALL 
union all
select HOME,AWAY,COMP,M_TIME,'HANDBALL' SPORT_TYPE from HANDBALL
union all
select  HOME,AWAY,LISTS,M_TIME,'ICE_HOCKEY' SPORT_TYPE from ICE_HOCKEY
union all
select  HOME,AWAY,COMP,M_TIME,'TENIST' SPORT_TYPE from TENISt
union all
select  HOME,AWAY,LISTS,M_TIME,'VOLLEYBALL' SPORT_TYPE  from VOLLEYBALL v;


 FUNCTION SEARACH_FOR_GAMES  ( p_search_string in varchar2 )
                             return weak_cur
  IS
    SEARCH_FIXID WEAK_CUR;   
  BEGIN  
    OPEN   SEARCH_FIXID FOR
       select  HOME,AWAY,COMP_NAME, M_TIME from VW_SPORTS s
        where s.HOME LIKE (:p_search_string) or s.AWAY LIKE (:p_search_string)
         and s.SPOR_TYPE IN 
    (
    'SOCCER',
    'BASKETBALL',
    'HANDBALL',
    'ICE_HOCKEY',
    'TENIST',
    'VOLLEYBALL'
    );
    RETURN SEARCH_FIXID;
  END SEARACH_FOR_GAMES;



  1. Bruger du Levenshtein-funktionen på hvert element i en tsvector?

  2. Oracle tabel kolonnenavn med mellemrum

  3. Opretter forbindelse til 4D fra Java

  4. Generer SQL-sætninger med python