Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am getting error while creating the view inside one procedure


PROCEDURE SP_TEST(
PI_SAAAA IN date,
PI_EEEEE IN date,
PI_SSSSS IN varchar2) IS



BEGIN

CREATE OR REPLACE VIEW V_TEST AS
select a.xxxx,a.yyyy,b.hhhh

from
table1 a, table2 b

CSS
commit;

EXCEPTION
 WHEN OTHERS THEN
  Rollback;

END SP_TEST;



Error am getting :
Compilation errors for PACKAGE BODY CONV.PKG_TEST

Error: PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe
Line: 50
Text: CREATE OR REPLACE VIEW V_TEST1 AS



What could be the reason?
Posted
Comments
Sudhakar Shinde 29-May-13 3:03am    
I have observed couple of things..
1) Create view statement in above code is not complete. You need to add a WHERE clause and semicolon(;) at the end of create statement.
2) CREATE statement is a DDL (Data Definition Language) statement and you do not need to write COMMIT after it.

1 solution

I'm not sure why you'd want/need to create a view from within a procedure, but I believe you need to use dynamic SQL. For example:

SQL
CREATE OR REPLACE PROCEDURE create_view is
PRAGMA AUTONOMOUS_TRANSACTION;

BEGIN
execute immediate 'CREATE VIEW just1 AS SELECT 1 as col1 from dual';
END;



Then execute it:

SQL
BEGIN
  username.CREATE_VIEW;
END;


Then the view will exist.
Scott
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900