Create Table in PL/SQL
Oracle PL/SQL supports dynamic SQL through which user can execute DDL operations through PL/SQL blocks .i.e anonymous blocks, stored procedures/packages,or through functions.Here is an example of creating a table called ab(id number,name varchar2(20).
--Declare a variable which can hold create table definition.
--call Execute immediate for that variable.
SQL> declare
2 v varchar2(250);
3 begin
4 v:='create table ab(id number, name varchar2(20))';
5 execute immediate v;
6 end;
7 .
SQL> set serveroutput on;
--Execute the script
SQL> /
PL/SQL procedure successfully completed.
--check wether table created or not
SQL> select * from ab;
no rows selected
--describe the table.
SQL> desc ab;
Name Null? Type
----------------------------------------------------------------------------------- -------- ---------------
ID NUMBER
NAME VARCHAR2(20)
Tags: create table in PL/SQL, oracle create table in pl/sql, execute immediate in pl/sql, create table with execute immediate in pl/sql.How to create a table in PL/SQL , How to create a table using Execute Immediate , Create table using dynamic sql in pl/sql, How to create table using dynamic sql.
No comments:
Post a Comment