Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Insert rows from a materialized view? Is it possible?
DA Morgan wrote:
> nkunkov_at_escholar.com wrote:
> > Hi,
> > Is it possible to do an insert from a materialized view?
> > I'd like to call a function from the view to do the insert.
> > Will this work?
> > Do I need to use execute immediate?
> > Your help is greatly appreciated.
> > Thank you.
>
> You need to:
>
> 1. Better explain what you are trying to do.
> 2. State the Oracle version
> 3. Which type of Materialized View?
> --
> Daniel A. Morgan
> University of Washington
> damorgan_at_x.washington.edu
> (replace x with u to respond)
> Puget Sound Oracle Users Group
> www.psoug.org
Daniel, thanks for trying to help me.
I'm not at work right now so can't provide the exact code but I will
try to give you some pseudo code. Please forgive syntax errors, this is
just a skeleton of what I'm doing. Also, just wanted to say I'm not an
Oracle guru, so most of this I have not done before.
I have to create a materialized view which will call a function for one
or two of it's columns.
Here is a function that encrypts input value and returns it converted
to a character but also does a table insert:
function getValue (varchar2 input) return varchar2
output varhcar2(200);
sqlCmd varchar2(1000);
is
output := DBMS_CRYPTO.encrypt(input,key......);
newSequenceValue := get new sequence number from a sequence;
--if sequence value doesn't exist in table B do the following insert
sqlCmd := 'insert into my table values(output, newSequenceValue)' ;
execute immediate sqlCmd;
return newSequenceValue;
create materialized view
..................
.................... ....................
Note the function call here.
This seems to work. But I haven't tried to refresh the view, I only
created it. Not sure if it will work on refresh.
Besides, first I had a regular insert instead of execute immediate.
That gave me an error when I tried creating a view. Something like
can't commit from view. So I put execute immediate and that seems to
work. But I am not sure this is something I can put on production.
Will this actually work or I'm overlooking some major problems? Will it
work on refresh? Do I need execute immediate or there is another way
to insert from view using function? Should there be restriction on how
to create the view? I think I can't use query rewrite.
Please let me know what you think.
Your help is greatly appreciated.
Thanks
NK
Received on Thu Jun 15 2006 - 12:15:48 CDT
![]() |
![]() |