2

Is there a way, in Oracle 11gR2 that I could create a single column with two names?

Reason I need this is back compatibility, on situations in which this would work:

create table test1 (col1 varchar2(10), col2 [some ref to col1]);

insert into test1 values ('test_value');

and then

SQL> select col1 from test1;
test_value

SQL> select col2 from test1;
test_value

There seem to be a way of thing so on SQL Server, I am looking for the Oracle equivalent to it.

ideas?

Community
  • 1
  • 1
filippo
  • 5,583
  • 13
  • 50
  • 72
  • Is creating a `view` not enough? – T.S. Oct 24 '13 at 20:38
  • cant.. would have two objects with the same name. also, due to other constrains, I couldn't rename the "original" – filippo Oct 24 '13 at 20:38
  • Not if in different schema – T.S. Oct 24 '13 at 20:40
  • well, this would all be in the same schema. – filippo Oct 24 '13 at 20:40
  • Another method would be to use Edition-Based Redefinition - you rename the table e.g. test1$base and then create edition-based views, one for each client. http://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_editions.htm - this would then allow you to use Edition triggers to transform data from both applications seemlessly. – Jeffrey Kemp Oct 25 '13 at 03:58

1 Answers1

3

You can create a VIRTUAL COLUMN:

CREATE TABLE test1 (
  col1 VARCHAR2(10),
  col2 VARCHAR2(10) GENERATED ALWAYS AS (col1 || '')
);

INSERT INTO test1 (col1) VALUES ('test_value');
COMMIT;

SELECT * FROM test1;

COL1       COL2     
---------- ----------
test_value test_value 

However, virtual columns cannot be manipulated by DML. Read more here: Oracle Base - Virtual Columns

Przemyslaw Kruglej
  • 8,003
  • 2
  • 26
  • 41