I have a problem with an Oracle stored procedure that dynamically creates some materialized views.
The procedure first drops the materialized views if there are any with the same name of the ones that will be created. Then it creates the new materialized views.
Both the statements of drop and create are execute by means of the execute immediate command.
When I execute the procedure, it first drops the materialized views already created and fails to create the new ones because of an alleged lack of privileges.
Instead, if I run the code as a script, it perfectly works.
I tried to create a simpler stored procedure, but I get the same error.
Is there anyone able to explain why it happens or how to understand the reason?
dropprivilege granted directly but thecreateprivilege granted via a role? (This is similar, but there will be better duplicate targets...) Why are you dropping and creating objects at runtime at all though - that is not a normal pattern? Unless the view definition changes each time you can refresh it (if that isn't already automatic). Or perhaps an MV isn't the right solution for whatever you're doing.