Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7884045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:41:42+00:00 2026-06-03T04:41:42+00:00

Could anybody help me to convert the following sql code into procedure? I’ve read

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:41:43+00:00Added an answer on June 3, 2026 at 4:41 am

    You could use either a PROCEDURE or a FUNCTION depending upon your ultimate requirements.

    A procedure would get the job done but you’d have to then query the MAYA table to see how many records you inserted.

    i.e.

    CREATE OR REPLACE
    PROCEDURE maya_insert
    IS
    BEGIN
       -- Truncate the maya table
       EXECUTE IMMEDIATE 'TRUNCATE TABLE MY_SCHEME.MAYA';
       --
       -- Insert records into 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);
    EXCEPTION
       WHEN others
       THEN
          DBMS_OUTPUT.put_line('MAYA_INSERT error: '||sqlerrm);
    END maya_insert;
    

    You may want to put a COMMIT; in there too unless you are committing the transaction outside of this procedure, if you do add the COMMIT; then also add a ROLLBACK; in the exception section.
    Be aware though that the TRUNCATE statement cannot be rolled back as it’s DDL. If you need the ability to roll it back then you’ll have to use the slower DELETE command which is DML.

    If you needed to know how many records were inserted into MAYA then use a function:

    i.e.

    CREATE OR REPLACE
    FUNCTION maya_insert
       RETURN NUMBER
    IS
    BEGIN
       -- Truncate the maya table
       EXECUTE IMMEDIATE 'TRUNCATE TABLE MY_SCHEME.MAYA';
       --
       -- Insert records into 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);
    
       -- Return the number of records inserted
       RETURN SQL%ROWCOUNT;
    EXCEPTION
       WHEN others
       THEN
          DBMS_OUTPUT.put_line('MAYA_INSERT error: '||sqlerrm);
          RETURN -1;
    END maya_insert;
    

    Here you will get the count of records inserted and if there was an error then you’ll get -1 returned. See above for my comments on COMMIT; and ROLLBACK; 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…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anybody help me to list Some Good Sites that are describing about Complete
Could anybody help me figure out the syntax of the code below? AddonInfo {
i started the learning MVVM pattern. So could anybody help me to list Some
Could anybody help with this? I am trying to integrate a coupon function into
Could anybody help me with some Jquery. I have a <div> with a bunch
Could anybody help me, please? I have this code: Process a; try { a
Hi could anybody help me understand this particular piece of code from this Langton's
I was wondering if anybody could help me with a method of creating a
I am new to php and was wondering if anybody could help me with
Could anybody explain, why next code isn't compiling? I'm creating a partially-specialized Map and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.