我如何在SQL中执行Oracle中的计算列

时间:2015-09-24 06:37:45

标签: sql-server oracle

如何使用oracle中的复合列创建这样的表:

SQL Server中的表定义是:

CREATE TABLE [dbo].[CCtestUsingSubstring] (
   [EmpNumb] INT NOT NULL, 
   [Designation] VARCHAR(50) NOT NULL, 
   [DOBirth] DATETIME NOT NULL, 
   [DORetirement] AS REPLACE([Designation],'E','O') )

insert into [CCtestUsingSubstring] values(1,'Developer',1/10/1992)

Select * from [CCtestUsingSubstring]

3 个答案:

答案 0 :(得分:1)

Oracle将此称为“虚拟列”:

CREATE TABLE CCtestUsingSubstring (
   EmpNumb INT NOT NULL, 
   Designation VARCHAR2(50) NOT NULL, 
   DOBirth DATE NOT NULL, 
   DORetirement AS (REPLACE(Designation,'e','O')));

insert into CCtestUsingSubstring (EmpNumb, Designation, DOBirth) 
values(1,'Developer',date '1992-10-01');

Select * from CCtestUsingSubstring

答案 1 :(得分:0)

CREATE TABLE [dbo].[CCtestUsingSubstring] (
   [EmpNumb] INT NOT NULL, 
   [Designation] VARCHAR(50) NOT NULL, 
   [DOBirth] DATETIME NOT NULL, 
   [DORetirement] AS REPLACE([Designation],'E','O') )

insert into [CCtestUsingSubstring] values(1,'Developer',1/10/1992)

Select * from [CCtestUsingSubstring]

答案 2 :(得分:0)

CREATE OR REPLACE TYPE my_tab_t AS TABLE OF VARCHAR2(30);
/
CREATE TABLE nested_table (id NUMBER, col1 my_tab_t)
       NESTED TABLE col1 STORE AS col1_tab;

INSERT INTO nested_table VALUES (1, my_tab_t('A'));
INSERT INTO nested_table VALUES (2, my_tab_t('B', 'C'));
INSERT INTO nested_table VALUES (3, my_tab_t('D', 'E', 'F'));
COMMIT;