Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> How to create a view dynamically?

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: How to create a view dynamically?
 anand  Posted: Aug 14, 2007 07:15:39 AM

 Total Post: 2
 Joined: Aug, 2007






 hello friends,
I am trying to create a view dynamically in a procedure. My friend gave a idea of using EXECUTE IMMEDIATE('CREATE VIEW...') . I tried out that, but that is not working.

anyone have a better idea?

 anand
Posted: Aug 14, 2007 07:45:42 AM  

 Total Post: 2
 Joined: Aug, 2007






 
sorries.. worked out the problem with subqueries itself.. :)

 Mitesh
Posted: Aug 28, 2007 05:29:25 AM  

 Total Post: 6
 Joined: Aug, 2007






 
Hi
Anand

Your friend is saying correct that u have to execute immediate ,
it will work.
i am giving u below example.

before executing this pl/sql , u have to first create table testindex with column name 'a'.

After that execute below code.


declare
-- Local variables here
v_a integer;
strSql varchar2(500);
v_viewname varchar2(100) :='v_testindex';
begin
-- Test statements here
execute immediate 'create or replace view ' || v_viewname || ' as select * from testindex';
execute immediate 'create or replace view ' || v_viewname || ' as select * from testindex';

--below query should be return single row
execute immediate 'select a from ' || v_viewname || ' t where t.a=1' into v_a;

dbms_output.put_line('value of v_a is ' || v_a);
end;



Thanks

Mitesh Bhimjiyaani


 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gopu Gopi327
  Gitesh Trivedi322
  Vinoth Kumar264
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software