Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to insert into schema .first check in schema where that table exists or not if there exists then insert into that table otherwise create table and insert into that table .your suggestion is very important to move ahead for this code .
this is code i have done bt where is error and mistake plz help me in pl/sql
CREATE OR REPLACE   PROCEDURE insert1(stringin IN VARCHAR2,value1  IN VARCHAR2,value2 IN VARCHAR2)
IS
  val VARCHAR2(20);
  val2 VARCHAR2(20);
  val3 VARCHAR(20);

BEGIN

IF NOT EXISTS (SELECT 1 FROM all_tables WHERE owner = 'HR')    THEN

 val3:='CREATE TABLE stringin(value1 VARCHAR2(20), value2 VARCHAR2(20)';
       EXECUTE IMMEDIATE val3;

  BEGIN

--   abc:= CREATE TABLE tbl_name (value1 VARCHAR2(20), value2 VARCHAR2(20)) ;

     val1:= 'INSERT INTO   val3 (value1, value2) VALUES("GGG", "XYZ")';

          DBMS_OUTPUT.PUT_LINE (val1);
END   ;

ELSE

BEGIN
   val2:=' INSERT  INTO  stringin (value1, value2)  VALUES ("GGG", "XYZ")' ;

          DBMS_OUTPUT.PUT_LINE (val2);
END ;
END IF ;
END ;

to find out
Posted
Updated 5-Mar-12 1:59am
v2
Comments
Varun Sareen 5-Mar-12 7:59am    
edit for: added pre tag

1 solution

SQL
IF NOT EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[table_name]') AND type in (N'U'))
CREAT TABLE ...
GO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900