Question:
How we can create a table in PL/SQL block. insert records into it??? is it possible by some procedure or function?? please give example...
Answer:
CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)
AS
l_stmt VARCHAR2(200);
BEGIN
DBMS_OUTPUT.put_line('STARTING ');
l_stmt := 'create table '|| p_table_name || ' as (select * from emp )';
execute IMMEDIATE l_stmt;
DBMS_OUTPUT.put_line('end ');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('exception '||SQLERRM || 'message'||sqlcode);
END; Source: CoolInterview.com
We can create table in procedure as explained in above case. but we can't create or perform any DDL in functions.
Source: CoolInterview.com
Answered by: Vinod Pandit | Date: 4/10/2008
| Contact Vinod Pandit
the above given answer is correct. but we can also create or perform any ddl in functions.
I have tested myself Source: CoolInterview.com
Answered by: Mike | Date: 12/9/2009
| Contact Mike
we can create a table through pl/sql block with dbms_sql package and execute immediate statement. CREATE OR REPLACE PROCEDURE PROC_CREATE_NEW_TABLE(STMT VARCHAR2) IS AUTHID CURRENT_USER BEGIN EXECUTE IMMEDIATE STMT; END; here AUTHID CURRENT_USER is used to create a table under current user privileges. through this procedure we can add our own fields of a table on run time,even it is not depended on structure of an existing table. Insertion record into the table, because it is DML operation so we can easily create a procedure with simple statements or execute immediate statement. Source: CoolInterview.com
Answered by: Ravindra Kumar Ray | Date: 1/7/2010
| Contact Ravindra Kumar Ray
DDL's can be used in function provided that function should be invoked in Begin End block not from Select statement. Source: CoolInterview.com
Answered by: Sathish | Date: 3/15/2010
| Contact Sathish
DDL's can be used in function provided that function should be invoked in Begin End block not from Select statement. Source: CoolInterview.com
Answered by: vvvv | Date: 6/13/2010
| Contact vvvv
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|