Could anybody help me to convert the following sql code into procedure? I’ve read some www sources and made a conclusion (may be) that it should be package?
TRUNCATE TABLE MY_SCHEME.MAYA;
INSERT INTO MY_SCHEME.MAYA (ID_TEST,
IQ,
DATE_,
COMMENT1)
SELECT ID_TEST,
IQ,
DATE_,
COMMENT1
FROM MY_SCHEME.STAGE_MAYA
where STAGE_MAYA.ID_TEST=(select max (ID_TEST) from MY_SCHEME.STAGE_MAYA)
Thanks a lot!
You could use either a
PROCEDUREor aFUNCTIONdepending upon your ultimate requirements.A procedure would get the job done but you’d have to then query the
MAYAtable to see how many records you inserted.i.e.
You may want to put a
COMMIT;in there too unless you are committing the transaction outside of this procedure, if you do add theCOMMIT;then also add aROLLBACK;in the exception section.Be aware though that the
TRUNCATEstatement cannot be rolled back as it’sDDL. If you need the ability to roll it back then you’ll have to use the slowerDELETEcommand which isDML.If you needed to know how many records were inserted into
MAYAthen use a function:i.e.
Here you will get the count of records inserted and if there was an error then you’ll get
-1returned. See above for my comments onCOMMIT;andROLLBACK;being added if you need them.As regards a package. Packages are used to group logically related functions procedures and other processing together in the database. As you only have one procedure or function there is no need to wrap it in a package at this stage.
See: http://docs.oracle.com/cd/B10501_01/appdev.920/a96624/09_packs.htm#362
Hope it helps…