[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ORA-01733: virtual column not allowed here

Posted on 2004-11-16
5
Medium Priority
?
3,367 Views
Last Modified: 2008-03-04
Bellow are my Tble, view, trigger and fuction when try to update the table using the view getting

ERROR at line 3:
ORA-01733: virtual column not allowed here



create table SKU_FUTURE_COST (
      IMAGE_RECNBR number(10) not null
     ,SKU varchar2(20) not null                    
    DATE_COST_EFF date -- yymmdd                
  );

create view VS_SKU_FUTURE_COST
   as select
   IMAGE_RECNBR
   ,SKU
   ,DATE_COST date -- yymmdd
   from SKU_FUTURE_COST
/

create or replace trigger SKU_FUTURE_COST_VIR
instead of insert on VS_SKU_FUTURE_COST
begin
   insert into SKU_FUTURE_COST (
         SKU
        ,DATE_COST_EFF
        ,Date_Add_Trigger
      ) values (
         :new.SKU
        ,fn_FmtCblDate_YYMMDD(:new.DATE_COST_EFF)
        ,sysdate
      );
end;
/

DROP FUNCTION fn_FmtCblDate_YYMMDD;

Create Function fn_FmtCblDate_YYMMDD(coboldate char)
   RETURN DATE AS
Begin
 Declare
  cobolholddate char(6);
  Result date;
 Begin
  IF coboldate = ' ' then
    Result := NULL;
  Else
    If coboldate = '000000' then
     Result := NULL;
    Else
    If length(coboldate) = 3 then
         cobolholddate  := '000' || coboldate ;
         Result :=  to_date((to_number(cobolholddate)), 'yymmdd');
    Else    
    If length(coboldate) = 4 then
         cobolholddate  := '00' || coboldate ;
         Result :=  to_date((to_number(cobolholddate)), 'yymmdd');
    Else      
    If length(coboldate) = 5 then
         cobolholddate  := '0' || coboldate ;
         Result :=  to_date((to_number(cobolholddate)), 'yymmdd');
    Else    
         Result :=  to_date((to_number(cobolholddate)), 'yymmdd');
    End if;
    End if;
    End if;
    End if;
 End if;
  RETURN Result;
 End;
End;
/
0
Comment
Question by:bolicat
5 Comments
 
LVL 23

Expert Comment

by:paquicuba
ID: 12597065
,DATE_COST date -- yymmdd
date -- is a reserved word

Put double quotes around it:

SQL> select sysdate date from dual;
select sysdate date from dual
               *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


Elapsed: 00:00:00.00
SQL> select sysdate "date" from dual;

date
---------
16-NOV-04

1 row selected.
0
 

Author Comment

by:bolicat
ID: 12597167
I'm not trying to select, I'm trying to update, delete and insert.
The insert work.

P.S. I'm no usnig the date in the view this is a typo

Thanks
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 12597202
You have other typos:

In view VS_SKU_FUTURE_COST ",DATE_COST" is not a SKU_FUTURE_COST
column.

In trigger SKU_FUTURE_COST_VIR except for DATE_COST_EFF,
the INSERT does not refer to any of SKU_FUTURE_COST:
   insert into SKU_FUTURE_COST (
         SKU
        ,DATE_COST_EFF
        ,Date_Add_Trigger)
....
0
 

Author Comment

by:bolicat
ID: 12597230
With and without the typos I'm getting the same error when try to update
0
 
LVL 5

Accepted Solution

by:
alexfrl earned 1500 total points
ID: 12598004
There are 2 problems

1st) Doubtful

create view VS_SKU_FUTURE_COST
   as select
   IMAGE_RECNBR
   ,SKU
   ,DATE_COST date -- yymmdd
   from SKU_FUTURE_COST
/

Please remove date which is after ,DATE_COST

2nd) Obvious


create or replace trigger SKU_FUTURE_COST_VIR
instead of insert on VS_SKU_FUTURE_COST
begin
   insert into SKU_FUTURE_COST (
         SKU
        ,DATE_COST_EFF
        ,Date_Add_Trigger
      ) values (
         :new.SKU
        ,fn_FmtCblDate_YYMMDD(:new.DATE_COST_EFF)
        ,sysdate
      );
end;
/

you are trying to insert ,fn_FmtCblDate_YYMMDD(:new.DATE_COST_EFF) into DATE_COST_EFF
There is your problem: the trigger is defined on your view which columns are:
IMAGE_RECNBR, SKU, DATE_COST

There are referencing to :new.DATE_COST_EFF means that DATE_COST_EFF is one of its (view's) columns.

But you do not see it on the list, neither I, nor the compiler ! It is a VIRTUAL column :))

As the result the compiler complains "ORA-01733: virtual column not allowed here"

Change it for DATE_COST and then it should work

Cheers


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question