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;
/
1 Answer 1
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;
/
-
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!!klamgade– klamgade2016年08月26日 03:36:53 +00:00Commented Aug 26, 2016 at 3:36
-
@klamgade Random data, data from other table?vercelli– vercelli2016年08月26日 07:07:48 +00:00Commented 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?klamgade– klamgade2016年08月28日 05:32:00 +00:00Commented Aug 28, 2016 at 5:32
Explore related questions
See similar questions with these tags.