ORA-01733: virtual column not allowed here

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;
/
bolicatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paquicubaCommented:
,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
bolicatAuthor Commented:
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
MikeOM_DBACommented:
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
bolicatAuthor Commented:
With and without the typos I'm getting the same error when try to update
0
alexfrlCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.