{"id":76598,"date":"2025-01-29T16:52:00","date_gmt":"2025-01-29T16:52:00","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=76598"},"modified":"2025-01-29T16:52:03","modified_gmt":"2025-01-29T16:52:03","slug":"what-is-a-dynamic-cursor-in-oracle-pl-sql","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=76598","title":{"rendered":"What is a Dynamic Cursor in Oracle PL\/SQL"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Dynamic\/Ref Cursor<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE OR REPLACE PROCEDURE query_invoice(<br>       month VARCHAR2, <br>       year VARCHAR2) IS<br>    <strong>TYPE cur_typ IS REF CURSOR;<br>    c cur_typ;<\/strong><br>    query_str VARCHAR2(200);<br>    inv_num NUMBER;<br>    inv_cust VARCHAR2(20);<br>    inv_amt NUMBER;<br>BEGIN<br>    <strong>query_str := 'SELECT num, cust, amt FROM inv_' || month ||'_'|| year <br>      || ' WHERE invnum = :id';<\/strong><br>    <strong>OPEN c FOR query_str USING inv_num;<\/strong><br>    LOOP<br>        FETCH c INTO inv_num, inv_cust, inv_amt;<br>        EXIT WHEN c%NOTFOUND;<br>        -- process row here<br>    END LOOP;<br>    CLOSE c;<br>END;<br>\/<\/pre>\n\n\n\n<p>Ref: <a href=\"https:\/\/docs.oracle.com\/cd\/B13789_01\/appdev.101\/b10795\/adfns_dy.htm\">https:\/\/docs.oracle.com\/cd\/B13789_01\/appdev.101\/b10795\/adfns_dy.htm<\/a> <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>cursor FOR loop<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"233\" src=\"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-20.png?resize=385%2C233\" alt=\"\" class=\"wp-image-76599\" style=\"width:788px;height:auto\" srcset=\"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-20.png?w=385 385w, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-20.png?resize=300%2C182 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Cursor For Loop for an Explicit Cursor<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"346\" height=\"298\" src=\"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-21.png?resize=346%2C298\" alt=\"\" class=\"wp-image-76600\" style=\"width:797px;height:auto\" srcset=\"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-21.png?w=346 346w, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/01\/image-21.png?resize=300%2C258 300w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Dynamic\/Ref Cursor CREATE OR REPLACE PROCEDURE query_invoice( month VARCHAR2, year VARCHAR2) IS TYPE cur_typ IS REF CURSOR; c cur_typ; query_str VARCHAR2(200); inv_num NUMBER; inv_cust VARCHAR2(20); inv_amt NUMBER;BEGIN query_str := &#8216;SELECT num, cust, amt FROM inv_&#8217; || month ||&#8217;_&#8217;|| year || &#8216; WHERE invnum = :id&#8217;; OPEN c FOR query_str USING inv_num; LOOP FETCH c INTO &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=76598\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-76598","post","type-post","status-publish","format-standard","hentry","category-root","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":76602,"url":"http:\/\/bangla.sitestree.com\/?p=76602","url_meta":{"origin":76598,"position":0},"title":"Dynamic SQL","author":"Sayed","date":"January 30, 2025","format":false,"excerpt":"\"Dynamic SQL is the SQL statement that is constructed and executed at runtime based on input parameters passed\" https:\/\/www.sqlshack.com\/dynamic-sql-in-sql-server\/ Example: ChatGPT DECLARE @sql AS NVARCHAR(MAX) SET @sql = 'SELECT * FROM Employees WHERE Department = ''' + @department + '''' EXEC sp_executesql @sql Another Example: Oracle table_name := 'HR.Employees'; dyn_sql\u2026","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75827,"url":"http:\/\/bangla.sitestree.com\/?p=75827","url_meta":{"origin":76598,"position":1},"title":"MS SQL Server Dynamic SQl, T-SQL","author":"Sayed","date":"June 25, 2023","format":false,"excerpt":"MS SQL Server Dynamic SQl, T-SQL Mostly: Dynamic SQL Stored Procedure Trigger Cursor Function Sayed Ahmed What are the Most Important Most Used Design ERD Convert ERD to database Normalization Indexing SQL Stored Procedure Dynamic SQL These will come, not too frequent Function, User Defined Data Types, Temporary Table Trigger,\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75975,"url":"http:\/\/bangla.sitestree.com\/?p=75975","url_meta":{"origin":76598,"position":2},"title":"SQL Server: Dynamic SQL, Stored Procedure, Cursor, SQL Injection, and similar","author":"Sayed","date":"April 27, 2024","format":false,"excerpt":"SQL Server: Dynamic SQL, Stored Procedure, Cursor, SQL Injection, and similar https:\/\/youtu.be\/uje72uNAT6I?list=PLUA7SYgJYDFoharKbJxz2Hxw6xQITXvBn","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69249,"url":"http:\/\/bangla.sitestree.com\/?p=69249","url_meta":{"origin":76598,"position":3},"title":"What are cursors? #38","author":"Author-Check- Article-or-Video","date":"August 15, 2021","format":false,"excerpt":"Cursors are server side database objects that are used by applications to apply operations on the database table data on a row-by-row basis. The operations may vary from one row to another row dynamically based on the requirements (business logic) and also multiple operations can be performed on the same\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76047,"url":"http:\/\/bangla.sitestree.com\/?p=76047","url_meta":{"origin":76598,"position":4},"title":"Oracle PL\/SQL: If-Then-Else, For Loop, While Loop","author":"Sayed","date":"May 12, 2024","format":false,"excerpt":"How it works: if, elsif, else (then) (Click on the images to see them clearly) Ref: https:\/\/docs.oracle.com\/cd\/B13789_01\/appdev.101\/b10807\/13_elems024.htm Example: Ref: https:\/\/docs.oracle.com\/cd\/B13789_01\/appdev.101\/b10807\/13_elems024.htm Oracle: CASE, WHEN, THEN Simple: Searched: '' Else: Reverse For Loop Ref: For Loop Examples in Oracle https:\/\/docs.oracle.com\/cd\/E11882_01\/appdev.112\/e25519\/controlstatements.htm#BABEFFDC Oracle While Loop While loop example from the referenced url DECLARE done\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2024\/05\/image-28.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2024\/05\/image-28.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2024\/05\/image-28.png?resize=525%2C300 1.5x"},"classes":[]},{"id":69107,"url":"http:\/\/bangla.sitestree.com\/?p=69107","url_meta":{"origin":76598,"position":5},"title":"MySQL New Features #5","author":"Author-Check- Article-or-Video","date":"August 12, 2021","format":false,"excerpt":"MySQL New Features Cursor Example:CREATE PROCEDURE p25 (OUT return_val INT)BEGINDECLARE a,b INT;DECLARE cur_1 CURSOR FOR SELECT s1 FROM t;DECLARE CONTINUE HANDLER FOR NOT FOUND < --SET b = 1; <--OPEN cur_1;REPEATFETCH cur_1 INTO a;UNTIL b = 1END REPEAT;CLOSE cur_1;SET return_val = a;END;\/\/ Stored procedure in MySQL http:\/\/www.mysqltutorial.org\/stored-procedures-loop.aspx Loop in stored\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76598"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76598\/revisions"}],"predecessor-version":[{"id":76601,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76598\/revisions\/76601"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76598"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}