• sqlfriends - Thursday, September 7, 2017 10:27 PM

    But use many dml in cursors in pl_sql caused context switch between sql engine and plsql engine which affects performance. My question is why not just use standard sql statements (set based) working on set in the stored procedure instead of use cursor for row by row processing?

    The use of standard SQL is done in Oracle. It's just like in SQL Server most people avoid cursors. In Oracle most people avoid explicit cursors. It depends on what they are doing with the results. Just like some administrative types of things in SQL Server may require the use of cursors. It does not mean every administrative task is done in cursors. Use of bulk binds , such as FORALL and bulk_collect, do operate on the result set in bulk.
    In Oracle, they also recommend avoiding explicit cursors and it is considered best to use set based operations. When a cursor does need to be used for whatever reason in Oracle, they usually perform well. They are very different compared to SQL Server cursors with different memory structures. As I said, I don't think you can compare cursors in Oracle to cursors in SQL Server.

    Each platform has extensions to standard SQL that are used for different reasons so the context of why something is being done needs to be taken into consideration. Moving away from standard SQL and using the extensions a database platforms SQL language is done to meet some type of need or functionality you don't have in standard SQL. If you have seen nothing but explicit cursors for everything, you probably should look else where. Same would be true if you saw CLR used for everything in SQL Server. That doesn't mean that neither of those have no purpose or use in their respective languages.

    Sue