﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Bert Scalzo's Blog</title>
    <description>&lt;table&gt;
        &lt;tr&gt;
            &lt;td valign="top"&gt;&lt;img height="183" alt="" width="139" src="/Portals/0/Blog/blog-bert-scalzo.png" /&gt;&lt;/td&gt;
            &lt;td valign="top"&gt;Bert Scalzo is a product architect for Quest Software,&amp;#160;a member of the Toad team and an &lt;a href="http://www.oracle.com/technology/community/oracle_ace/index.html"&gt;Oracle ACE&lt;/a&gt;. He has worked with Oracle databases for over two decades; his key areas of interest are data modeling, database benchmarking, tuning and optimization, "Star Schema" data warehouses and Linux. Bert is the author of several books and has written articles for many online outlets and publications,&amp;#160;and has presented at numerous Oracle conferences and user groups.
            &lt;p&gt;Bert's blog provides useful Toad “how to” and “tips and tricks” covering topics on database admin and benchmarking.&lt;/p&gt;
            &lt;p&gt;&lt;font color="#003366" size="3"&gt;&lt;strong&gt;Recent postings:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
&lt;/table&gt;</description>
    <link>http://toadworld.com/BLOGS/tabid/67/BlogId/14/Default.aspx</link>
    <language>en-US</language>
    <managingEditor>Bert Scalzo</managingEditor>
    <webMaster>webmaster@toadworld.com</webMaster>
    <pubDate>Fri, 19 Mar 2010 01:49:12 GMT</pubDate>
    <lastBuildDate>Fri, 19 Mar 2010 01:49:12 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.2.0.15477</generator>
    <item>
      <title>Only Toad can debug SQL Scripts</title>
      <description>&lt;div&gt;I have been doing Oracle work for just over two decades – and I’ve probably written thousands of SQL scripts. Many of those were DBA oriented in their task nature, but even application development presents times where SQL scripts are used. For example, the need may arise for the operating systems’ or third party schedulers to invoke a shell script to execute a SQL script to execute some PL/SQL code.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Historically while developing such scripts, there were no tools for debugging them – other than printing with DBMS_OUTPUT. SQL*Plus back then, nor SQL Developer now, offers the same debugging capability for SQL scripts that PL/SQL programmers have become accustomed. But years ago Toad rectified that situation – yet not too many people know about or leverage this one-of-a-kind functionality.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Let use my Dynamic SQL script &lt;a href="http://www.toadworld.com/Community/QuestExpertsBlogs/tabid/67/EntryID/247/Default.aspx"&gt;from last week’s blog&lt;/a&gt; as an example.&lt;/div&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;pre&gt;-- ri_off.sql&lt;br /&gt;set pagesize 0&lt;br /&gt;set feedback off&lt;br /&gt;set term off&lt;br /&gt;spool c:\temp\ri_off.tmp&lt;br /&gt;select 'alter table '||owner||'.'||table_name||' disable constraint &lt;br /&gt;'||constraint_name||';'&lt;br /&gt; from user_constraints&lt;br /&gt; where constraint_type = 'R'&lt;br /&gt; and status = 'ENABLED';&lt;br /&gt;spool off&lt;br /&gt;set term on&lt;br /&gt;set feedback on&lt;br /&gt;set echo on&lt;br /&gt;@c:\temp\ri_off.tmp&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;When first developing this script, how can I verify what’s going on inside – before actually doing the last step and running its output. Of course the obvious answer is to comment out the very last line and then visually inspect the temporary file’s generated code for correctness. But what if I needed to peak under the covers and see both how and why the results came out the way they did. That’s where Toad’s script debugger comes into play.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;First I load the script into the editor and turn on the SQL script debugger as shown here.&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;&lt;img height="562" alt="" width="700" src="http://toadworld.com/Portals/0/blogimages/BertBlog07162008-1.gif" /&gt;&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;After that you’ll see how the editor’s toolbar icons for debugging are now enabled, as highlighted here.&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;&lt;img height="421" alt="" width="627" src="http://toadworld.com/Portals/0/blogimages/BertBlog07162008-2.gif" /&gt;&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;Now we can step through our SQL script code just like we can in Toad’s PL/SQL debugger. First let’s update the sample code so I can show something of value. I’ve added two lines as shown here so that I have something to examine in the debugger (namely, I want to see the value of the var_xxx variable.&lt;/div&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;pre&gt;-- ri_off.sql&lt;br /&gt;set pagesize 0&lt;br /&gt;set feedback off&lt;br /&gt;set term off&lt;br /&gt;&lt;font style="BACKGROUND-COLOR: #ffff00"&gt;COLUMN xxx NOPRINT new_value var_xxx;&lt;br /&gt;SELECT count(*) as xxx from all_users;&lt;/font&gt;&lt;br /&gt;spool c:\temp\ri_off.tmp&lt;br /&gt;select 'alter table '||owner||'.'||table_name||' disable constraint &lt;br /&gt;'||constraint_name||';'&lt;br /&gt; from user_constraints&lt;br /&gt; where constraint_type = 'R'&lt;br /&gt; and status = 'ENABLED';&lt;br /&gt;spool off&lt;br /&gt;set term on&lt;br /&gt;set feedback on&lt;br /&gt;set echo on&lt;br /&gt;--@c:\temp\ri_off.tmp&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;So now I can set a break on line 8, run the script to that point, and examine my variables as shown here. Only Toad offers this unique capability – and it’s too darn useful not to take advantage of &lt;span&gt;&lt;font face="Wingdings"&gt;J&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;img height="422" alt="" width="626" src="http://toadworld.com/Portals/0/blogimages/BertBlog07162008-3.gif" /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;</description>
      <link>http://toadworld.com/BLOGS/tabid/67/EntryID/249/Default.aspx</link>
      <author>Bert Scalzo</author>
      <comments>http://toadworld.com/BLOGS/tabid/67/EntryID/249/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://toadworld.com/Default.aspx?tabid=67&amp;EntryID=249</guid>
      <pubDate>Wed, 16 Jul 2008 11:45:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://toadworld.com/DesktopModules/Blog/Trackback.aspx?id=249</trackback:ping>
    </item>
  </channel>
</rss>