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

  • Home
  • SEARCH
  • 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 3312802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:02:20+00:00 2026-05-17T22:02:20+00:00

I have a simple delete procedure which is using na cursor. I read somewhere

  • 0

I have a simple delete procedure which is using na cursor. I read somewhere that table vars should be preferred to cursors.

CREATE OR REPLACE PROCEDURE SMTAPP.LF_PLAN_VYMAZ (Str_oz varchar2, Num_rok number, Num_mesiac number, Str_s_trc_id varchar2) IS
    var_LF_PLAN_ID Number(20);
    cursor cur_plan is select id from lp_plan where lf_plan_id=var_LF_PLAN_ID;
BEGIN
   select ID into var_LF_PLAN_ID from lf_plan where oz=Str_oz and rok=Num_rok and mesiac=Num_mesiac and s_trc_id=Str_s_trc_id;
   for c1 in cur_plan loop
        delete from LP_PLAN_DEN where lp_plan_id=c1.id;
   end loop;
   delete from LP_PLAN where lf_plan_id=var_LF_PLAN_ID;
   delete from LP_PLAN_HIST where LF_PLAN_ID=var_LF_PLAN_ID;
   delete from LF_PLAN where id=var_LF_PLAN_ID;
END;
  • 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-05-17T22:02:21+00:00Added an answer on May 17, 2026 at 10:02 pm

    I don’t know what a “table var” is (I have a feeling it is a SQL Server term?) but I would not use a cursor here, I would do this:

    CREATE OR REPLACE PROCEDURE SMTAPP.LF_PLAN_VYMAZ 
       (Str_oz varchar2, Num_rok number, Num_mesiac number, Str_s_trc_id varchar2)
    IS
        var_LF_PLAN_ID Number(20);
    BEGIN
       select ID into var_LF_PLAN_ID
       from lf_plan
       where oz=Str_oz and rok=Num_rok and mesiac=Num_mesiac
       and s_trc_id=Str_s_trc_id;
    
       delete from LP_PLAN_DEN where lp_plan_id in 
          (select id from lp_plan where lf_plan_id=var_LF_PLAN_ID);
       delete from LP_PLAN where lf_plan_id=var_LF_PLAN_ID;
       delete from LP_PLAN_HIST where LF_PLAN_ID=var_LF_PLAN_ID;
       delete from LF_PLAN where id=var_LF_PLAN_ID;
    END;
    

    EDIT: “Table var” is indeed a SQL Server concept

    I would code this as shown above, however since you specifically want to see how to do it with a collection, here is another way that uses one:

    CREATE OR REPLACE PROCEDURE SMTAPP.LF_PLAN_VYMAZ 
       (Str_oz varchar2, Num_rok number, Num_mesiac number, Str_s_trc_id varchar2)
    IS
        var_LF_PLAN_ID Number(20);
        TYPE id_table IS TABLE OF lp_plan.id%TYPE;
        var_ids id_table_type;
    BEGIN
       select ID into var_LF_PLAN_ID
       from lf_plan
       where oz=Str_oz and rok=Num_rok and mesiac=Num_mesiac
       and s_trc_id=Str_s_trc_id;
    
       select id from lp_plan 
       bulk collect into var_ids
       where lf_plan_id=var_LF_PLAN_ID;
    
       forall i in var_ids.FIRST..var_ids.LAST
         delete from LP_PLAN_DEN where lp_plan_id = var_ids(i);
    
       delete from LP_PLAN where lf_plan_id=var_LF_PLAN_ID;
       delete from LP_PLAN_HIST where LF_PLAN_ID=var_LF_PLAN_ID;
       delete from LF_PLAN where id=var_LF_PLAN_ID;
    END;
    

    This will probably not perform as well as the previous method.

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

Sidebar

Related Questions

Should simple JavaBeans that have only simple getters and setters be unit tested?? What
Simple question: do I have to delete or delete [] c ? Does the
Ok, i have simple scenario: have two pages: login and welcome pages. im using
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple 2-column layout with a footer that clears both the right
I am using SQL Server 2008 Enterprise. I have created a very simple test
I have an Oracle table which contains event log messages for an application. We
I am trying to make my app localized. I have followed this procedure http://www.switchonthecode.com/tutorials/a-simple-localization-example-for-the-iphone
I have a simple form where a user can add, edit, and delete people
I have a script that appends some rows to a table. One of the

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.