SQL-如何将列添加到SQL VIEW,但不将其添加或更新到表中?

时间:2014-12-02 11:24:18

标签: sql oracle-apex

如何将列添加到SQL THAT LIST USA作为" America"印度作为"亚洲"中国作为"亚洲"等等而不实际将数据添加到表中但仅包含在视图中。我想要包含COUNTRY_VISITED和名为CONTINENTS的新列。

CREATE OR REPLACE VIEW V_HOLIDAYS 
AS
    SELECT CODE_OF_HOLIDAY, DESCRIPTION, COUNTRY_VISITED
    FROM ZZZ_HOLIDAY_DETAILS;    

3 个答案:

答案 0 :(得分:1)

CREATE OR REPLACE VIEW V_HOLIDAYS AS
SELECT  CODE_OF_HOLIDAY, 
        DESCRIPTION, 
        case when COUNTRY_VISITED = 'USA' then 'America'
             when COUNTRY_VISITED in ('India','China') then 'Asia'
             else COUNTRY_VISITED 
        end as COUNTRY_VISITED 
FROM ZZZ_HOLIDAY_DETAILS;  

答案 1 :(得分:0)

使用case声明:

CREATE OR REPLACE VIEW V_HOLIDAYS 
AS
    SELECT CODE_OF_HOLIDAY, DESCRIPTION, COUNTRY_VISITED,
           (CASE WHEN COUNTRY_VISITED = 'USA' THEN 'AMERICA'
                 WHEN COUNTRY_VISITED IN ('INDIA', 'CHINA') THEN 'ASIA'
            END) as CONTINENT
    FROM ZZZ_HOLIDAY_DETAILS;    

答案 2 :(得分:0)

 SELECT CODE_OF_HOLIDAY, DESCRIPTION, COUNTRY_VISITED, 
 CASE WHEN COUNTRY_VISITED = 'USA' THEN 'America' 
      WHEN COUNTRY_VISITED = 'China' THEN 'Asia' 
      WHEN COUNTRY_VISITED = 'India' THEN 'Asia' ELSE COUNTRY_VISITED 
 END AS COUNTRY_VISITED_ALIAS
 FROM ZZZ_HOLIDAY_DETAILS