newdeveloper india
asked on
create table in procedure having query like 'create table tablenm as (select * from tblnm2);
Please help me for this type of table creation..
create table in procedure having query like
'create table tablenm as (select * from tblnm2);
how to bind this query in procedure ??
create table in procedure having query like
'create table tablenm as (select * from tblnm2);
how to bind this query in procedure ??
you may also use this for better handling:
CREATE PROCEDURE YourSP
AS
BEGIN
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tablenm') AND type in (N'U'))
DROP TABLE tablenm
select * into tablenm from tblnm2;
END
ASKER
I have only one procedure to create in which I want to insert,update,alter and create table from my select query and then update this table with respective values and then insert those values in another table. This solution will help in another procedure.
Thank you Sir..
Thank you Sir..
It would appear that this question is posted in the Oracle zone.
Not sure what database that procedure is intended for, but it certainly isn't Oracle. SYS.OBJECTS isn't a valid object in Oracle and if it was a regular user wouldn't have privileges on it, not sure what OBJECT_ID is (probably a function), you cannot create a table that way, and you cannot execute DDL directly in PL/SQL.
For Oracle, I would do it this way:
Not sure what database that procedure is intended for, but it certainly isn't Oracle. SYS.OBJECTS isn't a valid object in Oracle and if it was a regular user wouldn't have privileges on it, not sure what OBJECT_ID is (probably a function), you cannot create a table that way, and you cannot execute DDL directly in PL/SQL.
For Oracle, I would do it this way:
create or replace procedure p1 as
already_exists exception;
pragma exception_init(already_exists, -955);
begin
execute immediate 'create table tablenm as (select * from tblnm2)';
exception
when already_exists then
execute immediate 'drop table tablenm';
execute immediate 'create table tablenm as (select * from tblnm2)';
end;
/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you sir...
It helped in some extent.
It helped in some extent.
Open in new window