Virtual column in 11g
Hi all,
I m migrating from 10g to 11g.I have doubt on virtual column.whether function based index and virtual column are same?
if no means what difference between then.What are difference in their performance??
No, they aren't the same.
if no means what difference between then
Function based index is a "INDEX" whereas virtual column is a "COLUMN". Both are two different Database objects.
What are difference in their performance??
You can't compare peformance of a Column with that of a Index.
Virtual columns appear to be normal table columns, but their values are derived rather than being stored on disc. E.g.,
CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
last_name VARCHAR2(10),
salary NUMBER(9,2),
comm1 NUMBER(3),
comm2 NUMBER(3),
salary1 AS (ROUND(salary*(1+comm1/100),2)),
salary2 NUMBER GENERATED ALWAYS AS (ROUND(salary*(1+comm2/100),2)) VIRTUAL, -- This is
your virtual column
CONSTRAINT employees_pk PRIMARY KEY (id)
For more info, you can refer to Oracle Documentation and below is additional link from asktom
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:676611400346196844
Ishan
Similar Messages
-
Virtual column in oracle 11g ???
HI Gurus,
I m really intrested in this new feature in oracle 11g called "Virtual column" . ....can anyone give me a very good example of code for virtual column???...i didnt find the good example for virtual column in online...
can we update or insert data into the virtual column ??
Thank you !!Hi,
For the last one, no.
See http://www.oracle.com/technology/pub/articles/oracle-database-11g-top-features/11g-schemamanagement.html
regards
Peter -
Virtual columns support in oracle 11g
Hi
I created a table with virtual columns using SQL as the APEX GUI didn't support it and I couldn't see the data dictionary of the table in object browser.
Some strange error about my user not having any privileges on the current scheme was displayed also when I tried to view the data. Dropped the table and all is normal again now, was looking forward to using the new 11g feature.
When will virtual columns be supported by APEX?
Regards
AdamAdam,
>> and I couldn't see the data dictionary of the table in object browser.
That's not my experience. I created a table in SQL Commands using:
CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
last_name VARCHAR2(10),
salary NUMBER(9,2),
comm1 NUMBER(3),
comm2 NUMBER(3),
salary1 AS (ROUND(salary*(1+comm1/100),2)),
salary2 NUMBER GENERATED ALWAYS AS (ROUND(salary*(1+comm2/100),2)) VIRTUAL,
CONSTRAINT employees_pk PRIMARY KEY (id)
);I was then able to browse the definition and view the data in Object Browser just fine.
>> Some strange error about my user not having any privileges on the current scheme was displayed also when I tried to view the data.
I couldn't reproduce this problem.
>> When will virtual columns be supported by APEX?
I created an application with an Interactive Report on the above table. On the resultant form, I had to change the item type of the virtual columns to Display Only. After that, DML on the form worked just great.
Joel -
ORA-31061 error while creating XMLType table with virtual column
I'm not calling it frustration ;)
but still... what about this one :
SQL> select * from v$version;
BANNER
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL> create table test_virtual of xmltype
2 xmltype store as binary xml
3 virtual columns (
4 doc_id as (
5 xmlcast(
6 xmlquery('/root/@id'
7 passing object_value returning content)
8 as number
9 )
10 )
11 )
12 ;
Table created.Now, on the latest version :
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 32-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> create table test_virtual of xmltype
2 xmltype store as binary xml
3 virtual columns (
4 doc_id as (
5 xmlcast(
6 xmlquery('/root/@id'
7 passing object_value returning content)
8 as number
9 )
10 )
11 )
12 ;
passing object_value returning content)
ERROR at line 7:
ORA-00604: error occurred at recursive SQL level 1
ORA-31061: XDB error: dbms_xdbutil_int.get_tablespace_tab
ORA-06512: at "XDB.DBMS_XDBUTIL_INT", line 1002Is there something I should be aware of?
Right now, I'm just evaluating the version so I can't submit any SR.
Thanks for anyone trying to reproduce the issue.Just tested again on a new installation (64-bit server).
It works :
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL>
SQL> create table test_virtual of xmltype
2 xmltype store as binary xml
3 virtual columns (
4 doc_id as (
5 xmlcast(
6 xmlquery('/root/@id'
7 passing object_value returning content)
8 as number
9 )
10 )
11 );
Table created
Now I'll try to see what are the differences between the two installations.
Thanks Dan and Marco for looking into this.
Edited by: odie_63 on 2 mai 2012 15:51 -
Query on virtual column that is defined in XMLIndex does not use the index
Hello,
I am facing an issue in executing queries on a virtual column that is defined in an XMLIndex: it appears as if the index is not used.
Database details:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
For this use case the XML documents adhere to the following XSD and are stored in an XMLType column in a table:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://a_name_space/v1"
targetNamespace="http://a_name_space/v1"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xsd:element name="fields">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="field" maxOccurs="unbounded">
<xsd:complexType>
<xsd:choice>
<xsd:element name="value" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="notEmptyString4000Type"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="values" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="notEmptyString4000Type">
<xsd:attribute name="startDate" type="xsd:date" use="required"/>
<xsd:attribute name="endDate" type="xsd:date" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="name" type="string30Type" use="required"/>
<xsd:attribute name="type" type="dataType" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="dataType">
<xsd:annotation>
<xsd:documentation>Char, Date, Number</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="C"/>
<xsd:enumeration value="D"/>
<xsd:enumeration value="N"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="string30Type">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="30"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="notEmptyString4000Type">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4000"/>
<xsd:pattern value=".+"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>A field can have a single value as well as multiple values.
The XMLIndex is defined as follows:
CREATE INDEX test_xmltype_idx ON test_xmltype (additional_fields) INDEXTYPE IS XDB.XMLIndex
PARAMETERS
XMLTable dt_fld_tab (TABLESPACE "TAB_SPACE" COMPRESS FOR OLTP) ''fields/field''
COLUMNS
name varchar2(30 char) PATH ''@name''
,dataType varchar2(1 char) PATH ''@type''
,val varchar2(4000 char) PATH ''value/text()''
,vals XMLType PATH ''values/value'' VIRTUAL
XMLTable dt_fld_multi_value_tab (TABLESPACE "TAB_SPACE" COMPRESS FOR OLTP) ''value'' passing vals
COLUMNS
val varchar2(4000) PATH ''text()''
,startDate varchar2(30 char) PATH ''@startDate''
,endDate varchar2(30 char) PATH ''@endDate''
');The following b-tree indexes are defined:
create index dt_field_name_idx on dt_fld_tab (name);
create index dt_field_value_idx on dt_fld_tab (val);
create index dt_field_values_idx on dt_fld_multi_value_tab (val);And stats are properly computed before the queries are executed:
call dbms_stats.gather_table_stats(user, 'test_xmltype', estimate_percent => null);Queries for single values are cost efficient and fast. With 600K rows in the table these return with 0.002 seconds.
Queries for multi-valued fields / elements are not though, these result in a full table scan.
Sample XML snippet:
<fields>
<field name="multiVal" type="C">
<values>
<value startDate="2013-01-01" endDate="2013-01-01">100</value>
<value startDate="2014-01-01">120</value>
</values>
</field>
</fields>Examples of costly and slow queries:
select id from test_xmltype
where xmlexists('/fields/field/@name="multiVal"' passing additional_fields)
and xmlexists('/fields/field/values/value[@startDate="2013-01-01"]' passing additional_fields)
and xmlexists('/fields/field/values/value[text()="100"]' passing additional_fields)
select id from test_xmltype
where xmlexists('/fields/field/@name="multiVal"' passing additional_fields)
and xmlexists('/fields/field/values/value[@startDate="2013-01-01" and .="100"]' passing additional_fields);Whereas the following query on the multi valued field is fast:
select id from test_xmltype
where xmlexists('/fields/field/@name="multiVal"' passing additional_fields)
and xmlexists('/fields/field/values/value[@startDate="2013-01-01"]' passing additional_fields);For the XPath /fields/field/values/value[@startDate="2013-01-01"] the index is used.
Suspected cause: XPath issue for the value of a multi valued field, e.g. /fields/field/values/value[text()="aValue"].
Any hints are appreciated: what am I overlooking here?
Thanks in advance,
-Sjoerd
Edited by: user615230 on May 27, 2013 7:46 AMHello,
This is using binary XML. The table creation script is:
create table test_xmltype
(id number(14,0) not null primary key
,member_code varchar2(30 char) not null
,period_code varchar2(30 char) not null
,amount number(12,2) not null
,additional_fields xmltype
);The schema is not registered in the database. Is that required? It is primarily used to generate Java classes that will be used in order to construct the XML documents.
And you are right: for our initial investigation the sample XML documents are generated with a PLSQL routine and do not contain namespaces. But for the single valued fields there are also no namespaces and the queries on these are executed with very satisfactory plans.
Thanks for the swift reply.
-Sjoerd -
Adding virtual column: ORA-12899: value too large for column
I'm using Oracle 11g, Win7 OS, SQL Developer
I'm trying to add virtual column to my test table, but getting ORA-12899: value too large for column error. Below are the details.
Can someone help me in this?
CREATE TABLE test_reg_exp
(col1 VARCHAR2(100));
INSERT INTO test_reg_exp (col1) VALUES ('ABCD_EFGH');
INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_ABC');
INSERT INTO test_reg_exp (col1) VALUES ('WXYZ_ABCD');
INSERT INTO test_reg_exp (col1) VALUES ('ABCDE_PQRS');
INSERT INTO test_reg_exp (col1) VALUES ('ABCD_WXYZ');
ALTER TABLE test_reg_exp
ADD (col2 VARCHAR2(100) GENERATED ALWAYS AS (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_')));
SQL Error: ORA-12899: value too large for column "COL2" (actual: 100, maximum: 400)
12899. 00000 - "value too large for column %s (actual: %s, maximum: %s)"
*Cause: An attempt was made to insert or update a column with a value
which is too wide for the width of the destination column.
The name of the column is given, along with the actual width
of the value, and the maximum allowed width of the column.
Note that widths are reported in characters if character length
semantics are in effect for the column, otherwise widths are
reported in bytes.
*Action: Examine the SQL statement for correctness. Check source
and destination column data types.
Either make the destination column wider, or use a subset
of the source column (i.e. use substring).When I try to select, I'm getting correct results:
SELECT col1, (REGEXP_REPLACE (col1, '^ABCD[A-Z]*_'))
FROM test_reg_exp;Thanks.Yes RP, it working if you give col2 size >=400.
@Northwest - Could you please test the same w/o having a regex clause in col2?
I doubt on the usage of a REGEX in this dynamic col case.
Refer this (might help) -- http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
Below snippet from above link.... see if this helps...
>
Notes and restrictions on virtual columns include:
Indexes defined against virtual columns are equivalent to function-based indexes.
Virtual columns can be referenced in the WHERE clause of updates and deletes, but they cannot be manipulated by DML.
Tables containing virtual columns can still be eligible for result caching.
Functions in expressions must be deterministic at the time of table creation, but can subsequently be recompiled and made non-deterministic without invalidating the virtual column. In such cases the following steps must be taken after the function is recompiled:
Constraint on the virtual column must be disabled and re-enabled.
Indexes on the virtual column must be rebuilt.
Materialized views that access the virtual column must be fully refreshed.
The result cache must be flushed if cached queries have accessed the virtual column.
Table statistics must be regathered.
Virtual columns are not supported for index-organized, external, object, cluster, or temporary tables.
The expression used in the virtual column definition has the following restrictions:
It cannot refer to another virtual column by name.
It can only refer to columns defined in the same table.
If it refers to a deterministic user-defined function, it cannot be used as a partitioning key column.
The output of the expression must be a scalar value. It cannot return an Oracle supplied datatype, a user-defined type, or LOB or LONG RAW.
>
Edited by: ranit B on Oct 16, 2012 11:48 PM
Edited by: ranit B on Oct 16, 2012 11:54 PM -
ORA-01733- virtual column not allowed here - Insert using inline view
Does anyone know why I am getting ORA-01733- virtual column not allowed here
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
---no error without WITH CHECK option
SQL> INSERT INTO
2 (SELECT
3 location_id,
4 city,
5 l.country_id
6 FROM countries c, locations l,regions r
7 where l.country_id = c.country_id
8 and r.region_id=c.region_id
9 and r.region_name = 'Asia')
10 VALUES (5500, 'Wansdworth Common', 'UK');
1 row created.
SQL> rollback;
Rollback complete.
-----error with WITH CHECK OPTION
SQL> INSERT INTO
2 (SELECT
3 location_id,
4 city,
5 l.country_id
6 FROM countries c, locations l,regions r
7 where l.country_id = c.country_id
8 and r.region_id=c.region_id
9 and r.region_name = 'Asia' WITH CHECK OPTION)
10 VALUES (5500, 'Wansdworth Common', 'UK');
INSERT INTO
ERROR at line 1:
ORA-01733: virtual column not allowed here
I was expecting
ORA-01402: view WITH CHECK OPTION where-clause violation
for the second one. Is there anything I am missing here ?Randolf
Thank you very much for the update to this old question
After reading the link I think I should ignore this error and accept it as ORA-01402
The information you asked me to check did not lead me an understanding of different error types.
SQL> ----view for ORA-01733
SQL> create view test_v_1
2 as
3 SELECT
4 location_id,
5 city,
6 l.country_id
7 FROM countries c, locations l,regions r
8 where l.country_id = c.country_id
9 and r.region_id=c.region_id
10 and r.region_name = 'Asia' WITH CHECK OPTION;
View created.
SQL>
SQL>
SQL>
SQL> select * from user_updatable_columns where table_name='TEST_V_1';
OWNER TABLE_NAME COLUMN_NAME UPD INS DEL
HR TEST_V_1 CITY YES YES YES
HR TEST_V_1 COUNTRY_ID NO NO NO
HR TEST_V_1 LOCATION_ID YES YES YES
SQL>
SQL> ----view for ORA-01402
SQL>
SQL> create view test_v_2
2 as
3 SELECT
4 d.department_id,
5 d.department_name,
6 d.location_id
7 FROM hr.departments d,hr.locations l
8 WHERE l.location_id=d.location_id
9 and d.location_id < 2000
10 WITH CHECK OPTION;
View created.
SQL>
SQL> select * from user_updatable_columns where table_name='TEST_V_2';
OWNER TABLE_NAME COLUMN_NAME UPD INS DEL
HR TEST_V_2 DEPARTMENT_ID YES YES YES
HR TEST_V_2 DEPARTMENT_NAME YES YES YES
HR TEST_V_2 LOCATION_ID NO NO NO
SQL>
SQL>
SQL> ----INSERT STILL FAILING WITH DIFFERENT ERROR DESPITE THE SAME UPDATABLE COLUMN STRUCTURE
SQL> insert into test_v_1 values (5500, 'Wansdworth Common', 'UK');
insert into test_v_1 values (5500, 'Wansdworth Common', 'UK')
ERROR at line 1:
ORA-01733: virtual column not allowed here
SQL> insert into test_v_2 values (9999, 'Entertainment', 2500);
insert into test_v_2 values (9999, 'Entertainment', 2500)
ERROR at line 1:
ORA-01402: view WITH CHECK OPTION where-clause violation
SQL>A. Coskan GUNDOGAR
Oracle DBA
http://coskan.wordpress.com
“A man's errors are his portals of discovery.”
James Joyce -
ORA-00939 when creating XML table with Virtual Columns
Getting error on creating table with VIRTUAL COLUMNS:
Error at Command Line:4 Column:31
Error report:
SQL Error: ORA-00939: too many arguments for function
00939. 00000 - "too many arguments for function"
Without VIRTUAL COLUMNS works fine.
Where to start?
Is it possible to add Virtual Columns after a table is created?
CREATE TABLE TDS_XML OF XMLType
XMLSCHEMA "http://xmlns.abc.com/tds/TDSSchemaGen2.xsd"
ELEMENT "TDSTestData"
VIRTUAL COLUMNS
TESTID AS (
XMLCast(
XMLQuery('declare default element namespace "http://xmlns.abc.com/tds/TDSSchemaGen2.xsd"; /TDSTestData/TestID' PASSING OBJECT_VALUE RETURNING CONTENT) AS VARCHAR2(32)
)SQL*Plus: Release 11.2.0.2.0 Production on Mon Apr 30 20:17:29 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL>victor_shostak wrote:
Figured, Virtual Columns work only for Binary XML.They are only supported, currently, for Binary XML. -
Virtual column and partition exchange load
Hi All,
Can someone tell me that if i have a virtual column on a table in 11g then can we load the data as partition exchange loading into the table.
Thanks & Regards,
Ankit RanaHemant K Chitale wrote:
Why not run a simple test with a dummy table, a few columns (plus a virtual column) and a few partitions ?
Excellent suggestion.
Shouldn't take more than about 30 minutes to create a test case - and if it takes more than 30 minutes the OP needs the practice anyway to get a better feel for the technology.
Hint to OP: make sure you put some data in the "incoming" table, make sure you put some data in the "non-exchanged" partitions, remember to include a unique/pk constraint if you're expecting one on production, and run with sql_trace enabled to see what's happening in the background.
Regards
Jonathan Lewis -
Dropping a column in composite xmltype table with virtual column
Hello,
i found some interesting behavior. I have a table with xmltype column and a virtual column. If i drop a column, which has an index smaller than the index for the xmltype column, than the virtual column reference for xmltype column is not changed.
select * from v$version;
drop table t_xml purge;
create table t_xml( c1 number,
c2 number,
cxml xmltype,
c3 number,
xmlflag number as (nvl2(cxml,1,0)));
select * from t_xml;
alter table t_xml drop column c2;
select * from t_xml; The 2nd select will result in error:
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> alter table t_xml drop column c2;
Tabelle wurde geändert.
SQL>
SQL> select * from t_xml;
select * from t_xml
FEHLER in Zeile 1:
ORA-00904: "SYS_NC00004$": ungültiger BezeichnerNow the virtual column xmlflag references still the old hidden column for cxml (SYS_NC00004$). It not references the new hidden column, which is now SYS_NC00003$.
I think, it is a bug! Can someone inform oracle? I have no access to metalink.Hi,
Please try this code:
loop at int_inv into wa_inv.
lv_count = lv_count + 1.
AT END OF posnr. <------- The field you want to sum..
gs_total-posnr = wa_inv-posnr.
gs_total-cov_total = lv_count.
APPEND gs_total TO gt_total.
CLEAR : gs_total,
lv_count,
wa_inv.
ENDAT.
ENDLOOP. -
CREATING VIRTUAL COLUMN IN OWB11g
How can i create virtual columns in ORACLE 11g using Warehouse Builder. OWB11g does not seem to have this option available. The only other option seems to be to alter the table using sql.
Thanks, I know how is it done. using the data object editor. I can't see anywhere in the data object editor where the virtual column creation could go. I have tried using the default value and this is the query it generates below.
CREATE TABLE "TABLE_1"
"TEST" VARCHAR2(7),
"TEST2" VARCHAR2(7) default GENERATED ALWAYS AS (1)
this is the error I receive
Error
ORA-00984: column not allowed here
obviously the default is the problem. Is there anyway i could do this using the data object editor -
Problem with creating virtual column
Hello,
We've got problem with creating virtual column.
There is table R_T that contain columns R_ID and L_ID, we would like to create virtual column RL_ID that contains sth like 'R_ID-L_ID' (R_ID, L_ID and RL_ID are varchars).
According documentation we've tried:
alter table R_T add column (RL_ID varchar2(60) generated always as (R_ID||'-'||L_ID) VIRTUAL)
but getting
ORA-00904: : invalid identifier
00904.00000 - "%s: invalid identifier"
Have no idea where is the problem.
Table, columns names are little different but contains only capital letters A - Z and underscore "_".
Has anyone idea?
Thanks a lot.Strange...
This does work for me :
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as dev
SQL>
SQL> create table r_t (
2 r_id varchar2(25),
3 l_id varchar2(25)
4 );
Table created
SQL> insert into r_t (r_id, l_id) values('R','L');
1 row inserted
SQL> alter table r_t add (rl_id varchar2(60) generated always as (r_id||'-'||l_id) virtual);
Table altered
SQL> select * from r_t;
R_ID L_ID RL_ID
R L R-L
SQL> -
Insertion in Table with Virtual Column
Hi,
I am using 11.1.0.7.0 on Solaris 10.
I created following table:
test@mytest> create table mytest (c1 number, c2 number generated always as (1) virtual);
Table created.
test@mytest> create unique index idx on mytest(c2);
Index created.
test@mytest> insert into mytest values(1);
insert into mytest values(1)
ERROR at line 1:
ORA-00947: not enough values
test@mytest> Why it is not letting me insert into the table, because we cannot insert value in a virtual column?
regards
Edited by: Panicked DBA on Aug 28, 2010 3:59 AMThis works a little bit better but not really as expected:
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL>
SQL> drop table mytest purge;
Table dropped.
SQL>
SQL> create table mytest (c1 number, c2 number generated always as (1) virtual);
Table created.
SQL> create unique index idx on mytest(c2);
Index created.
SQL> insert into mytest(c1) values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> set null IS_NULL
SQL> select c1, c2 from mytest ;
C1 C2
1It looks like there is a bug if you specify C2 NUMBER data type:
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL>
SQL> drop table mytestok purge;
Table dropped.
SQL> drop table mytestko purge;
Table dropped.
SQL>
SQL> create table mytestok (c1 number, c2 generated always as (1) virtual);
Table created.
SQL> insert into mytestok(c1) values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select c1, c2 from mytestok ;
C1 C2
1 1
SQL> select * from mytestok where c2 = 1;
C1 C2
1 1
SQL>
SQL> create table mytestko (c1 number, c2 number generated always as (1) virtual);
Table created.
SQL> insert into mytestko(c1) values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> set null IS_NULL
SQL> select c1, c2 from mytestko ;
C1 C2
1
SQL> select * from mytestko where c2 = 1;
no rows selected
SQL> exit -
Not able to model virtual column
Hello,
I am using SQL developer 3.2.20.09 with Data Modeler version 3.1.4.710.
I am trying to model a virtual column by adding the following properties to the column:
Allow Nulls: not checked
Datatype: varchar2(1)
Computed: checked
Column expression: the call to a function
When generating the DDL, the column is modeled as:
<name> VARCHAR2 (1) NOT NULL
Is this the correct way to model the virtual column?
Thanks in advance,
JoopHi Joop,
yes, your definition is correct. Virtual columns are supported in Oracle Database 11g, so you need to set RDBMS type for your relational model as Oracle 11g (or up) and then you'll get correct DDL generated.
Philip -
General Question: should Fact Table use virtual column?
Hi,
I have read several articles about 11g's Virtual Column feature and it all looks very good. But I just want to know
- Whether virtual column is also good for Fact table or not?
- Is it recommedated?
- Is there a 'limit' or 'recommedation'regarding how many virtual columns I should use in a table?
ThanksIn an OLTP system, the number of virtual columns is self-limiting because there aren't that many simple ways to combine the columns in a single table using simple expressions. In a data warehouse, there are likely a lot more expressions that you might want to compute, so you would have to be careful as oracletune points out if expressions can change over time assuming that you want the version of the computation that was in force at the time the row was written to be used.
There really isn't a rule of thumb. It's a lot like asking how many indexes a table should have-- the only answer is to do a cost-benefit analysis on each potential index/ virtual column to determine if the benefits outweigh the cost. A virtual column allows you to avoid computing an expression when you are inserting a value but requires that you compute it at query time. If a row is queried millions of times, written once, and never updated, that probably isn't a great trade-off. If a row is queried a few times and updated a bunch, avoiding the computations is probably worthwhile. If you need to store the value and you have an OLTP system, the ability to ensure that you never have stale computations is great.
Justin
Maybe you are looking for
-
I have been unable to update or reinstall Itunes to my windows 7 64 bit computer. I have tried most of the suggestions to date to no avail. My outcome is a dialog box that says itunes was not installed. . . At one point, it created a situation whe
-
Inner Query relating to calculated field in main query
I have a query that has calculating fields in it. What I am trying to do is Create another inner SELECT query similar to the one above but using the FP_Qty_Required calculated field in the main query? Is this even possible? Thanks in advance Aaron
-
Instant client libraries 32-11.1.0.6.0
I install Oracle 11g (windows 32 bit platform) on windows 2003. It installed successfully and is up. From another windows 2003 machine, I am trying to connect from a windows application to that oracle server using instant client libraires. I had down
-
Dear Team, I have to enter the data field of peoplesoft pages in hindi language , please let me know how can i do that. it is our customer requirement.
-
We need some fixes and an update!!
so far with my HTC Merge i cant update kindle app, cant download new widgets and it doesnt have very many perosnalization options, if you see this post verizon please please please release an update with fixes.