如何更改视图中虚拟列的数据类型?

时间:2015-04-01 18:33:17

标签: sql oracle sql-view

create or replace view ABC_VIEW(
   VEHICLEID, BRAND,
   MODEL, VEHICLE_TYPE,
   FUEL_TYPE, TRANSMISSION_TYPE,
   GEARBOX, DRIVE_TYPE,
   VEHICLE_NUMBER, PRICE, 
   "TEST Column"
) as 
  select VEHICLEID, BRAND,
         MODEL, VEHICLE_TYPE,
         FUEL_TYPE, TRANSMISSION_TYPE,
         GEARBOX, DRIVE_TYPE,
         VEHICLE_NUMBER, PRICE, 
         '' as "TEST Column" 
    from ABC;

默认情况下,"Test Column"创建为Char(1)。如何将其更改为Number数据类型?

请帮帮我。感谢。

2 个答案:

答案 0 :(得分:5)

喜欢这里:

create or replace view v_abc as 
  select cast(null as number) test_column
    from dual;

测试:

select table_name, column_name, data_type 
  from all_tab_columns where table_name='V_ABC';

TABLE_NAME                     COLUMN_NAME                    DATA_TYPE 
------------------------------ ------------------------------ -------
V_ABC                          TEST_COLUMN                    NUMBER

答案 1 :(得分:0)

您可能正在寻找TO_NUMBER功能。

试试这个:

create or replace view ABC_VIEW
(VEHICLEID,BRAND,MODEL,VEHICLE_TYPE,FUEL_TYPE,TRANSMISSION_TYPE,GEARBOX,DRIVE_TYPE,VEHICLE_NUMBER,PRICE,**"TEST Column"**) 
as select  VEHICLEID,BRAND,MODEL,VEHICLE_TYPE,FUEL_TYPE,
TRANSMISSION_TYPE,GEARBOX, DRIVE_TYPE,VEHICLE_NUMBER,PRICE,TO_NUMBER('') 
 from ABC;