Creating and populating table using pl/sql

database-designoracle-11gplsqltable

I have been looking for a way to create a table in pl/sql format like using DECLARE and BEGIN. Below is what i tried in sql Developer and but continiously getting the error below.

Please advise what am i doing wrong and if any good resource to learn on populating table using pl/sql? cheers!!

Error report : ORA-06550: line 6, column 1:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:***

  • begin case declare exit for goto if loop mod null pragma

  • raise return select update while with an identifier


Code :
set serveroutput on;
DECLARE
v_customer_ID VARCHAR(10) not null := 3025;
v_customer_Name VARCHAR(15) :='Michel Jackson' ;
v_room_code VARCHAR(5) := 6536;
BEGIN
CREATE TABLE CUSTOMER
( v_customer_id VARCHAR2(10) NOT NULL,
v_customer_name varchar2(15),
v_room_code varchar2(5),
CONSTRAINT CUSTOMER_PK PRIMARY KEY (v_customer_ID)
);
END;
/

Best Answer

You can't. You have to use execute immediate. Check here

DECLARE 
    v_customer_ID  VARCHAR(10) not null := 3025;
    v_customer_Name VARCHAR(15) :='Michel Jackson' ;
    v_room_code  VARCHAR(5) := 6536;
BEGIN

  execute immediate 'create table customer....';

END;
/