mysql database question Create a stored procedure PDYNTABLE
mysql database question
Create a stored procedure ( P_DYN_TABLE) that creates a table DYNAMICALLY by having 2 input parameters, 1 which is the SOURCE table for that new table, and the second input is the name of the new table. You will need to define two statements, 1 for the structure of the table, AND 1 statement to populate it (Hint for the first statement you will need to build the CREATE statement by concatenating the NEW table name and the SOURCE table. For the second statement you will need to use the PREPARE and EXECUTE commands. ).
Solution
/*FIRST CREATE P_DYN_TABLE FOR NAME(name text) PARAMETER IN SOURCE AND NEWTABLE and then use the below code*/
CREATE TABLE NEW-TABLE(id integer,name text); /*here i am using two parameters*/
SELECT * INTO NEW-TABLE FROM SOURCE; /*here is a code for selectin a newtable from source*/
DBMS_OUTPUT.PUT_LINE(\'NEW TABLE IS CREATED AND POPULATED\'); /*finaly new table is created*/
