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 204457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:28:10+00:00 2026-05-11T17:28:10+00:00

SQL Server developers consider Cursors a bad practise , except under some circumstances. They

  • 0

SQL Server developers consider Cursors a bad practise , except under some circumstances. They believe that Cursors do not use the SQL engine optimally since it is a procedural construct and defeats the Set based concept of RDBMS.

However, Oracle developers do not seem to recommend against Cursors. Oracle’s DML statements themselves are implicit cursors.

Why this difference in approach? Is it because of the way these 2 products are made, or does this advice apply to both products?

  • 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-11T17:28:10+00:00Added an answer on May 11, 2026 at 5:28 pm

    What’s wrong with cursors is that they are often abused, both in Oracle and in MS SQL.

    Cursor are for keeping a stable resultset which you can retrieve row-by-row. They are implicitly created when your query is run, and closed when it’s finished.

    Of course keeping such a resultset requires some resources: locks, latches, memory, even disk space.

    The faster these resources are freed, the better.

    Keeping a cursor open is like keeping a fridge door open

    You don’t do it for hours without necessity, but it does not mean you should never open your fridge.

    That means that:

    • You don’t get your results row-by-row and sum them: you call the SQL‘s SUM instead.
    • You don’t execute whole query and get the first results from the cursor: you append a rownum <= 10 condition to your query

    , etc.

    As for Oracle, processing your cursors inside a procedure requires infamous SQL/PLSQL context switch which happens every time you get a result of an SQL query out of the cursor.

    It involves passing large amounts of data between threads and synchronizing the threads.

    This is one of the most irritating things in Oracle.

    One of the less evident consequences of that behaviour is that triggers in Oracle should be avoided if possible.

    Creating a trigger and calling a DML function is equal to opening the cursor selecting the updated rows and calling the trigger code for each row of this cursor.

    Mere existence of the trigger (even the empty trigger) may slow down a DML operation 10 times or more.

    A test script on 10g:

    SQL> CREATE TABLE trigger_test (id INT NOT NULL)
      2  /
    
    Table created
    
    Executed in 0,031 seconds
    SQL> INSERT
      2  INTO   trigger_test
      3  SELECT level
      4  FROM   dual
      5  CONNECT BY
      6     level <= 1000000
      7  /
    
    1000000 rows inserted
    
    Executed in 1,469 seconds
    SQL> COMMIT
      2  /
    
    Commit complete
    
    Executed in 0 seconds
    SQL> TRUNCATE TABLE trigger_test
      2  /
    
    Table truncated
    
    Executed in 3 seconds
    SQL> CREATE TRIGGER trg_test_ai
      2  AFTER INSERT
      3  ON trigger_test
      4  FOR EACH ROW
      5  BEGIN
      6     NULL;
      7  END;
      8  /
    
    Trigger created
    
    Executed in 0,094 seconds
    SQL> INSERT
      2  INTO   trigger_test
      3  SELECT level
      4  FROM   dual
      5  CONNECT BY
      6     level <= 1000000
      7  /
    
    1000000 rows inserted
    
    Executed in 17,578 seconds
    

    1.47 seconds without a trigger, 17.57 seconds with an empty trigger doing nothing.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I find it surprising that it's so hard to remove.… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer AFAIK, the regular licence for VS is for the user,… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer The best way to improve the performance of resizing is,… May 11, 2026 at 11:48 pm

Related Questions

Update 2009.04.24 The main point of my question is not developer confusion and what
I've read a few threads on SO about usefulness of unit-testing various applications. The
I'm beginning PHP development, and I'm looking at picking brains for ideas and best
We have an ASP.Net app, that behaves strangely under IIS6. The app itself is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.