Dynamic sql example




DECLARE



 SQLSTMT VARCHAR2(500);



 CURSOR C1 IS SELECT DISTINCT 'GRANT FRS_JTO_OD TO '||SDO_CODE ABC FROM EXCHANGE_SDO;



 BEGIN

 SQLSTMT:=NULL;

 FOR V1 IN C1 LOOP

 sqlstmt:=V1.ABC;

 execute immediate (sqlstmt);

 END LOOP;

 END;

 /



NOTE :- Do not put  ‘;’ in the sqlstmt


FOR DDL



DECLARE



SQLSTMT VARCHAR2(500);





 BEGIN



SQLSTMT:='CREATE TEMPORARY TABLESPACE TEMP_new1 TEMPFILE ''/usr1/TEMP_new1.dbf'' SIZE 50M REUSE

AUTOEXTEND ON NEXT 32 M MAXSIZE unlimited EXTENT MANAGEMENT LOCAL UNIFORM SIZE 32M';



execute immediate (sqlstmt);



SQLSTMT:='ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP_new1';



execute immediate (sqlstmt);



SQLSTMT:='DROP TABLESPACE TEMP_ABC INCLUDING CONTENTS AND DATAFILES';



execute immediate (sqlstmt);



END;

/


 

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post