Debugging PL/SQL

I am using Toad for Oracle. Is there any way within PL/SQL code to define a section or block of code as code that should only run when you are debugging PL/SQL procedures/functions?

I think the OP wants something more like this (tested in 11g, should work from 10.2 onwards if I remember correctly):
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create or replace procedure procedurewithdebug
  2  as
  3  begin
  4      dbms_output.put_line('Start of procedure');
  5
  6      $if $$debug $then
  7          dbms_output.put_line('Extra code section only called when $$debug is TRUE');
  8      $end
  9
10      dbms_output.put_line('End of procedure');
11  end procedurewithdebug;
12  /
Procedure created.
SQL> set serverout on
SQL> exec procedurewithdebug
Start of procedure
End of procedure
PL/SQL procedure successfully completed.
SQL> call dbms_preprocessor.print_post_processed_source('PROCEDURE','WILLIAM','PROCEDUREWITHDEBUG');
procedure procedurewithdebug
as
begin
dbms_output.put_line('Start of procedure');
dbms_output.put_line('End of procedure');
end procedurewithdebug;
Call completed.
SQL> alter session set plsql_ccflags = 'debug:true';
Session altered.
SQL> alter procedure procedurewithdebug compile;
Procedure altered.
SQL> exec procedurewithdebug
Start of procedure
Extra code section only called when $$debug is TRUE
End of procedure
PL/SQL procedure successfully completed.
SQL> call dbms_preprocessor.print_post_processed_source('PROCEDURE','WILLIAM','PROCEDUREWITHDEBUG');
procedure procedurewithdebug
as
begin
dbms_output.put_line('Start of procedure');
dbms_output.put_line('Extra code section only called when $$debug is TRUE');
dbms_output.put_line('End of procedure');
end procedurewithdebug;
Call completed.
SQL> alter session set plsql_ccflags = 'debug:false';
Session altered.
SQL>
SQL> alter procedure procedurewithdebug compile;
Procedure altered.
SQL> exec procedurewithdebug
Start of procedure
End of procedure
PL/SQL procedure successfully completed.Note this does not automatically detect whether a procedure is compiled for debug - you have to set a compilation directive explicitly. (There is nothing special about '$$debug' either - I could have used '$$banana'.)
As a variation, you can also use package constants:
SQL> create or replace package environment_settings
  2  as
  3      debug constant boolean := TRUE;
  4  end environment_settings;
  5  /
Package created.
SQL> create or replace procedure procedurewithdebug
  2  as
  3  begin
  4      dbms_output.put_line('Start of procedure');
  5
  6      $if environment_settings.debug $then
  7          dbms_output.put_line('Extra code section only called when environment_settings.debug is TRUE');
  8      $end
  9
10      dbms_output.put_line('End of procedure');
11  end procedurewithdebug;
12  /
Procedure created.
SQL> exec procedurewithdebug
Start of procedure
Extra code section only called when environment_settings.debug is TRUE
End of procedure
PL/SQL procedure successfully completed.
SQL> create or replace package environment_settings
  2  as
  3      debug constant boolean := FALSE;
  4  end environment_settings;
  5  /
Package created.
SQL> exec procedurewithdebug
Start of procedure
End of procedure
PL/SQL procedure successfully completed.Note that PL/SQL isn't just skipping the line like an ordinary IF statement, the PL/SQL compiler is actually excluding the section at compile time:
SQL> call dbms_preprocessor.print_post_processed_source('PROCEDURE','WILLIAM','PROCEDUREWITHDEBUG');
procedure procedurewithdebug
as
begin
dbms_output.put_line('Start of procedure');
dbms_output.put_line('End of procedure');
end procedurewithdebug;
Call completed.Edited by: William Robertson on Mar 26, 2009 7:18 AM

Similar Messages

  • I cannot debug with SQL server 2008 SSMS asks for Firewall permission?

    hi friends,
    I run SQL server 2008 R2 developer edition on windows 8 basic edition. SQL server is installed in my local machine. when I tried to debug a sql script it asked the firewall permission as show on image
    when googled I found this
    Article from MSDN with fix tool but it cannot installed on my Windows 8 OS, is there way to fix it without giving any unauthorized access to my system?
    thanks
    I use Visual studio 2012 Ultimate and SQL server 2008 developer edition!

    Hi,
    The hotfix you provide applies for Windows Server 2008.
    The windows firewall on this machine is currently blocking remote debugging.
    According the message, the following ports need to be enabled for remote debugging. Use the procedure that is described in the section
    Configuring a Port in Windows Firewall to enable the following ports through Windows Firewall:
    Ports
    Protocol
    135
    TCP
    Required
    500, 4500
    UDP
    Required if your domain policy requires   network communication to be performed through IPSec.
    See the below article for more information:
    How to: Enable Transact-SQL Debugging
    http://msdn.microsoft.com/en-us/library/vstudio/s0fk6z6e(v=vs.100).aspx
    Thanks.
    Tracy Cai
    TechNet Community Support

  • Probs Debugging PL/SQL proc JDev903

    Im trying to debug PL/SQL functions in JDeveloper 9.0.3.
    Issue N1. In Run PL/SQL window JDev adds schema name to my function and PL/SQL block fails to compile. Im manually deleting prefix from my function and block is compiled successfully.
    Then an error happened: PLS-00302: component 'JDEV_TMP_PROC_1' must be declared
    Please advice
    Debugger attempting to connect to database.
    Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
    Executing PL/SQL: DECLARE
    id VARCHAR2( 30 );
    BEGIN
    id := DBMS_DEBUG.initialize( '24.27.75.30:1036303964414', 1 );
    DBMS_DEBUG.debug_on( TRUE );
    END;
    Debugger connected to database.
    Deadlock detection is not supported by the debuggee virtual machine.
    Executing PL/SQL: BEGIN MY_SCHEMA."JDEV_TMP_PROC_1"(); END;
    ORA-06550: line 1, column 11:
    PLS-00302: component 'JDEV_TMP_PROC_1' must be declared
    ORA-06550: line 1, column 7:

    JDev can debug with Oracle 8.1.7 or later.
    Is the PL/SQL you want to debug in the same schema as you are connecting? Because you mentioned schema names, I wonder if there may be a bug with trying to debug PL/SQL in a schema other than the one you are connected to. If so, can you try creating connection as the owner of the PL/SQL and see if that works?
    Thanks!
    -- Brian (JDev Team)

  • How to Debug PL/SQL in SQL Developer?

    I am not able to debug PL/SQL and i have following error please advice how I can enable privileges and I want to know the steps of debugging.
    Connecting to the database My_connection.
    Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
    Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_DEBUG_JDWP", line 68
    ORA-06512: at line 1
    This session requires DEBUG CONNECT SESSION and DEBUG ANY PROCEDURE user privileges.
    Process exited.
    Disconnecting from the database My_connection.
    Thanks for your time

    You need to get the DBA for the database to grant your account the privileges mentioned in the error message.
    Once that is done it should just work.
    Make sure you compile for debug
    You need some way to stop the debugger from just running through the code to the end
      - either set breakpoints
      - or Use Tools|Preferences|Debugger|Start Debugging Option to Step Into.

  • Debugging PL/SQL using JDeveloper

    Hi all,
    I'm running JDeveloper 10.1.3.2.0 on Windows XP (32-bit) SP2 connecting to a Oracle 10g 10.2.1.0 (64-bit) on UNIX.
    I have compiled the packages and procedure using JDeveloper and can run the procedure using SQL*Plus but I when I try to run the procedure in JDeveloper
    the "Run PL/SQL" dialogue appears, the Messages window shows: "Connecting to the database oradb01". I click OK and nothing seems to happen.
    I have been told by my DBA that I have all the prerequisites to debug PL/SQL so I wonder if I am missing something. Can anyone help?
    Thanks all,
    LG

    Brilliant. Thanks Shay,
    The only thing I wasn't sure about was that I tried to use the IP address of my workstation (from ipconfig) in the DBMS_DEBUG_JDWP.CONNECT_TCP procedure and for some reason it wouldn't work, so I used the Windows full computer name instead and it worked fine.
    Leo

  • How to debug PL/SQL functions? Passing parameter and debugger error

    Hi,
    How to debug a PL/SQL function in JDeveloper? There are two problems with it:
    1) Don't see how it's possible to pass parameters required by function call (in the dialog opening after Debug -> Debug FUNCTION_NAME)
    2) In a function returning table_name%ROWTYPE (and having a record declaration for table_name%ROWTYPE), debug gives error:
    PLS-00103: Encountered symbol "/" when expecting one of ... in line
    v_Return PL/SQL RECORD;
    Debugging procedures works as expected.
    Found a similar question without answer here:
    Debugging PL/SQL with parameters

    Check
    http://www.oracle.com/technology/obe/obe9051jdev/plsqlobe/obeplsql.htm#t2
    Frank

  • Debug PL/SQL in SQL Developer

    I am not able to debug PL/SQL and i have following error please advice how I can enable privileges and I want to know the steps of debugging.
    Connecting to the database My_connection.
    Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
    Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_DEBUG_JDWP", line 68
    ORA-06512: at line 1
    This session requires DEBUG CONNECT SESSION and DEBUG ANY PROCEDURE user privileges.
    Process exited.
    Disconnecting from the database My_connection.
    Thanks for your time

    Pl do not post duplicates - https://forums.oracle.com/thread/2559861

  • Debugging PL/SQL blocks in SQL Developer

    Is there any way to debug blocks of PL/SQL in SQL Developer by setting breakpoints in the code? I'm using SQL Developer.
    I'm trying to debug some fairly complex PL/SQL blocks - they are not procedures or functions and so I'm unable to run them in debug mode.
    p.s. Apologies should have posted this in the database forum really.
    Edited by: Antilles on Sep 10, 2008 1:12 AM

    Hello,
    Sure you can, take a look at the following two links -
    http://sueharper.blogspot.com/2006/07/remote-debugging-with-sql-developer_13.html
    http://www.oracle.com/technology/oramag/oracle/08-may/o38browser.html
    Hope this helps,
    John.
    http://jes.blogs.shellprompt.net
    http://www.apex-evangelists.com

  • Debugging  PL/SQL Package

    How Can I Debug PL/SQL Package using Jdeveloper.

    This forum is for feedback about the OTN site.
    Here is the URL for the JDeveloper and ADF forum:
    JDeveloper and ADF

  • Debugging PL/SQL Packages

    We have been searching for an effective debugging tool for
    PL/SQL but have come up short. The issue that we have
    encountered is that no tool that we have attempted to use will
    show global package variables. Does anyone know of a product or
    methodology that will do a complete job when debugging PL/SQL?
    null

    Hi,
    Try SQL-Programmer you can get free 60 days evaluation copy on
    net www.sfi-software.com
    bye
    Kevin Middleton (guest) wrote:
    : We have been searching for an effective debugging tool for
    : PL/SQL but have come up short. The issue that we have
    : encountered is that no tool that we have attempted to use will
    : show global package variables. Does anyone know of a product
    or
    : methodology that will do a complete job when debugging PL/SQL?
    null

  • Debugging PL/SQL procedures with JDeveloper ?

    Hi,
    does anyone know if it is possible to debug PL/SQL procedures and packages with JDeveloper ? I'm using a 9.0.1.2.0 database but JDeveloper returns the error "The target VB_TEST could not be started because the database version does not support debugging." when I try to debug a PL/SQL procedure.
    If it is not possible, does anyone know a good alternative ?Oracle Script Debugger is not available anymore at technet.

    I need to retrive data from PL/SQL stored procedures. I am using the DynamicSQL component (2nd workaround) to retrive data from PL/SQL stored procedures. <br><br>
    I am having some problems.<br><br>
    This is the code I am running in Fuego Studio 5.5 SP 11 Build #71108:<br><br>
    dynamicSQL as Fuego.Sql.DynamicSQL<br>
    iterator as Iterator(Any[Any])<br>
    sentence as String<br>
    implname as String<br><br>
    dynamicSQL = Fuego.Sql.DynamicSQL()<br>
    implname = "conexionORBPAU"<br>
    sentence = "var result REFCURSOR; " + <br>
    "exec :result_cursor := pkg_audbpm_bpaasig_indicador.prgetsingle(9999);";<br>
    iterator = executeQuery(DynamicSQL, sentence, implname, inParameters : []);<br><br>
    And, this is the error:<br><br>
    java.sql.SQLException: Falta el parametro IN o OUT en el indice:: 1 <br>
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)<br>      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)<br>
    oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1681)<br>
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3280)<br>
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)<br>
         at fuego.jdbc.FaultTolerantPreparedStatement.executeQuery(FaultTolerantPreparedStatement.java:579)<br>
         at fuegoblock.sql.DynamicSQL.executeQuery(DynamicSQL.java:340)<br>
    ...<br><br>
    This is the code of the PL/SQL in the Oracle DB:<br><br>
    CREATE OR REPLACE PACKAGE PKG_AUDBPM_BPAASIG_INDICADOR IS<br>
    TYPE cursor_type IS REF CURSOR;<br>
         FUNCTION prGetSingle<br>
         (<br>
              p_ID_ASIG_INDICADOR IN NUMBER<br>
         )<br>
         RETURN cursor_type;<br><br>
    END PKG_AUDBPM_BPAASIG_INDICADOR;<br><br>
    is my code OK? Any ideas?<br><br>
    Thanks in advance.<br>

  • Debug in sql server 2012

    Hi,
    I have 3 sql server (2005,2008,2012) In 2005 and 2008 remote debug (from sql management studio installed on the client) works without problems.
    In sql 2012 debugging only works on sql management studio installed locally, why?
    The server 2012 and the client are in the same domain, and both have the firewall disabled
    to connect to all 3 I always use the same sql server management studio 2014
    thanks!

    Hi matti157,
    As your description, you fail to use remote T-SQL Debugger in the instance of SQL Server 2012. Please help to post the error information here for analysis. Based on my research, the issue could be due to the RPC or authentication issue. You could pay attention
    to the points below to troubleshoot your issue.
    1.It is recommended to verify if the configuration of the T-SQL Debugging  was done correctly. To verify that, you can follow the steps from the link:
    http://msdn.microsoft.com/en-us/library/cc646024(v=sql.100).aspx
    2.Verify if the SQL Server Management Studio was started with Administrator permissions (Run as Administrator);
    3.Verify if the account used to connect remote to T-SQL Debugger has the right of ‘sysadmin’ on SQL Server Instance and if it is in the Local Administrators Windows Group
    4.Verify if the following services are started:
    a.TCP/IP NetBIOS Helper;
    b.Remote Registry;
    c.RPC Service;
    5.Verify if DCOM is active on the server and client. To do  that please follow the steps described in the link:
    http://technet.microsoft.com/en-us/library/cc771387.aspx.
    6.If you have intermediary devices between SQL Server and client, it is absolutely necessary to configure on this devices the  necessary rules and ports , so the communication between the SQL Server and the client not to be blocked;
    7.To verify if you have any issues with the permissions at DCOM level, you can activate the DCOM logging using the following link:
    http://support.microsoft.com/kb/892500.  To verify if the DCOM works fine you can do the test from the following article
    http://support.microsoft.com/kb/259011/en-us.
    For more information about the process, please refer to the article:
    http://blogs.technet.com/b/beatrice_popa/archive/2012/11/28/quot-unable-to-start-t-sql-debugging-could-not-attach-to-sql-server-process-on-databasename-the-rpc-server-is-unavailable-quot.aspx
    Regards,
    Michelle Li

  • Problem displaying data and Smart data debugging pl/sql

    I'm using JDev 9.0.5.1 build 1065, when i debug a PL/SQL function from the connections navigator, it allows me to stop at a breakpoint, but it doesn't display anything in the data or smart data panes. Do i need to change a config setting somewhere ? The PL/SQL is in an Oracle 8i database, does it need to be 10g for this functionality to work ?
    Thanks
    Alistair

    Are you trying to debug ASP.NET or a windows app or direct debugging?
    If a windows app or direct debugging, follow these steps:
    http://cshay.blogspot.com/2006/07/plsql-debugger-in-visual-studio.html
    If ASP.NET, follow part of the steps above to configure, but then use these steps for External App debugging:
    Debugging PL/SQL from .Net 2003

  • How do I connect the debugger for remotely debugging PL/SQL?

    Hi everyone,
    Remotely debugging PL/SQL from JDeveloper and SQL Developer is something I have tried unsuccessfully to do.
    The steps I took were to right-click my connection, select Remote Debug... and specify "4000" for the Port and "n.n.n.n" for the Local address which seems to correctly start the listener. (I used ipconfig to double-check the address.) Then, I run the anonymous block you see below.
    begin
    dbms_debug_jdwp.connect_tcp( 'n.n.n.n', 4000 );
    end;
    But, I always get the following error:
    Error starting at line 18 in command:
    begin
    dbms_debug_jdwp.connect_tcp( 'n.n.n.n', 4000 );
    end;
    Error report:
    ORA-30683: failure establishing connection to debugger
    ORA-12535: TNS:operation timed out
    ORA-06512: at "SYS.DBMS_DEBUG_JDWP", line 68
    ORA-06512: at line 2
    30683. 00000 -  "failure establishing connection to debugger"
    *Cause:    An error was indicated when trying to establish a connection
               to a debugger. Usually a TNS error will display along with
               this message to further explain the problem, although this
               TNS error will likely be hidden if you choose to trap the error.
    *Action:   Correct the indicated parameter value and try again.
    Additionally, my firewall in Windows 7 is disabled, and I work remotely from home via VPN.
    The instructions are thatI followed: Sue's Blog... again...: Remote Debugging with SQL Developer.
    Any help would be greatly appreciated. Thanks!
    James

    I found the answer.
    Object classes are missing.
    The right insert code is down but I have a new question.
    -How can I assign Resource acces to user in PL/SQL?
    Right insert code:
    declare
    vn_retval pls_integer;
    emp_session dbms_ldap.session;
    emp_dn varchar2(256);
    emp_array dbms_ldap.mod_array;
    emp_vals dbms_ldap.string_collection ;
    vv_ldap_host varchar2(256);
    vv_ldap_port varchar2(256);
    vv_ldap_user varchar2(256);
    vv_ldap_passwd varchar2(256);
    vv_ldap_base varchar2(256);
    begin
    vn_retval := -1;
    vv_ldap_host := 'XXXXXXX';
    vv_ldap_port := '389');
    vv_ldap_user := 'LDAP_USER';
    vv_ldap_passwd:= 'LDAP_PASSWD';
    vv_ldap_base := 'LDAP_BASE';
    dbms_ldap.use_exception := true;
    -- Initialize ldap library and get session handle.
    emp_session := dbms_ldap.init(vv_ldap_host, vv_ldap_port);
    -- Bind to the directory
    vn_retval := dbms_ldap.simple_bind_s(emp_session, vv_ldap_user, vv_ldap_passwd);
    -- Process New Entry in the database
    -- Create and setup attribute array for the New entry
    emp_array := dbms_ldap.create_mod_array(4);
    emp_vals(1) := 'NAME';
    dbms_ldap.populate_mod_array(emp_array, dbms_ldap.mod_add, 'cn', emp_vals);
    emp_vals(1) := 'NAME';
    dbms_ldap.populate_mod_array(emp_array, dbms_ldap.mod_add, 'sn', emp_vals);
    emp_vals(1) := 'top';
    emp_vals(2) := 'person';
    emp_vals(3) := 'organizationalPerson';
    emp_vals(4) := 'orcluserv2';
    emp_vals(5) := 'orcluser';
    emp_vals(6) := 'inetOrgPerson';
    dbms_ldap.populate_mod_array(emp_array, dbms_ldap.mod_add, 'objectclass', emp_vals);
    emp_vals.delete;
    emp_vals(1) := 'NAME' || '1';
    dbms_ldap.populate_mod_array(emp_array, dbms_ldap.mod_add, 'userpassword', emp_vals);
    -- DN for Entry to be Added under 'ldap_base'
    emp_dn := 'cn=' || 'NAME' || ', ' || vv_ldap_base ;
    -- Add new Entry to ldap directory
    vn_retval := dbms_ldap.add_s(emp_session, emp_dn, emp_array);
    -- Free attribute array (emp_array)
    dbms_ldap.free_mod_array(emp_array);
    -- Unbind from ldap directory
    vn_retval := dbms_ldap.unbind_s(emp_session);
    end;

  • Can't get External Application Debugging to work to debug PL/SQL.

    I can debug PL/SQL directly. I wish to debug ASP.NET applications using IIS. To debug my application I must attach to aspnet_wp.exe and fire up IE or firefox.. I have tried to set ORA_DEBUG_JDWP just before the call to the PL/SQL SP, but the debugger doesn't stop at the PL/SQL break point--I have set a break point just before the PL/SQL call and then enable 'Start Oracle External Application Debugger" and enter the port number that I set in ORA_DEBUG_JDWP. I believe that ORA_DEBUG_JDWP must be set before an Oracle connection is established. If I do that it interferes with my firefox or IE browser that I need to get to the point of the PL/SQL call--there are many postbacks that are encountered through the course of getting to the point where the PL/SQL call (i.e. logging in, navigating through the menu and then entering values to trigger the call). Has anyone gotten ODT to work in this configured environment? Any suggestions would be appreciated.

    Yes, I have gone through the article step by step many times. The crux of my problem I believe is that I am to "3) Add code to your ASP.NET app to set the environment variable at the process level. You need to do this at a point in the code before a connection is opened. In C# this looks something like:
    Environment.SetEnvironmentVariable("ORA_DEBUG_JDWP", "host=mymachine;port=8888", EnvironmentVariableTarget.Process);"
    I must access the Oracle database for various logon information before I get to the PL/SQL SP that I want to debug. On the first Oracle database access I get the following Oracle error because I have already set the ORA_DEBUG_JDWP variable so any connection to Oracle is trying to access the debugger (That's what I conclude anyway)..
    ORA-01031: insufficient privileges\nORA-06512: at \"SYS.DBMS_DEBUG_JDWP\", line 68\nORA-06512: at \"SYS.DBMS_DEBUG_JDWP_CUSTOM\", line 59\nORA-06512: at line 1\n"
    Thanks,
    Brent
    <<Did you have a chance to go through the steps in this article?:
    <<http://cshay.blogspot.com/2006/10/debugging-plsql-from-aspnet-and-visual.html
    <<Let me know.
    <<Christian

Maybe you are looking for

  • Mixing materials with different Goods Receipt date in the same Storage Unit

    Hello everybody, I´d like to know how  FIFO strategy would affect to this example: Adding boxes from one storage unit (pallet) to another storage unit (pallet). Both storage units have different goods receipt dates, so there is a pallet which has box

  • BDC to save text in VL02N

    Hi All, I have a requirement of adding a BDC logic in my program . While recording, I need to call the transaction  VL02N and update the delivery number and: add some text under the tab:      Texts-> Body Text and save the same. I am able to record u

  • JMenuItem icon prboblem

    Hi, I implemented some JMenuItem in my application. Some of them have icons, some don't. How can I justify their position for those ones without icons?? Currently it's like: [ ] item1 [ ] itme2 item3 [ ] item4 thanx heaps

  • Extreme music software on vista

    Hi all. I have recently upgraded to vista 32 and with that have installed all the latest vista drivers for my xfi extreme music card. The problem is when using creative mediasource 5 v5.20.23 none of the buttons below the playback controls work (Audi

  • Recommend a SSD that works in a Lenovo T60 (type 2007-CTO)

    Recommend a SSD that works in a Lenovo T60 (type 2007-CTO) !!! I will install a SSD HD on confirmation of fully working with my Lenovo T60. Have tested a Inel SSD 530 (model: SSDSC2BW180A4) fw: DC12. This disk hangs during installation of both Window