0

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; /

asked Aug 24, 2016 at 8:21

1 Answer 1

0

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;
/
answered Aug 24, 2016 at 8:24
3
  • i am trying to populate this table using a procedure so i can do it for 50-100 numbers of rows. Could you please advise with some ideas or examples? Cheers!! Commented Aug 26, 2016 at 3:36
  • @klamgade Random data, data from other table? Commented Aug 26, 2016 at 7:07
  • For adding random data. I have created a separate question for it . [ dba.stackexchange.com/questions/147955/… ] .. Example here actually works, however, please suggest if any idea for placing correct Branch_ID and Boolean value for Is_Booked column? Commented Aug 28, 2016 at 5:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.