<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Interview Questions &amp; Answers - SQL Queries Forum				            </title>
            <link>https://sqlqueries.in/community/interview-questions-answers/</link>
            <description>SQL Queries Discussion Board</description>
            <language>en-GB</language>
            <lastBuildDate>Sun, 12 Jul 2026 00:31:20 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Advanced PL/SQL Coding Interview Questions — Asked in Infosys, Accenture &amp; Wipro (2025 Edition)</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/advanced-pl-sql-coding-interview-questions-asked-in-infosys-accenture-wipro-2025-edition/</link>
                        <pubDate>Sun, 09 Nov 2025 06:10:26 +0000</pubDate>
                        <description><![CDATA[In 2025, Infosys, Accenture, and Wipro continue to test Oracle developers with complex PL/SQL coding questions based on real-time performance scenarios, not just syntax.
These questions are...]]></description>
                        <content:encoded><![CDATA[<p data-start="931" data-end="1122">In 2025, <strong data-start="940" data-end="951">Infosys</strong>, <strong data-start="953" data-end="966">Accenture</strong>, and <strong data-start="972" data-end="981">Wipro</strong> continue to test Oracle developers with <strong data-start="1022" data-end="1057">complex PL/SQL coding questions</strong> based on <strong data-start="1067" data-end="1102">real-time performance scenarios</strong>, not just syntax.</p>
<p data-start="1124" data-end="1303">These questions are designed to check your ability to <strong data-start="1178" data-end="1209">write optimized PL/SQL code</strong>, use <strong data-start="1215" data-end="1230">collections</strong>, manage <strong data-start="1239" data-end="1253">exceptions</strong>, and handle <strong data-start="1266" data-end="1300">large data volumes efficiently</strong>.</p>
<p data-start="1305" data-end="1488">If you’re preparing for mid-level or senior Oracle roles, this list of <strong data-start="1376" data-end="1429">advanced PL/SQL interview questions with examples</strong> will help you ace both coding and technical discussions.</p>
<hr data-start="1490" data-end="1493" />
<h3 data-start="1495" data-end="1569">&#x1f539; <strong data-start="1502" data-end="1567">Top Advanced PL/SQL Coding Interview Questions (2025 Edition)</strong></h3>
<h4 data-start="1571" data-end="1652"><strong data-start="1576" data-end="1650">1&#xfe0f;&#x20e3; What is the difference between an Explicit and an Implicit Cursor?</strong></h4>
<p data-start="1653" data-end="1666"><strong data-start="1653" data-end="1664">Answer:</strong></p>
<ul data-start="1667" data-end="1898">
<li data-start="1667" data-end="1799">
<p data-start="1669" data-end="1799"><strong data-start="1669" data-end="1689">Implicit Cursor:</strong> Automatically created by Oracle for single SQL statements like <code data-start="1753" data-end="1761">INSERT</code>, <code data-start="1763" data-end="1771">UPDATE</code>, <code data-start="1773" data-end="1781">DELETE</code>, <code data-start="1783" data-end="1796">SELECT INTO</code>.</p>
</li>
<li data-start="1800" data-end="1898">
<p data-start="1802" data-end="1898"><strong data-start="1802" data-end="1822">Explicit Cursor:</strong> Declared by the developer for queries returning multiple rows.<br data-start="1885" data-end="1888" />Example:</p>
</li>
</ul>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">DECLARE</span>
  <span class="hljs-keyword">CURSOR</span> emp_cur <span class="hljs-keyword">IS</span> <span class="hljs-keyword">SELECT</span> emp_name, salary <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> dept_id <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">FOR</span> rec <span class="hljs-keyword">IN</span> emp_cur LOOP
    DBMS_OUTPUT.PUT_LINE(rec.emp_name <span class="hljs-operator">||</span> <span class="hljs-string">' - '</span> <span class="hljs-operator">||</span> rec.salary);
  <span class="hljs-keyword">END</span> LOOP;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="2109" data-end="2164">&#x2705; <em data-start="2111" data-end="2164">Common in Wipro and Accenture PL/SQL coding rounds.</em></p>
<hr data-start="2166" data-end="2169" />
<h4 data-start="2171" data-end="2236"><strong data-start="2176" data-end="2234">2&#xfe0f;&#x20e3; What is Bulk Collect in PL/SQL and why is it used?</strong></h4>
<p data-start="2237" data-end="2424">Used for <strong data-start="2246" data-end="2273">performance improvement</strong> when fetching multiple rows.<br data-start="2302" data-end="2305" />Instead of fetching one row at a time, <strong data-start="2344" data-end="2360">BULK COLLECT</strong> retrieves data in batches into PL/SQL collections.<br data-start="2411" data-end="2414" />Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">DECLARE</span>
  TYPE emp_tab <span class="hljs-keyword">IS</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">OF</span> employees<span class="hljs-operator">%</span>ROWTYPE;
  v_emp emp_tab;
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> BULK <span class="hljs-keyword">COLLECT</span> <span class="hljs-keyword">INTO</span> v_emp <span class="hljs-keyword">FROM</span> employees;
  <span class="hljs-keyword">FOR</span> i <span class="hljs-keyword">IN</span> <span class="hljs-number">1.</span>.v_emp.COUNT LOOP
    DBMS_OUTPUT.PUT_LINE(v_emp(i).emp_name);
  <span class="hljs-keyword">END</span> LOOP;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="2657" data-end="2716">&#x2705; <em data-start="2659" data-end="2716">Accenture often asks this for large data-load projects.</em></p>
<hr data-start="2718" data-end="2721" />
<h4 data-start="2723" data-end="2793"><strong data-start="2728" data-end="2791">3&#xfe0f;&#x20e3; What is the difference between FORALL and Bulk Collect?</strong></h4>
<div class="_tableContainer_1rjym_1">
<div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse">
<table class="w-fit min-w-(--thread-content-width)" data-start="2794" data-end="3011">
<thead data-start="2794" data-end="2829">
<tr data-start="2794" data-end="2829">
<th data-start="2794" data-end="2804" data-col-size="sm">Feature</th>
<th data-start="2804" data-end="2819" data-col-size="sm">BULK COLLECT</th>
<th data-start="2819" data-end="2829" data-col-size="sm">FORALL</th>
</tr>
</thead>
<tbody data-start="2868" data-end="3011">
<tr data-start="2868" data-end="2942">
<td data-start="2868" data-end="2878" data-col-size="sm">Purpose</td>
<td data-start="2878" data-end="2908" data-col-size="sm">Fetch multiple rows at once</td>
<td data-col-size="sm" data-start="2908" data-end="2942">Execute DML operations in bulk</td>
</tr>
<tr data-start="2943" data-end="3000">
<td data-start="2943" data-end="2954" data-col-size="sm">Used For</td>
<td data-col-size="sm" data-start="2954" data-end="2974">SELECT statements</td>
<td data-col-size="sm" data-start="2974" data-end="3000">INSERT, UPDATE, DELETE</td>
</tr>
<tr data-start="3001" data-end="3011">
<td data-start="3001" data-end="3011" data-col-size="sm">Example:</td>
<td data-col-size="sm"> </td>
<td data-col-size="sm"> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span>FORALL i <span class="hljs-keyword">IN</span> <span class="hljs-number">1.</span>.v_ids.COUNT
  <span class="hljs-keyword">UPDATE</span> employees <span class="hljs-keyword">SET</span> bonus <span class="hljs-operator">=</span> <span class="hljs-number">0.1</span> <span class="hljs-operator">*</span> salary <span class="hljs-keyword">WHERE</span> emp_id <span class="hljs-operator">=</span> v_ids(i);
</span></code></div>
</div>
<p data-start="3119" data-end="3182">&#x1f4cc; <em data-start="3122" data-end="3182">Infosys interviewers focus on this for optimization logic.</em></p>
<hr data-start="3184" data-end="3187" />
<h4 data-start="3189" data-end="3240"><strong data-start="3194" data-end="3238">4&#xfe0f;&#x20e3; Explain Ref Cursors and their types.</strong></h4>
<p data-start="3241" data-end="3316">Ref cursors allow passing cursor results between subprograms dynamically.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">DECLARE</span>
  TYPE emp_ref <span class="hljs-keyword">IS</span> <span class="hljs-keyword">REF</span> <span class="hljs-keyword">CURSOR</span>;
  c1 emp_ref;
  v_name employees.name<span class="hljs-operator">%</span>TYPE;
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">OPEN</span> c1 <span class="hljs-keyword">FOR</span> <span class="hljs-keyword">SELECT</span> name <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> department_id <span class="hljs-operator">=</span> <span class="hljs-number">20</span>;
  LOOP
    <span class="hljs-keyword">FETCH</span> c1 <span class="hljs-keyword">INTO</span> v_name;
    EXIT <span class="hljs-keyword">WHEN</span> c1<span class="hljs-operator">%</span>NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_name);
  <span class="hljs-keyword">END</span> LOOP;
  <span class="hljs-keyword">CLOSE</span> c1;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="3606" data-end="3652">&#x2705; <em data-start="3608" data-end="3650">Common in Infosys advanced coding tests.</em></p>
<hr data-start="3654" data-end="3657" />
<h4 data-start="3659" data-end="3735"><strong data-start="3664" data-end="3733">5&#xfe0f;&#x20e3; How can you handle multiple exceptions in PL/SQL efficiently?</strong></h4>
<p data-start="3736" data-end="3802">Use named and generic exceptions with <code data-start="3774" data-end="3780">WHEN</code> clauses.<br data-start="3789" data-end="3792" />Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">UPDATE</span> employees <span class="hljs-keyword">SET</span> salary <span class="hljs-operator">=</span> salary <span class="hljs-operator">*</span> <span class="hljs-number">1.1</span> <span class="hljs-keyword">WHERE</span> dept_id <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;
EXCEPTION
  <span class="hljs-keyword">WHEN</span> NO_DATA_FOUND <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'No employees found.'</span>);
  <span class="hljs-keyword">WHEN</span> OTHERS <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Error: '</span> <span class="hljs-operator">||</span> SQLERRM);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="4042" data-end="4116">&#x1f4cc; <em data-start="4045" data-end="4116">Accenture often gives a block with errors and asks you to correct it.</em></p>
<hr data-start="4118" data-end="4121" />
<h4 data-start="4123" data-end="4187"><strong data-start="4128" data-end="4185">6&#xfe0f;&#x20e3; What are PL/SQL Collections? Explain their types.</strong></h4>
<ul data-start="4188" data-end="4345">
<li data-start="4188" data-end="4250">
<p data-start="4190" data-end="4250"><strong data-start="4190" data-end="4231">Associative Arrays (INDEX BY tables):</strong> Key-value pairs.</p>
</li>
<li data-start="4251" data-end="4309">
<p data-start="4253" data-end="4309"><strong data-start="4253" data-end="4271">Nested Tables:</strong> Similar to arrays, dynamic in size.</p>
</li>
<li data-start="4310" data-end="4345">
<p data-start="4312" data-end="4345"><strong data-start="4312" data-end="4324">VARRAYs:</strong> Fixed-size arrays.</p>
</li>
</ul>
<p data-start="4347" data-end="4372">Example (Nested Table):</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">DECLARE</span>
  TYPE t_numbers <span class="hljs-keyword">IS</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">OF</span> NUMBER;
  v_nums t_numbers :<span class="hljs-operator">=</span> t_numbers(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>);
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">FOR</span> i <span class="hljs-keyword">IN</span> <span class="hljs-number">1.</span>.v_nums.COUNT LOOP
    DBMS_OUTPUT.PUT_LINE(v_nums(i));
  <span class="hljs-keyword">END</span> LOOP;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="4566" data-end="4632">&#x2705; <em data-start="4568" data-end="4632">Infosys &amp; Wipro focus on associative arrays and nested tables.</em></p>
<hr data-start="4634" data-end="4637" />
<h4 data-start="4639" data-end="4734"><strong data-start="4644" data-end="4732">7&#xfe0f;&#x20e3; What is a Cursor FOR Loop and how is it different from explicit cursor handling?</strong></h4>
<p data-start="4735" data-end="4828">Cursor FOR Loop simplifies cursor management — no need to explicitly open, fetch, or close.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">FOR</span> emp_rec <span class="hljs-keyword">IN</span> (<span class="hljs-keyword">SELECT</span> emp_name <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> dept_id <span class="hljs-operator">=</span> <span class="hljs-number">50</span>)
LOOP
  DBMS_OUTPUT.PUT_LINE(emp_rec.emp_name);
<span class="hljs-keyword">END</span> LOOP;
</span></code></div>
</div>
<p data-start="4964" data-end="5008">&#x1f4cc; <em data-start="4967" data-end="5008">Asked in Accenture intermediate rounds.</em></p>
<hr data-start="5010" data-end="5013" />
<h4 data-start="5015" data-end="5080"><strong data-start="5020" data-end="5078">8&#xfe0f;&#x20e3; Real-Time Scenario: Bulk Update with Error Logging</strong></h4>
<p data-start="5081" data-end="5152"><strong data-start="5081" data-end="5094">Question:</strong> Update employee bonuses in bulk and log failed updates.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">DECLARE</span>
  TYPE id_tab <span class="hljs-keyword">IS</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">OF</span> employees.emp_id<span class="hljs-operator">%</span>TYPE;
  v_ids id_tab :<span class="hljs-operator">=</span> id_tab(<span class="hljs-number">101</span>, <span class="hljs-number">102</span>, <span class="hljs-number">103</span>);
<span class="hljs-keyword">BEGIN</span>
  FORALL i <span class="hljs-keyword">IN</span> <span class="hljs-number">1.</span>.v_ids.COUNT SAVE EXCEPTIONS
    <span class="hljs-keyword">UPDATE</span> employees <span class="hljs-keyword">SET</span> bonus <span class="hljs-operator">=</span> bonus <span class="hljs-operator">+</span> <span class="hljs-number">500</span> <span class="hljs-keyword">WHERE</span> emp_id <span class="hljs-operator">=</span> v_ids(i);
EXCEPTION
  <span class="hljs-keyword">WHEN</span> OTHERS <span class="hljs-keyword">THEN</span>
    <span class="hljs-keyword">FOR</span> i <span class="hljs-keyword">IN</span> <span class="hljs-number">1.</span>.<span class="hljs-keyword">SQL</span><span class="hljs-operator">%</span>BULK_EXCEPTIONS.COUNT LOOP
      <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> error_log <span class="hljs-keyword">VALUES</span>(<span class="hljs-keyword">SQL</span><span class="hljs-operator">%</span>BULK_EXCEPTIONS(i).ERROR_INDEX,
                                   SQLERRM(<span class="hljs-operator">-</span><span class="hljs-keyword">SQL</span><span class="hljs-operator">%</span>BULK_EXCEPTIONS(i).ERROR_CODE),
                                   SYSDATE);
    <span class="hljs-keyword">END</span> LOOP;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="5674" data-end="5721">&#x2705; <em data-start="5676" data-end="5721">Common in Wipro PL/SQL automation projects.</em></p>
<hr data-start="6452" data-end="6455" />
<h3 data-start="6457" data-end="6478">&#x1f4a1; <strong data-start="6464" data-end="6476">Pro Tip:</strong></h3>
<p data-start="6479" data-end="6541">When explaining PL/SQL logic in interviews, add <strong data-start="6527" data-end="6538">context</strong>:</p>
<blockquote data-start="6542" data-end="6670">
<p data-start="6544" data-end="6670">“We implemented bulk updates in a payroll module where performance improved by 60% after using FORALL with SAVE EXCEPTIONS.”</p>
</blockquote>
<p data-start="6672" data-end="6753">This gives a real-world impact — which impresses senior interviewers instantly.</p>
<hr data-start="6755" data-end="6758" />
<h3 data-start="6760" data-end="6783">&#x1f9e9; <strong data-start="6767" data-end="6781">Conclusion</strong></h3>
<p data-start="6784" data-end="6943">These <strong data-start="6790" data-end="6851">Advanced PL/SQL Coding Interview Questions (2025 Edition)</strong> from <strong data-start="6857" data-end="6887">Infosys, Accenture &amp; Wipro</strong> are drawn from actual project-based technical rounds.</p>
<p data-start="6945" data-end="7122">Mastering these topics — <strong data-start="6970" data-end="7056">bulk operations, ref cursors, autonomous transactions, and optimization techniques</strong> — will help you stand out as a top-performing Oracle developer.</p>
<p data-start="7124" data-end="7262">Practice these scenarios regularly on <strong data-start="7162" data-end="7180">Oracle LiveSQL</strong> or <strong data-start="7184" data-end="7201">SQL Developer</strong> to strengthen your command and speed in PL/SQL interviews.</p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/advanced-pl-sql-coding-interview-questions-asked-in-infosys-accenture-wipro-2025-edition/</guid>
                    </item>
				                    <item>
                        <title>PL/SQL Triggers, Packages &amp; Exception Handling — Real-Time Scenario Questions Asked in TCS, HCL &amp; Capgemini (2025 Edition)</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/pl-sql-triggers-packages-exception-handling-real-time-scenario-questions-asked-in-tcs-hcl-capgemini-2025-edition/</link>
                        <pubDate>Sun, 09 Nov 2025 06:08:54 +0000</pubDate>
                        <description><![CDATA[If you’re preparing for PL/SQL interviews at TCS, HCL, or Capgemini, expect questions that go beyond syntax.Recruiters focus on real-time scenarios involving triggers, packages, and exceptio...]]></description>
                        <content:encoded><![CDATA[<p data-start="848" data-end="1119">If you’re preparing for <strong data-start="872" data-end="893">PL/SQL interviews</strong> at <strong data-start="897" data-end="923">TCS, HCL, or Capgemini</strong>, expect questions that go beyond syntax.<br data-start="964" data-end="967" />Recruiters focus on <strong data-start="987" data-end="1010">real-time scenarios</strong> involving <strong data-start="1021" data-end="1067">triggers, packages, and exception handling</strong> — key concepts in every enterprise Oracle system.</p>
<p data-start="1121" data-end="1323">This post brings you <strong data-start="1142" data-end="1175">practical interview questions</strong> directly from developer rounds in 2025, including <strong data-start="1226" data-end="1252">project-based examples</strong> and <strong data-start="1257" data-end="1281">error-handling logic</strong> you can use in production environments.</p>
<hr data-start="1325" data-end="1328" />
<h3 data-start="1330" data-end="1418">&#x1f539; <strong data-start="1337" data-end="1416">Top PL/SQL Triggers, Packages &amp; Exception Handling Questions (2025 Edition)</strong></h3>
<h4 data-start="1420" data-end="1483"><strong data-start="1425" data-end="1481">1&#xfe0f;&#x20e3; What is a Trigger in PL/SQL? When do you use it?</strong></h4>
<p data-start="1484" data-end="1657"><strong data-start="1484" data-end="1495">Answer:</strong><br data-start="1495" data-end="1498" />A <strong data-start="1500" data-end="1511">trigger</strong> is a stored PL/SQL block that automatically executes in response to a database event such as <strong data-start="1605" data-end="1615">INSERT</strong>, <strong data-start="1617" data-end="1627">UPDATE</strong>, or <strong data-start="1632" data-end="1642">DELETE</strong>.<br data-start="1643" data-end="1646" />Used for:</p>
<ul data-start="1658" data-end="1752">
<li data-start="1658" data-end="1683">
<p data-start="1660" data-end="1683">Auditing data changes</p>
</li>
<li data-start="1684" data-end="1712">
<p data-start="1686" data-end="1712">Enforcing business rules</p>
</li>
<li data-start="1713" data-end="1752">
<p data-start="1715" data-end="1752">Automating logging and calculations</p>
</li>
</ul>
<p data-start="1754" data-end="1780">Example (Audit Trigger):</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE <span class="hljs-keyword">TRIGGER</span> trg_audit_salary
AFTER <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">OF</span> salary <span class="hljs-keyword">ON</span> employees
<span class="hljs-keyword">FOR</span> <span class="hljs-keyword">EACH</span> <span class="hljs-type">ROW</span>
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> salary_audit(emp_id, old_sal, new_sal, updated_on)
  <span class="hljs-keyword">VALUES</span>(:OLD.emp_id, :OLD.salary, :NEW.salary, SYSDATE);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="2018" data-end="2084">&#x2705; <em data-start="2020" data-end="2082">Frequently asked in Capgemini production support interviews.</em></p>
<hr data-start="2086" data-end="2089" />
<h4 data-start="2091" data-end="2157"><strong data-start="2096" data-end="2155">2&#xfe0f;&#x20e3; What are the different types of Triggers in Oracle?</strong></h4>
<div class="_tableContainer_1rjym_1">
<div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse">
<table class="w-fit min-w-(--thread-content-width)" data-start="2158" data-end="2506">
<thead data-start="2158" data-end="2190">
<tr data-start="2158" data-end="2190">
<th data-start="2158" data-end="2165" data-col-size="sm">Type</th>
<th data-start="2165" data-end="2179" data-col-size="sm">Description</th>
<th data-start="2179" data-end="2190" data-col-size="sm">Example</th>
</tr>
</thead>
<tbody data-start="2226" data-end="2506">
<tr data-start="2226" data-end="2297">
<td data-start="2226" data-end="2235" data-col-size="sm">BEFORE</td>
<td data-start="2235" data-end="2278" data-col-size="sm">Executes before the triggering statement</td>
<td data-start="2278" data-end="2297" data-col-size="sm">Data validation</td>
</tr>
<tr data-start="2298" data-end="2368">
<td data-start="2298" data-end="2306" data-col-size="sm">AFTER</td>
<td data-start="2306" data-end="2348" data-col-size="sm">Executes after the triggering statement</td>
<td data-start="2348" data-end="2368" data-col-size="sm">Auditing changes</td>
</tr>
<tr data-start="2369" data-end="2431">
<td data-start="2369" data-end="2382" data-col-size="sm">INSTEAD OF</td>
<td data-start="2382" data-end="2400" data-col-size="sm">Used with views</td>
<td data-start="2400" data-end="2431" data-col-size="sm">Modifies data through views</td>
</tr>
<tr data-start="2432" data-end="2506">
<td data-start="2432" data-end="2443" data-col-size="sm">COMPOUND</td>
<td data-start="2443" data-end="2477" data-col-size="sm">Combines multiple timing points</td>
<td data-start="2477" data-end="2506" data-col-size="sm">Used in bulk operations</td>
</tr>
</tbody>
</table>
</div>
</div>
<p data-start="2508" data-end="2572">&#x1f4cc; <em data-start="2511" data-end="2570">TCS often asks for “real use cases” of compound triggers.</em></p>
<hr data-start="2574" data-end="2577" />
<h4 data-start="2579" data-end="2645"><strong data-start="2584" data-end="2643">3&#xfe0f;&#x20e3; Real-Time Scenario: Prevent Negative Salary Updates</strong></h4>
<p data-start="2646" data-end="2729"><strong data-start="2646" data-end="2659">Question:</strong> Create a trigger that prevents updating salary to a negative value.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE <span class="hljs-keyword">TRIGGER</span> trg_check_salary
BEFORE <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">OF</span> salary <span class="hljs-keyword">ON</span> employees
<span class="hljs-keyword">FOR</span> <span class="hljs-keyword">EACH</span> <span class="hljs-type">ROW</span>
<span class="hljs-keyword">BEGIN</span>
  IF :NEW.salary <span class="hljs-operator">&lt;</span> <span class="hljs-number">0</span> <span class="hljs-keyword">THEN</span>
    RAISE_APPLICATION_ERROR(<span class="hljs-number">-20001</span>, <span class="hljs-string">'Salary cannot be negative!'</span>);
  <span class="hljs-keyword">END</span> IF;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="2948" data-end="3007">&#x2705; <em data-start="2950" data-end="3007">Common business rule scenario used in HCL ERP projects.</em></p>
<hr data-start="3009" data-end="3012" />
<h4 data-start="3014" data-end="3069"><strong data-start="3019" data-end="3067">4&#xfe0f;&#x20e3; What is a Package in PL/SQL? Why use it?</strong></h4>
<p data-start="3070" data-end="3244">A <strong data-start="3072" data-end="3083">package</strong> is a collection of logically related PL/SQL objects — such as procedures, functions, variables, and cursors — grouped together for reusability and modularity.</p>
<p data-start="3246" data-end="3256">Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE PACKAGE emp_pkg <span class="hljs-keyword">AS</span>
  <span class="hljs-keyword">PROCEDURE</span> add_employee(p_id NUMBER, p_name VARCHAR2, p_sal NUMBER);
  <span class="hljs-keyword">PROCEDURE</span> get_employee(p_id NUMBER);
<span class="hljs-keyword">END</span> emp_pkg;
</span></code></div>
</div>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE PACKAGE BODY emp_pkg <span class="hljs-keyword">AS</span>
  <span class="hljs-keyword">PROCEDURE</span> add_employee(p_id NUMBER, p_name VARCHAR2, p_sal NUMBER) <span class="hljs-keyword">IS</span>
  <span class="hljs-keyword">BEGIN</span>
    <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> employees <span class="hljs-keyword">VALUES</span>(p_id, p_name, p_sal);
    <span class="hljs-keyword">COMMIT</span>;
  <span class="hljs-keyword">END</span>;

  <span class="hljs-keyword">PROCEDURE</span> get_employee(p_id NUMBER) <span class="hljs-keyword">IS</span>
    v_name employees.name<span class="hljs-operator">%</span>TYPE;
  <span class="hljs-keyword">BEGIN</span>
    <span class="hljs-keyword">SELECT</span> name <span class="hljs-keyword">INTO</span> v_name <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> emp_id <span class="hljs-operator">=</span> p_id;
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Employee: '</span> <span class="hljs-operator">||</span> v_name);
  <span class="hljs-keyword">END</span>;
<span class="hljs-keyword">END</span> emp_pkg;
</span></code></div>
</div>
<p data-start="3851" data-end="3894">&#x2705; <em data-start="3853" data-end="3894">Asked in TCS project design interviews.</em></p>
<hr data-start="3896" data-end="3899" />
<h4 data-start="3901" data-end="3974"><strong data-start="3906" data-end="3972">5&#xfe0f;&#x20e3; What is the difference between a Procedure and a Function?</strong></h4>
<div class="_tableContainer_1rjym_1">
<div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse">
<table class="w-fit min-w-(--thread-content-width)" data-start="3975" data-end="4211">
<thead data-start="3975" data-end="4009">
<tr data-start="3975" data-end="4009">
<th data-start="3975" data-end="3985" data-col-size="sm">Feature</th>
<th data-start="3985" data-end="3997" data-col-size="sm">Procedure</th>
<th data-start="3997" data-end="4009" data-col-size="sm">Function</th>
</tr>
</thead>
<tbody data-start="4048" data-end="4211">
<tr data-start="4048" data-end="4078">
<td data-start="4048" data-end="4066" data-col-size="sm">Returns a value</td>
<td data-start="4066" data-end="4071" data-col-size="sm">No</td>
<td data-start="4071" data-end="4078" data-col-size="sm">Yes</td>
</tr>
<tr data-start="4079" data-end="4105">
<td data-start="4079" data-end="4093" data-col-size="sm">Used in SQL</td>
<td data-start="4093" data-end="4098" data-col-size="sm">No</td>
<td data-start="4098" data-end="4105" data-col-size="sm">Yes</td>
</tr>
<tr data-start="4106" data-end="4163">
<td data-start="4106" data-end="4116" data-col-size="sm">Purpose</td>
<td data-start="4116" data-end="4136" data-col-size="sm">Perform an action</td>
<td data-start="4136" data-end="4163" data-col-size="sm">Compute and return data</td>
</tr>
<tr data-start="4164" data-end="4211">
<td data-start="4164" data-end="4174" data-col-size="sm">Example</td>
<td data-start="4174" data-end="4190" data-col-size="sm">Insert record</td>
<td data-start="4190" data-end="4211" data-col-size="sm">Calculate bonus</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr data-start="4213" data-end="4216" />
<h4 data-start="4218" data-end="4270"><strong data-start="4223" data-end="4268">6&#xfe0f;&#x20e3; What is Exception Handling in PL/SQL?</strong></h4>
<p data-start="4271" data-end="4347">Exception handling lets you gracefully manage runtime errors.<br data-start="4332" data-end="4335" />Structure:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">BEGIN</span>
  <span class="hljs-comment">-- Your logic</span>
EXCEPTION
  <span class="hljs-keyword">WHEN</span> NO_DATA_FOUND <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'No record found!'</span>);
  <span class="hljs-keyword">WHEN</span> ZERO_DIVIDE <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Cannot divide by zero!'</span>);
  <span class="hljs-keyword">WHEN</span> OTHERS <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Unknown error occurred!'</span>);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="4616" data-end="4710">&#x2705; <em data-start="4618" data-end="4710">Capgemini often gives a code snippet and asks you to identify the correct exception block.</em></p>
<hr data-start="4712" data-end="4715" />
<h4 data-start="4717" data-end="4784"><strong data-start="4722" data-end="4782">7&#xfe0f;&#x20e3; Real-Time Scenario: Log Errors in an Exception Table</strong></h4>
<p data-start="4785" data-end="4856"><strong data-start="4785" data-end="4798">Question:</strong> Write code to log errors instead of stopping execution.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> employees <span class="hljs-keyword">VALUES</span> (<span class="hljs-number">101</span>, <span class="hljs-string">'Mark'</span>, <span class="hljs-keyword">NULL</span>);
EXCEPTION
  <span class="hljs-keyword">WHEN</span> OTHERS <span class="hljs-keyword">THEN</span>
    <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> error_log(err_msg, log_date)
    <span class="hljs-keyword">VALUES</span>(SQLERRM, SYSDATE);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="5035" data-end="5083">&#x1f4cc; <em data-start="5038" data-end="5083">Used widely in HCL data migration projects.</em></p>
<hr data-start="5085" data-end="5088" />
<h4 data-start="5090" data-end="5156"><strong data-start="5095" data-end="5154">8&#xfe0f;&#x20e3; What is RAISE_APPLICATION_ERROR and why is it used?</strong></h4>
<p data-start="5157" data-end="5213">Used to define <strong data-start="5172" data-end="5189">custom errors</strong> in PL/SQL.<br data-start="5200" data-end="5203" />Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span>IF v_salary <span class="hljs-operator">&lt;</span> <span class="hljs-number">10000</span> <span class="hljs-keyword">THEN</span>
  RAISE_APPLICATION_ERROR(<span class="hljs-number">-20005</span>, <span class="hljs-string">'Salary below company threshold.'</span>);
<span class="hljs-keyword">END</span> IF;
</span></code></div>
</div>
<p data-start="5328" data-end="5418">&#x2705; <em data-start="5330" data-end="5418">TCS often asks to differentiate between system exceptions and user-defined exceptions.</em></p>
<br /><hr data-start="6161" data-end="6164" />
<h3 data-start="6166" data-end="6187">&#x1f4a1; <strong data-start="6173" data-end="6185">Pro Tip:</strong></h3>
<p data-start="6188" data-end="6256">When explaining PL/SQL logic in interviews, follow this structure:</p>
<blockquote data-start="6257" data-end="6365">
<p data-start="6259" data-end="6365">“I’ll define the business rule → trigger event → package structure → exception handling → optimization.”</p>
</blockquote>
<p data-start="6367" data-end="6470">This stepwise explanation shows <strong data-start="6399" data-end="6422">real-world thinking</strong> — exactly what TCS, HCL &amp; Capgemini look for.</p>
<hr data-start="6472" data-end="6475" />
<h3 data-start="6477" data-end="6500">&#x1f9e9; <strong data-start="6484" data-end="6498">Conclusion</strong></h3>
<p data-start="6501" data-end="6768">These <strong data-start="6507" data-end="6582">PL/SQL triggers, packages &amp; exception handling questions (2025 Edition)</strong> from <strong data-start="6588" data-end="6612">TCS, HCL &amp; Capgemini</strong> are based on <strong data-start="6626" data-end="6653">actual developer rounds</strong>.<br data-start="6654" data-end="6657" />They test your ability to <strong data-start="6683" data-end="6733">write efficient, modular, and error-proof code</strong> — crucial in enterprise systems.</p>
<p data-start="6770" data-end="6938">Focus on explaining <strong data-start="6790" data-end="6804">logic flow</strong> and <strong data-start="6809" data-end="6837">performance improvements</strong> instead of just syntax — that’s what differentiates a <strong data-start="6892" data-end="6919">senior Oracle developer</strong> from a beginner.</p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/pl-sql-triggers-packages-exception-handling-real-time-scenario-questions-asked-in-tcs-hcl-capgemini-2025-edition/</guid>
                    </item>
				                    <item>
                        <title>PL/SQL Interview Questions for Oracle Developer Roles in TCS &amp; Infosys (2025 Edition)</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/pl-sql-interview-questions-for-oracle-developer-roles-in-tcs-infosys-2025-edition/</link>
                        <pubDate>Sun, 09 Nov 2025 05:39:11 +0000</pubDate>
                        <description><![CDATA[If you’re applying for an Oracle Developer role in TCS or Infosys (2025), PL/SQL knowledge is a key differentiator.These real-world interview questions have been compiled from recent candida...]]></description>
                        <content:encoded><![CDATA[<p data-start="671" data-end="951">If you’re applying for an <strong data-start="697" data-end="717">Oracle Developer</strong> role in <strong data-start="726" data-end="751">TCS or Infosys (2025)</strong>, PL/SQL knowledge is a key differentiator.<br data-start="794" data-end="797" />These <strong data-start="803" data-end="837">real-world interview questions</strong> have been compiled from recent candidate experiences and technical rounds conducted by top Indian IT companies.</p>
<p data-start="953" data-end="1107">You’ll find everything from <strong data-start="981" data-end="1029">triggers, procedures, and exception handling</strong> to <strong data-start="1033" data-end="1077">performance tuning and cursor management</strong> — all in one concise guide.</p>
<hr data-start="1109" data-end="1112" />
<h3 data-start="1114" data-end="1182">&#x1f539; <strong data-start="1121" data-end="1180">Top PL/SQL Interview Questions &amp; Answers (2025 Edition)</strong></h3>
<h4 data-start="1184" data-end="1247"><strong data-start="1189" data-end="1245">1&#xfe0f;&#x20e3; What is PL/SQL and how is it different from SQL?</strong></h4>
<p data-start="1248" data-end="1261"><strong data-start="1248" data-end="1259">Answer:</strong></p>
<ul data-start="1262" data-end="1505">
<li data-start="1262" data-end="1328">
<p data-start="1264" data-end="1328"><strong data-start="1264" data-end="1271">SQL</strong> is a query language for interacting with the database.</p>
</li>
<li data-start="1329" data-end="1505">
<p data-start="1331" data-end="1505"><strong data-start="1331" data-end="1341">PL/SQL</strong> (Procedural Language for SQL) adds programming features like loops, conditions, and error handling.<br data-start="1441" data-end="1444" />&#x2705; Used in <strong data-start="1454" data-end="1478">TCS technical rounds</strong> to test your foundation.</p>
</li>
</ul>
<hr data-start="1507" data-end="1510" />
<h4 data-start="1512" data-end="1573"><strong data-start="1517" data-end="1571">2&#xfe0f;&#x20e3; What are the different types of PL/SQL blocks?</strong></h4>
<ol data-start="1574" data-end="1760">
<li data-start="1574" data-end="1624">
<p data-start="1577" data-end="1624"><strong data-start="1577" data-end="1596">Anonymous Block</strong> – unnamed, executed once.</p>
</li>
<li data-start="1625" data-end="1690">
<p data-start="1628" data-end="1690"><strong data-start="1628" data-end="1643">Named Block</strong> – stored as procedure, function, or trigger.</p>
</li>
<li data-start="1691" data-end="1760">
<p data-start="1694" data-end="1760"><strong data-start="1694" data-end="1710">Nested Block</strong> – blocks inside another block for modular code.</p>
</li>
</ol>
<hr data-start="1762" data-end="1765" />
<h4 data-start="1767" data-end="1840"><strong data-start="1772" data-end="1838">3&#xfe0f;&#x20e3; What is the difference between a procedure and a function?</strong></h4>
<div class="_tableContainer_1rjym_1">
<div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse">
<table class="w-fit min-w-(--thread-content-width)" data-start="1841" data-end="2028">
<thead data-start="1841" data-end="1875">
<tr data-start="1841" data-end="1875">
<th data-start="1841" data-end="1851" data-col-size="sm">Feature</th>
<th data-start="1851" data-end="1863" data-col-size="sm">Procedure</th>
<th data-start="1863" data-end="1875" data-col-size="sm">Function</th>
</tr>
</thead>
<tbody data-start="1914" data-end="2028">
<tr data-start="1914" data-end="1942">
<td data-start="1914" data-end="1930" data-col-size="sm">Returns value</td>
<td data-col-size="sm" data-start="1930" data-end="1935">No</td>
<td data-col-size="sm" data-start="1935" data-end="1942">Yes</td>
</tr>
<tr data-start="1943" data-end="1969">
<td data-start="1943" data-end="1957" data-col-size="sm">Used in SQL</td>
<td data-col-size="sm" data-start="1957" data-end="1962">No</td>
<td data-col-size="sm" data-start="1962" data-end="1969">Yes</td>
</tr>
<tr data-start="1970" data-end="2028">
<td data-start="1970" data-end="1980" data-col-size="sm">Purpose</td>
<td data-start="1980" data-end="1997" data-col-size="sm">Perform action</td>
<td data-col-size="sm" data-start="1997" data-end="2028">Return a computation result</td>
</tr>
</tbody>
</table>
</div>
</div>
<p data-start="2030" data-end="2049">Example function:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE <span class="hljs-keyword">FUNCTION</span> get_bonus(sal NUMBER)
<span class="hljs-keyword">RETURN</span> NUMBER <span class="hljs-keyword">AS</span>
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">RETURN</span> sal <span class="hljs-operator">*</span> <span class="hljs-number">0.1</span>;
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<hr data-start="2159" data-end="2162" />
<h4 data-start="2164" data-end="2207"><strong data-start="2169" data-end="2205">4&#xfe0f;&#x20e3; What are triggers in PL/SQL?</strong></h4>
<p data-start="2208" data-end="2343">Triggers are <strong data-start="2221" data-end="2248">special stored programs</strong> that automatically execute when a database event occurs (INSERT, UPDATE, DELETE).<br data-start="2330" data-end="2333" />Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE <span class="hljs-keyword">TRIGGER</span> trg_audit
AFTER <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">ON</span> employees
<span class="hljs-keyword">FOR</span> <span class="hljs-keyword">EACH</span> <span class="hljs-type">ROW</span>
<span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> audit_log(emp_id, created_on)
  <span class="hljs-keyword">VALUES</span>(:NEW.emp_id, SYSDATE);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<p data-start="2517" data-end="2576">&#x2705; <em data-start="2519" data-end="2574">Frequently asked in Infosys project-based interviews.</em></p>
<hr data-start="2578" data-end="2581" />
<h4 data-start="2583" data-end="2635"><strong data-start="2588" data-end="2633">5&#xfe0f;&#x20e3; What is a cursor? What are its types?</strong></h4>
<p data-start="2636" data-end="2689">Cursors are pointers to result sets of SQL queries.</p>
<ul data-start="2690" data-end="2841">
<li data-start="2690" data-end="2757">
<p data-start="2692" data-end="2757"><strong data-start="2692" data-end="2711">Implicit Cursor</strong> – created automatically for simple queries.</p>
</li>
<li data-start="2758" data-end="2841">
<p data-start="2760" data-end="2841"><strong data-start="2760" data-end="2779">Explicit Cursor</strong> – declared by the developer for complex queries.<br data-start="2828" data-end="2831" />Example:</p>
</li>
</ul>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CURSOR</span> emp_cur <span class="hljs-keyword">IS</span> <span class="hljs-keyword">SELECT</span> emp_id, salary <span class="hljs-keyword">FROM</span> employees;
</span></code></div>
</div>
<hr data-start="2910" data-end="2913" />
<h4 data-start="2915" data-end="2969"><strong data-start="2920" data-end="2967">6&#xfe0f;&#x20e3; How do you handle exceptions in PL/SQL?</strong></h4>
<p data-start="2970" data-end="3025">PL/SQL uses the <code data-start="2986" data-end="2997">EXCEPTION</code> block for error handling.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">BEGIN</span>
  <span class="hljs-keyword">SELECT</span> salary <span class="hljs-keyword">INTO</span> v_sal <span class="hljs-keyword">FROM</span> employees <span class="hljs-keyword">WHERE</span> emp_id <span class="hljs-operator">=</span> <span class="hljs-number">100</span>;
EXCEPTION
  <span class="hljs-keyword">WHEN</span> NO_DATA_FOUND <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Employee not found'</span>);
  <span class="hljs-keyword">WHEN</span> OTHERS <span class="hljs-keyword">THEN</span>
    DBMS_OUTPUT.PUT_LINE(<span class="hljs-string">'Error occurred'</span>);
<span class="hljs-keyword">END</span>;
</span></code></div>
</div>
<hr data-start="3258" data-end="3261" />
<h4 data-start="3263" data-end="3328"><strong data-start="3268" data-end="3326">7&#xfe0f;&#x20e3; What is the difference between %TYPE and %ROWTYPE?</strong></h4>
<ul data-start="3329" data-end="3456">
<li data-start="3329" data-end="3389">
<p data-start="3331" data-end="3389"><strong data-start="3331" data-end="3341">%TYPE:</strong> Refers to the data type of a variable/column.</p>
</li>
<li data-start="3390" data-end="3456">
<p data-start="3392" data-end="3456"><strong data-start="3392" data-end="3405">%ROWTYPE:</strong> Represents a complete row of a table.<br data-start="3443" data-end="3446" />Example:</p>
</li>
</ul>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span>v_name employees.name<span class="hljs-operator">%</span>TYPE;  
v_row employees<span class="hljs-operator">%</span>ROWTYPE;
</span></code></div>
</div>
<hr data-start="3524" data-end="3527" />
<h4 data-start="3529" data-end="3583"><strong data-start="3534" data-end="3581">8&#xfe0f;&#x20e3; How can you improve PL/SQL performance?</strong></h4>
<ul data-start="3584" data-end="3756">
<li data-start="3584" data-end="3638">
<p data-start="3586" data-end="3638">Use <strong data-start="3590" data-end="3609">bulk operations</strong> (<code data-start="3611" data-end="3619">FORALL</code>, <code data-start="3621" data-end="3635">BULK COLLECT</code>)</p>
</li>
<li data-start="3639" data-end="3697">
<p data-start="3641" data-end="3697">Avoid too many context switches between SQL and PL/SQL</p>
</li>
<li data-start="3698" data-end="3724">
<p data-start="3700" data-end="3724">Use <strong data-start="3704" data-end="3722">bind variables</strong></p>
</li>
<li data-start="3725" data-end="3756">
<p data-start="3727" data-end="3756">Analyze <strong data-start="3735" data-end="3754">execution plans</strong></p>
</li>
</ul>
<p data-start="3758" data-end="3822">&#x2705; <em data-start="3760" data-end="3822">Asked in both TCS &amp; Infosys performance optimization rounds.</em></p>
<hr data-start="3824" data-end="3827" />
<h4 data-start="3829" data-end="3882"><strong data-start="3834" data-end="3880">9&#xfe0f;&#x20e3; Explain the use of packages in PL/SQL.</strong></h4>
<p data-start="3883" data-end="4012">Packages group related procedures, functions, and variables.<br data-start="3943" data-end="3946" />They improve performance by loading once into memory.<br data-start="3999" data-end="4002" />Example:</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> REPLACE PACKAGE emp_pkg <span class="hljs-keyword">AS</span>
  <span class="hljs-keyword">PROCEDURE</span> get_details(p_id NUMBER);
<span class="hljs-keyword">END</span> emp_pkg;
</span></code></div>
</div>
<hr data-start="4113" data-end="4116" />
<h4 data-start="4118" data-end="4165"><strong data-start="4123" data-end="4163">&#x1f51f; What are autonomous transactions?</strong></h4>
<p data-start="4166" data-end="4267">An <strong data-start="4169" data-end="4195">autonomous transaction</strong> is independent of the main transaction — used in logging or auditing.</p>
<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary">
<div class="sticky top-9">
<div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">
<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-sql"><span>PRAGMA AUTONOMOUS_TRANSACTION;
</span></code></div>
</div>
<p data-start="4310" data-end="4386">Used frequently in <strong data-start="4329" data-end="4364">Infosys finance domain projects</strong> for audit tracking.</p>
<hr data-start="4388" data-end="4391" />
<h3 data-start="4393" data-end="4414">&#x1f4a1; <strong data-start="4400" data-end="4412">Pro Tip:</strong></h3>
<p data-start="4415" data-end="4503">When answering PL/SQL questions, always add a <strong data-start="4461" data-end="4486">real project use-case</strong> — for example:</p>
<blockquote data-start="4504" data-end="4600">
<p data-start="4506" data-end="4600">“We used triggers to maintain a daily audit log for employee record changes in Oracle HRMS.”</p>
</blockquote>
<p data-start="4602" data-end="4650">This adds depth and shows hands-on experience.</p>
<hr data-start="4652" data-end="4655" />
<h3 data-start="4657" data-end="4680">&#x1f9e9; <strong data-start="4664" data-end="4678">Conclusion</strong></h3>
<p data-start="4681" data-end="4987">These <strong data-start="4687" data-end="4744">PL/SQL interview questions for TCS and Infosys (2025)</strong> prepare you for both <strong data-start="4766" data-end="4802">theoretical and practical rounds</strong>.<br data-start="4803" data-end="4806" />Focus on writing clean, optimized, and modular PL/SQL code — as recruiters value <strong data-start="4887" data-end="4904">logic clarity</strong>, <strong data-start="4906" data-end="4931">performance awareness</strong>, and <strong data-start="4937" data-end="4957">debugging skills</strong> more than memorized syntax.</p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/pl-sql-interview-questions-for-oracle-developer-roles-in-tcs-infosys-2025-edition/</guid>
                    </item>
				                    <item>
                        <title>Understanding Loops in PL/SQL with Practical Examples</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/understanding-loops-in-pl-sql-with-practical-examples/</link>
                        <pubDate>Thu, 24 Jul 2025 02:34:25 +0000</pubDate>
                        <description><![CDATA[Understanding Loops in PL/SQL with Practical Examples
Loops are essential in PL/SQL when you want to execute a block of statements repeatedly. They allow you to automate repetitive tasks su...]]></description>
                        <content:encoded><![CDATA[<p><strong>Understanding Loops in PL/SQL with Practical Examples</strong></p>
<p>Loops are essential in PL/SQL when you want to execute a block of statements repeatedly. They allow you to automate repetitive tasks such as processing records, generating sequences, or performing calculations until a condition is met. PL/SQL supports three main types of loops: <strong>Simple Loop</strong>, <strong>WHILE Loop</strong>, and <strong>FOR Loop</strong>.</p>
<hr />
<p><strong>Simple Loop in PL/SQL</strong></p>
<p>A simple loop continues indefinitely until explicitly exited using the <code>EXIT</code> or <code>EXIT WHEN</code> statement.</p>
<pre contenteditable="false"><code class="language-plsql">DECLARE
   counter NUMBER := 1;
BEGIN
   LOOP
      DBMS_OUTPUT.PUT_LINE('Counter = ' || counter);
      counter := counter + 1;
      EXIT WHEN counter &gt; 5;
   END LOOP;
END;
</code></pre>
<p>This loop will print numbers from 1 to 5 and then exit. Use simple loops when the exit condition is inside the loop body.</p>
<hr />
<p><strong>WHILE Loop in PL/SQL</strong></p>
<p>A <code>WHILE</code> loop checks the condition before each iteration. The loop executes only if the condition is <code>TRUE</code>.</p>
<pre contenteditable="false"><code class="language-plsql">DECLARE
   i NUMBER := 1;
BEGIN
   WHILE i &lt;= 5 LOOP
      DBMS_OUTPUT.PUT_LINE('Value = ' || i);
      i := i + 1;
   END LOOP;
END;
</code></pre>
<p>Use the <code>WHILE</code> loop when the number of iterations depends on a condition that can change within the loop.</p>
<hr />
<p><strong>FOR Loop in PL/SQL</strong></p>
<p>A <code>FOR</code> loop is the cleanest way to iterate over a known range of values.</p>
<pre contenteditable="false"><code class="language-plsql">BEGIN
   FOR i IN 1..5 LOOP
      DBMS_OUTPUT.PUT_LINE('i = ' || i);
   END LOOP;
END;
</code></pre>
<p>This is the most readable and concise loop when you know the start and end values in advance.</p>
<hr />
<p><strong>Nested Loops Example</strong></p>
<p>PL/SQL allows nesting loops to handle multi-level operations like matrix processing or combinations:</p>
<pre contenteditable="false"><code class="language-plsql">BEGIN
   FOR i IN 1..3 LOOP
      FOR j IN 1..2 LOOP
         DBMS_OUTPUT.PUT_LINE('i=' || i || ', j=' || j);
      END LOOP;
   END LOOP;
END;
</code></pre>
<p>This will print every combination of <code>i</code> and <code>j</code> values from the nested loop.</p>
<hr />
<p><strong>When to Use Each Loop</strong></p>
<ul>
<li>
<p>Use <strong>Simple Loop</strong> when you need full control over loop execution.</p>
</li>
<li>
<p>Use <strong>WHILE Loop</strong> when the loop depends on a dynamic condition.</p>
</li>
<li>
<p>Use <strong>FOR Loop</strong> when the number of iterations is known or fixed.</p>
</li>
</ul>
<hr />
<p><strong>Common Mistakes to Avoid</strong></p>
<ul>
<li>
<p>Forgetting the <code>EXIT</code> condition in simple loops causes infinite loops.</p>
</li>
<li>
<p>Not updating the counter variable in <code>WHILE</code> loops results in stuck loops.</p>
</li>
<li>
<p>Using loops for operations that can be done with SQL set-based queries can reduce performance.</p>
</li>
</ul>
<hr />
<p><strong>Summary Table</strong></p>
<table>
<thead>
<tr>
<th>Loop Type</th>
<th>Entry Condition</th>
<th>Exit Required</th>
<th>Use Case Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Simple Loop</td>
<td>After execution</td>
<td>Yes</td>
<td>Custom stop condition</td>
</tr>
<tr>
<td>WHILE Loop</td>
<td>Before execution</td>
<td>No</td>
<td>Conditional iteration</td>
</tr>
<tr>
<td>FOR Loop</td>
<td>Automatic range</td>
<td>No</td>
<td>Fixed range of iterations</td>
</tr>
</tbody>
</table>
<p> </p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/understanding-loops-in-pl-sql-with-practical-examples/</guid>
                    </item>
				                    <item>
                        <title>How to Delete Duplicate Records in SQL Without Using ROWID?</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/how-to-delete-duplicate-records-in-sql-without-using-rowid/</link>
                        <pubDate>Thu, 24 Jul 2025 02:18:23 +0000</pubDate>
                        <description><![CDATA[How to Delete Duplicate Records in SQL Without Using ROWID?How can I delete duplicate records from a SQL table without using ROWID or Common Table Expressions?Yes, you can delete duplicate r...]]></description>
                        <content:encoded><![CDATA[<p><br />How to Delete Duplicate Records in SQL Without Using ROWID?<br /><br /><br />How can I delete duplicate records from a SQL table without using ROWID or Common Table Expressions?<br /><br /><br /><br />Yes, you can delete duplicate records from a table even without using `ROWID` or `CTE`. One effective way is by using the `GROUP BY` and `HAVING` clauses along with a temporary table. Here's how:<br /><br />&#x1f501; Step-by-Step Example:<br /><br />Suppose you have a table called `employees`:<br /><br /><br /></p>
<pre contenteditable="false">CREATE TABLE employees (
id INT,
name VARCHAR(50),
department VARCHAR(50)
);</pre>
<p><br /><br /><br />And it has duplicate rows like this:<br /><br />| id | name | department |<br />|----|----------|------------|<br />| 1 | John | HR |<br />| 2 | Alice | IT |<br />| 1 | John | HR |<br />| 3 | Robert | IT |<br /><br /> &#x2705; Method to Delete Duplicates Without ROWID:<br /><br /><br /></p>
<pre contenteditable="false">CREATE TABLE temp_employees AS
SELECT MIN(ROWNUM) as rn, id, name, department
FROM employees
GROUP BY id, name, department;

DELETE FROM employees;

INSERT INTO employees
SELECT id, name, department FROM temp_employees;

DROP TABLE temp_employees;</pre>
<p><br /><br />&#x2705; Alternate Simple Approach (for MySQL):<br /><br /><br /></p>
<pre contenteditable="false">DELETE e1 FROM employees e1
JOIN employees e2
ON e1.id = e2.id AND e1.name = e2.name AND e1.department = e2.department
WHERE e1.ROWID &gt; e2.ROWID;</pre>
<p><br /><br />&#x26a0;&#xfe0f; Note: The above uses `ROWID`, so skip this if you need a non-ROWID version as per requirement.<br /><br /><br /><br /></p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/how-to-delete-duplicate-records-in-sql-without-using-rowid/</guid>
                    </item>
				                    <item>
                        <title>What are Triggers in PL/SQL, and how do they work?</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/what-are-triggers-in-pl-sql-and-how-do-they-work/</link>
                        <pubDate>Sun, 03 Nov 2024 05:32:08 +0000</pubDate>
                        <description><![CDATA[In PL/SQL, a trigger is a stored program that automatically executes in response to specified events on a table or view. Triggers enforce business rules, validate data, and help maintain dat...]]></description>
                        <content:encoded><![CDATA[<div class="flex-shrink-0 flex flex-col relative items-end">
<div>
<div class="pt-0">
<div class="gizmo-bot-avatar flex h-8 w-8 items-center justify-center overflow-hidden rounded-full"> </div>
</div>
</div>
</div>
<div class="group/conversation-turn relative flex w-full min-w-0 flex-col agent-turn">
<div class="flex-col gap-1 md:gap-3">
<div class="flex max-w-full flex-col flex-grow">
<div class="min-h-8 text-message flex w-full flex-col items-end gap-2 whitespace-normal break-words :mt-5" dir="auto" data-message-author-role="assistant" data-message-id="4cf1aa21-f25e-4695-a140-c108e94da494" data-message-model-slug="gpt-4o">
<div class="flex w-full flex-col gap-1 empty:hidden first:pt-">
<div class="markdown prose w-full break-words dark:prose-invert light">
<p> </p>
<p>In PL/SQL, a <strong>trigger</strong> is a stored program that automatically executes in response to specified events on a table or view. Triggers enforce business rules, validate data, and help maintain data integrity within a database. They run automatically when specified events such as <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> occur on the associated table.</p>
<h4><strong>1. Types of Triggers</strong></h4>
<p>Triggers in PL/SQL are categorized based on timing and events:</p>
<ol>
<li>
<p><strong>Timing-Based Triggers</strong>:</p>
<ul>
<li><strong>BEFORE Triggers</strong>: Fire before the triggering event is executed. Commonly used for validating data before making changes.</li>
<li><strong>AFTER Triggers</strong>: Fire after the triggering event is executed. Used for logging or updating related tables.</li>
</ul>
</li>
<li>
<p><strong>Event-Based Triggers</strong>:</p>
<ul>
<li><strong>DML Triggers</strong>: Execute in response to <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> operations.</li>
<li><strong>DDL Triggers</strong>: Fire on Data Definition Language (DDL) events like <code>CREATE</code>, <code>ALTER</code>, or <code>DROP</code>.</li>
<li><strong>Instead-of Triggers</strong>: Used with views to handle <code>DML</code> operations on complex views that cannot be modified directly.</li>
</ul>
</li>
</ol>
<h4><strong>2. Basic Syntax of a Trigger</strong></h4>
<p>A typical trigger structure includes a name, timing, event type, and trigger body.</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">CREATE OR REPLACE TRIGGER trigger_name
BEFORE | AFTER event_type
ON table_name
FOR EACH ROW
BEGIN
    -- Trigger body (code to execute)
END;
</code></div>
</div>
<h4><strong>3. Example of a Trigger</strong></h4>
<p>Suppose we have an <code>employees</code> table, and we want to create a trigger that logs changes to employee salaries:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center"> </div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">CREATE OR REPLACE TRIGGER log_salary_changes
AFTER UPDATE OF salary ON employees
FOR EACH ROW
BEGIN
    INSERT INTO salary_log (employee_id, old_salary, new_salary, change_date)
    VALUES (:OLD.employee_id, :OLD.salary, :NEW.salary, SYSDATE);
END;
</code></div>
</div>
<p><strong>Explanation</strong>:</p>
<ul>
<li><strong>AFTER UPDATE</strong>: The trigger activates after any <code>UPDATE</code> on the <code>salary</code> column.</li>
<li><strong>FOR EACH ROW</strong>: Ensures the trigger runs for each row affected.</li>
<li>
<div> </div>
<strong>and</strong>
<div> </div>
: These are special bind variables. <code>:OLD.salary</code> holds the previous value, while <code>:NEW.salary</code> holds the updated value.</li>
<li><strong>Action</strong>: Inserts a log entry in <code>salary_log</code> with the old and new salary values.</li>
</ul>
<h4><strong>4. Benefits of Using Triggers</strong></h4>
<ul>
<li><strong>Automatic Execution</strong>: Triggers activate without manual intervention, ensuring consistency and data validation in real-time.</li>
<li><strong>Data Integrity</strong>: Enforce complex business rules that cannot be easily handled by constraints.</li>
<li><strong>Audit and Logging</strong>: Track changes to sensitive data for security and compliance.</li>
</ul>
<h4><strong>5. Limitations and Best Practices</strong></h4>
<p>While triggers are powerful, they can lead to complex behavior if not managed carefully.</p>
<ul>
<li><strong>Performance Impact</strong>: Triggers execute automatically and can slow down DML operations if they contain complex logic or interact with other tables.</li>
<li><strong>Debugging Complexity</strong>: Triggers run automatically, which can complicate debugging. Make sure the logic is straightforward and documented.</li>
<li><strong>Avoid Cascading Triggers</strong>: Triggers should not initiate other triggers unnecessarily, as it can lead to unpredictable outcomes and performance issues.</li>
</ul>
<h4><strong>6. Using Conditional Logic in Triggers</strong></h4>
<p>Triggers can include conditional logic to execute different code depending on specific criteria. For example:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center"> </div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">CREATE OR REPLACE TRIGGER check_salary_increase
BEFORE UPDATE OF salary ON employees
FOR EACH ROW
WHEN (NEW.salary &gt; OLD.salary * 1.20)
BEGIN
    RAISE_APPLICATION_ERROR(-20001, 'Salary increase exceeds 20% limit');
END;
</code></div>
</div>
<p>This trigger raises an error if the new salary is more than 20% higher than the old salary, enforcing a business rule.</p>
<hr />
<h4><strong>Conclusion</strong></h4>
<p>PL/SQL triggers provide a robust way to enforce rules, automate audits, and maintain data consistency within Oracle databases. However, overuse or complex triggers can impact performance, so they should be carefully implemented with clear, specific logic. For advanced use cases, consider exploring the <a href="https://docs.oracle.com/en/database/" target="_new" rel="noopener"><span>Oracle</span><span> Trigger</span><span> Documentation</span></a> for more detailed information.</p>
</div>
</div>
</div>
</div>
</div>
</div>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>Vinay Kumar</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/what-are-triggers-in-pl-sql-and-how-do-they-work/</guid>
                    </item>
				                    <item>
                        <title>What are PL/SQL Cursors, and why are they used?</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/what-are-pl-sql-cursors-and-why-are-they-used/</link>
                        <pubDate>Sun, 03 Nov 2024 05:30:42 +0000</pubDate>
                        <description><![CDATA[In PL/SQL, a cursor is a pointer to a context area on the database, which allows you to retrieve and manipulate query results row by row. Cursors are essential in PL/SQL for handling SQL que...]]></description>
                        <content:encoded><![CDATA[<p>In PL/SQL, a <strong>cursor</strong> is a pointer to a context area on the database, which allows you to retrieve and manipulate query results row by row. Cursors are essential in PL/SQL for handling SQL query results, especially when the query returns multiple rows. They help manage the row-by-row processing of data effectively within PL/SQL blocks.</p>
<h4><strong>1. Types of Cursors in PL/SQL</strong></h4>
<p>PL/SQL supports two main types of cursors:</p>
<ol>
<li><strong>Implicit Cursors</strong>: These are automatically created by Oracle when a single-row SQL query (such as <code>SELECT INTO</code>) is executed within PL/SQL. The database handles the cursor internally, so you don’t need to declare or manage it.</li>
<li><strong>Explicit Cursors</strong>: These are defined explicitly by the programmer and are used when you need to process multiple rows from a query. They provide more control over query execution and data processing.</li>
</ol>
<h4><strong>2. Using an Explicit Cursor</strong></h4>
<p>Explicit cursors follow four main steps:</p>
<ol>
<li><strong>Declare the Cursor</strong>: Define the SQL query for the cursor.</li>
<li><strong>Open the Cursor</strong>: Open the cursor to execute the query and establish the context.</li>
<li><strong>Fetch Data</strong>: Retrieve rows one by one using the <code>FETCH</code> command.</li>
<li><strong>Close the Cursor</strong>: Close the cursor to release the context area and free resources.</li>
</ol>
<p>Here’s a basic example of using an explicit cursor to retrieve employee details:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">DECLARE
    CURSOR emp_cursor IS
        SELECT employee_id, name, salary FROM employees WHERE department_id = 10;
    emp_id employees.employee_id%TYPE;
    emp_name employees.name%TYPE;
    emp_salary employees.salary%TYPE;
BEGIN
    OPEN emp_cursor;
    LOOP
        FETCH emp_cursor INTO emp_id, emp_name, emp_salary;
        EXIT WHEN emp_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE('ID: ' || emp_id || ' Name: ' || emp_name || ' Salary: ' || emp_salary);
    END LOOP;
    CLOSE emp_cursor;
END;
</code></div>
</div>
<p><em>Explanation:</em></p>
<ul>
<li><strong>Declare</strong>: The <code>emp_cursor</code> cursor is defined with a query selecting employees from a specific department.</li>
<li><strong>Open</strong>: The cursor is opened, executing the query and setting up the result context.</li>
<li><strong>Fetch</strong>: Each row is fetched in the loop, assigning data to the variables.</li>
<li><strong>Close</strong>: The cursor is closed once all rows are processed, freeing resources.</li>
</ul>
<h4><strong>3. Cursor Attributes</strong></h4>
<p>Cursors have built-in attributes that provide information about query execution:</p>
<ul>
<li><strong>%FOUND</strong>: Returns <code>TRUE</code> if the last fetch returned a row, else <code>FALSE</code>.</li>
<li><strong>%NOTFOUND</strong>: Returns <code>TRUE</code> if the last fetch did not return a row.</li>
<li><strong>%ROWCOUNT</strong>: Returns the number of rows fetched so far.</li>
<li><strong>%ISOPEN</strong>: Returns <code>TRUE</code> if the cursor is open.</li>
</ul>
<p>Using attributes can help manage cursor processing more effectively.</p>
<h4><strong>4. Benefits of Using Cursors</strong></h4>
<ul>
<li><strong>Efficient Data Handling</strong>: Allows row-by-row processing, which is useful for operations requiring sequential data handling.</li>
<li><strong>Flexibility in Data Retrieval</strong>: Provides granular control over query execution and allows custom processing for each row.</li>
<li><strong>Memory Management</strong>: Explicitly closing cursors helps manage memory usage effectively.</li>
</ul>
<h4><strong>5. Implicit vs. Explicit Cursors</strong></h4>
<ul>
<li><strong>Implicit Cursors</strong>: Simpler and automatic but limited to single-row operations. Ideal for quick <code>SELECT INTO</code> operations.</li>
<li><strong>Explicit Cursors</strong>: Offer greater control, supporting multi-row processing and suitable for complex data handling scenarios.</li>
</ul>
<hr />
<h4><strong>Conclusion</strong></h4>
<p>PL/SQL cursors are essential for row-wise data processing in database operations. While implicit cursors are automatically managed for simple queries, explicit cursors provide full control over multi-row data handling. Using explicit cursors along with cursor attributes like <code>%FOUND</code> and <code>%ROWCOUNT</code> enables efficient and flexible data retrieval in PL/SQL. For further insights, check out the <a href="https://docs.oracle.com/en/database/" target="_new" rel="noopener"><span>Oracle</span><span> Cursor</span><span> Documentation</span></a> for advanced cursor techniques.</p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>Vinay Kumar</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/what-are-pl-sql-cursors-and-why-are-they-used/</guid>
                    </item>
				                    <item>
                        <title>What is a PL/SQL Block, and how is it structured?</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/what-is-a-pl-sql-block-and-how-is-it-structured/</link>
                        <pubDate>Sun, 03 Nov 2024 05:29:40 +0000</pubDate>
                        <description><![CDATA[In PL/SQL, code is organized into blocks that allow for modular, structured programming. A PL/SQL block is a unit of code that encapsulates SQL and procedural statements, making it easy to d...]]></description>
                        <content:encoded><![CDATA[<div class="flex-shrink-0 flex flex-col relative items-end">
<div>
<div class="pt-0">
<div class="gizmo-bot-avatar flex h-8 w-8 items-center justify-center overflow-hidden rounded-full">
<div class="relative p-1 rounded-sm flex items-center justify-center bg-token-main-surface-primary text-token-text-primary h-8 w-8"> </div>
</div>
</div>
</div>
</div>
<div class="group/conversation-turn relative flex w-full min-w-0 flex-col agent-turn">
<div class="flex-col gap-1 md:gap-3">
<div class="flex max-w-full flex-col flex-grow">
<div class="min-h-8 text-message flex w-full flex-col items-end gap-2 whitespace-normal break-words :mt-5" dir="auto" data-message-author-role="assistant" data-message-id="b0976759-546e-4478-83b7-eb63f1a04e80" data-message-model-slug="gpt-4o">
<div class="flex w-full flex-col gap-1 empty:hidden first:pt-">
<div class="markdown prose w-full break-words dark:prose-invert light">
<p>In PL/SQL, code is organized into <strong>blocks</strong> that allow for modular, structured programming. A PL/SQL block is a unit of code that encapsulates SQL and procedural statements, making it easy to develop and manage database logic. PL/SQL blocks are foundational in creating stored procedures, functions, triggers, and anonymous blocks.</p>
<h4><strong>1. Structure of a PL/SQL Block</strong></h4>
<p>A PL/SQL block consists of three main sections:</p>
<ol>
<li><strong>Declaration Section</strong>: This is optional and is used to declare variables, constants, and other elements used in the block.</li>
<li><strong>Executable Section</strong>: This is the required part where the code logic is implemented. It contains SQL statements, conditional checks, loops, and function calls.</li>
<li><strong>Exception Section</strong>: This is also optional and handles errors that might occur in the executable section, preventing abrupt termination.</li>
</ol>
<p>Here’s the basic syntax of a PL/SQL block:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary"> </div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">DECLARE
    -- Declaration section (optional)
    variable_name datatype;
BEGIN
    -- Executable section (mandatory)
    NULL; -- Placeholder for executable statements
EXCEPTION
    -- Exception section (optional)
    WHEN others THEN
        -- Handle exceptions here
END;
</code></div>
</div>
<h4><strong>2. Example of a PL/SQL Block</strong></h4>
<p>Consider a simple example where we calculate a bonus for an employee and handle potential errors.</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary">plsql</div>
<div class="sticky top-9 md:top-">
<div class="absolute bottom-0 right-2 flex h-9 items-center"> </div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-plsql">DECLARE
    salary NUMBER := 5000;
    bonus NUMBER;
BEGIN
    -- Calculate bonus
    bonus := salary * 0.1;
    DBMS_OUTPUT.PUT_LINE('Bonus: ' || bonus);
EXCEPTION
    WHEN ZERO_DIVIDE THEN
        DBMS_OUTPUT.PUT_LINE('Error: Division by zero');
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('An unknown error occurred');
END;
</code></div>
</div>
<p>In this example:</p>
<ul>
<li><strong>Declaration Section</strong>: Defines <code>salary</code> and <code>bonus</code> variables.</li>
<li><strong>Executable Section</strong>: Calculates a 10% bonus based on <code>salary</code> and outputs the result.</li>
<li><strong>Exception Section</strong>: Catches any errors, such as division by zero, and outputs an error message.</li>
</ul>
<h4><strong>3. Types of PL/SQL Blocks</strong></h4>
<p>PL/SQL blocks can be:</p>
<ul>
<li><strong>Anonymous Blocks</strong>: These blocks aren’t saved in the database. They are often used for quick, ad-hoc tasks or testing.</li>
<li><strong>Named Blocks</strong>: These are stored in the database as subprograms like <strong>procedures</strong>, <strong>functions</strong>, <strong>packages</strong>, and <strong>triggers</strong>.</li>
</ul>
<h4><strong>4. Benefits of PL/SQL Blocks</strong></h4>
<p>Using PL/SQL blocks provides multiple benefits:</p>
<ul>
<li><strong>Modularity</strong>: Allows complex code to be divided into smaller, manageable units.</li>
<li><strong>Error Handling</strong>: Exception handling within blocks helps manage errors effectively.</li>
<li><strong>Efficiency</strong>: Minimizes network traffic by grouping SQL statements and logic within a single block, especially beneficial for stored procedures and functions.</li>
</ul>
<h4><strong>5. Scope of Variables in PL/SQL Blocks</strong></h4>
<p>Variables declared in the declaration section of a PL/SQL block are only available within that block. If a block is nested within another, it can access variables from the outer block unless variables of the same name are declared in the inner block.</p>
<hr />
<h4><strong>Conclusion</strong></h4>
<p>Understanding the structure of PL/SQL blocks is essential for writing organized, error-resistant database logic. Each block consists of declaration, executable, and optional exception sections, enabling modular and maintainable coding practices. Whether working with anonymous or named blocks, PL/SQL's block structure enhances code readability and error handling, making it an essential tool for database developers.</p>
<p>For a more detailed guide on PL/SQL blocks, see <a href="https://docs.oracle.com/en/database/" target="_new" rel="noopener"><span>Oracle’s</span><span> PL</span><span>/SQL</span><span> Documentation</span></a>.</p>
</div>
</div>
</div>
</div>
</div>
</div>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>Vinay Kumar</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/what-is-a-pl-sql-block-and-how-is-it-structured/</guid>
                    </item>
				                    <item>
                        <title>Query Optimization: A Comprehensive Guide for Stored Procedures</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/query-optimization-a-comprehensive-guide-for-stored-procedures/</link>
                        <pubDate>Wed, 12 Jul 2023 03:38:16 +0000</pubDate>
                        <description><![CDATA[Query Optimization: A Comprehensive Guide for Stored ProceduresIntroduction:As a beginner in query optimization, understanding how to optimize stored procedures (SPs) can greatly enhance the...]]></description>
                        <content:encoded><![CDATA[<p>Query Optimization: A Comprehensive Guide for Stored Procedures<br /><br /><strong>Introduction</strong>:<br />As a beginner in query optimization, understanding how to optimize stored procedures (SPs) can greatly enhance the performance of your SQL queries. This comprehensive guide will take you from the basics to advanced techniques, equipping you with the knowledge and examples needed to effectively optimize SPs and eliminate expensive code.<br /><br /><strong>1. Microsoft SQL Server Documentation</strong>:<br />The  https://docs.microsoft.com/en-us/sql/relational-databases/performance/query-tuning-concepts?view=sql-server-ver15 provides valuable insights into query tuning and optimization concepts. Gain a deeper understanding of query execution plans, index optimization, statistics, and more. Explore real-world examples and learn practical tips to improve the efficiency of your SPs.<br /><br /><strong>2. MySQL Documentation</strong>:<br /> https://dev.mysql.com/doc/refman/8.0/en/query-optimization.html on optimizing SQL queries encompasses SP optimization as well. Uncover the intricacies of indexing, query execution plans, and query analysis. Discover techniques to enhance performance and ensure your SPs run smoothly.<br /><br /><strong>3. Oracle Documentation</strong>:<br /> https://docs.oracle.com/en/database/oracle/oracle-database/19/tgsql/optimizing-SQL.html includes a dedicated section on optimizing SQL statements, which can be directly applied to optimizing SPs. Delve into advanced topics such as optimizing joins, leveraging indexing effectively, and utilizing hints. Acquire the expertise to fine-tune your SPs for optimal performance.<br /><br /><strong>4. PostgreSQL Documentation</strong>:<br />In the  https://www.postgresql.org/docs/current/performance-tips.html , you'll find a section dedicated to performance tips, providing valuable insights for optimizing SQL queries and SPs. Understand query planning, index optimization, and key configuration parameters. Implement these techniques to significantly boost the efficiency of your SPs.<br /><br /><strong>5. SQL Server Central:</strong><br />Join the thriving  https://www.sqlservercentral.com/articles/query-optimization , where SQL professionals converge. Access an extensive collection of articles, tutorials, and examples specifically focused on query optimization. Benefit from practical insights, expert advice, and real-world scenarios to tackle the challenges of optimizing your SPs.<br /><br /><strong>Conclusion</strong>:<br />Query optimization is a critical skill that empowers you to improve the performance of your SPs. By exploring the resources mentioned above and applying the techniques they offer, you'll gain the expertise needed to identify and resolve performance bottlenecks within your SPs. Remember, practice and experimentation are key to mastering the art of query optimization. Start optimizing your SPs today and experience significant performance improvements.<br /><br /></p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>SQL Admin</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/query-optimization-a-comprehensive-guide-for-stored-procedures/</guid>
                    </item>
				                    <item>
                        <title>Displaying Unique Names and Branches of Students using a PL/SQL Cursor</title>
                        <link>https://sqlqueries.in/community/interview-questions-answers/displaying-unique-names-and-branches-of-students-using-a-pl-sql-cursor/</link>
                        <pubDate>Fri, 16 Jun 2023 13:35:14 +0000</pubDate>
                        <description><![CDATA[Displaying Unique Names and Branches of Students using a PL/SQL CursorIntroduction:
In this article, we will explore how to use a PL/SQL cursor to retrieve and display unique names and bran...]]></description>
                        <content:encoded><![CDATA[<p>Displaying Unique Names and Branches of Students using a PL/SQL Cursor<br /><br /><span style="text-decoration: underline"><strong><span style="font-size: 12pt">Introduction:</span></strong></span></p>
<p><br />In this article, we will explore how to use a PL/SQL cursor to retrieve and display unique names and branches of all the students in the STUDENT relation. This approach will ensure that the information presented is distinct, providing a comprehensive overview of the student population. By leveraging PL/SQL, we can efficiently retrieve the data and present it in a user-friendly manner. Let's dive into the code and optimize it for SEO to increase the chances of ranking higher on Google.<br /><br />---<br /><br /><span style="text-decoration: underline"><span style="font-size: 12pt"><strong>Section 1: Setting up the Environment</strong></span></span><br />To get started, we need to ensure that the necessary database environment is set up. This includes creating the required tables, such as the STUDENT relation, which should contain columns for names and branches.<br /><br />Section 2: Writing the PL/SQL Code<br />In this section, we will write the PL/SQL code that fetches the unique names and branches of all the students using a cursor. Let's take a look at the code snippet below:<br /><br /></p>
<pre contenteditable="false">```sql
DECLARE
CURSOR student_cursor IS
SELECT DISTINCT name, branch
FROM STUDENT;
student_record student_cursor%ROWTYPE;
BEGIN
OPEN student_cursor;
LOOP
FETCH student_cursor INTO student_record;
EXIT WHEN student_cursor%NOTFOUND;
-- Display student name and branch here
DBMS_OUTPUT.PUT_LINE('Name: ' || student_record.name || ', Branch: ' || student_record.branch);
END LOOP;
CLOSE student_cursor;
END;
/
```</pre>
<p><br /><br />Section 3: Understanding the Code<br />Now, let's break down the code and understand how it works:<br /><br />- We declare a cursor called `student_cursor` to select distinct names and branches from the STUDENT table.<br />- The `student_record` variable is defined using the `%ROWTYPE` attribute of the cursor, which represents a row of the STUDENT table.<br />- We open the cursor using the `OPEN` statement to initialize the cursor.<br />- Inside the loop, we fetch the data from the cursor into the `student_record` variable.<br />- The loop continues until there are no more records to fetch (`EXIT WHEN student_cursor%NOTFOUND`).<br />- Within the loop, we display the student's name and branch using the `DBMS_OUTPUT.PUT_LINE` function.<br /><br />Section 4: Optimizing for SEO<br />To improve the chances of ranking higher on Google and making the article SEO-friendly, we can follow these best practices:<br /><br />1. Title Tag: Ensure that the title of the article includes relevant keywords, such as "PL/SQL cursor," "students," and "names and branches." For example, "PL/SQL Cursor: Display Unique Student Names and Branches from STUDENT Relation."<br /><br />2. Meta Description: Craft a concise and informative meta description that accurately summarizes the article's content. Include relevant keywords to attract search engine users.<br /><br />3. Heading Tags: Use heading tags (H1, H2, H3, etc.) to structure the article. The main heading (H1) should include the target keywords and provide a clear overview of the topic.<br /><br />4. Keyword Placement: Incorporate relevant keywords naturally throughout the article, including in subheadings, the introduction, and the conclusion. Avoid keyword stuffing, as it can negatively impact readability and search rankings.<br /><br />5. Quality Content: Provide valuable and comprehensive information about using PL/SQL cursors to display unique student names and branches. Ensure the article is well-researched, insightful, and offers practical examples.<br /><br />6. Images and Alt Text: Include relevant images, such as screenshots of code snippets or visual representations of the STUDENT relation. Optimize image filenames and provide descriptive alt text for accessibility and SEO benefits.<br /><br /><br /></p>]]></content:encoded>
						                            <category domain="https://sqlqueries.in/community/interview-questions-answers/">Interview Questions &amp; Answers</category>                        <dc:creator>Ramesh123</dc:creator>
                        <guid isPermaLink="true">https://sqlqueries.in/community/interview-questions-answers/displaying-unique-names-and-branches-of-students-using-a-pl-sql-cursor/</guid>
                    </item>
							        </channel>
        </rss>
		