Support for dynamic SQL debugging.

When I pass p_deptno = 30 and run code below, the refcursor returns the rows. But when I pass the dpetno = null, then it moves to the State if p_job is not null and an error. Can someone help me please in this debug code.
declare
p_deptno number:=null;
p_job varchar2(30):='SALESMAN';
v_sql varchar2(4000);
l_ename varchar2(30);

  TYPE my_cursor IS REF CURSOR;
  RC my_cursor;

begin
  v_sql := 'select ename 
            from emp
           where 1=1';
           
  if p_deptno is not null then
    v_sql := v_sql||' AND deptno='||p_deptno;
  else
    if p_job is not null then
      v_sql := v_sql||' AND job='||p_job;
    end if;
  end if;
  
  OPEN RC FOR v_sql;
  LOOP
    FETCH RC INTO l_ename;
    EXIT WHEN RC%NOTFOUND;
    dbms_output.put_line(l_ename);
  END LOOP;
  CLOSE RC;
END;
Thank you.

Published by: user3565577 on March 6, 2010 20:44

Check your quote:

SQL> declare
p_deptno number:=null;
p_job varchar2(30):='SALESMAN';
v_sql varchar2(4000);
l_ename varchar2(30);

  type my_cursor is ref cursor;
  rc my_cursor;

begin
  v_sql := 'select ename
            from emp
           where 1=1';

  if p_deptno is not null then
    v_sql := v_sql||' AND deptno='||p_deptno;
  else
    if p_job is not null then
      v_sql := v_sql||' AND job='''||p_job||'''';
    end if;
  end if;

  open rc for v_sql;
  loop
    fetch rc into l_ename;
    exit when rc%notfound;
    dbms_output.put_line(l_ename);
  end loop;
  close rc;
end;
/
ALLEN
WARD
MARTIN
TURNER
PL/SQL procedure successfully completed.

Even better: try to use bind variables.

Tags: Database

Similar Questions

  • No support for oracle sql functions

    Hi all

    Please can someone explain why the B-tree indexes are not capable of supporting SQL queries using the built-in functions of Oracle.

    We have indexes of tree b on account_no column.

    Select * from test_table where account_no = 11005208

    the above query use the index on account_no

    Select * from test_table where superior (account_no) = 11005208

    But this query does not use the index on the account_no, going for the full table scan.

    My question here is account_no is the numeric data type.
    Then, there is no difference between the data in the columns account_no and upper (account_no) column data, so why he does not use index when using sql functions in an sql query?

    Hello

    If you apply the upper function, Oracle implicitly converts its argument to a string, so your query is actually upper (to_char (account_no)).
    There is none HAVE fully functional in the optimizer and you do not expect to know everything and do all the conclusions that a human being can do. Why should Oracle re - write this type of query analysis the data type of the columns and features when it seems more natural programmer write a correct query (without capital letters in this example) or, if necessary, create an index based on a function?

  • support for MS SQL 2008 vCenter

    Hello

    Does anyone have an idea what vCenter release will support Microsoft SQL 2008?

    Thank you

    vSphere supports SQL 2008 for the VC database - it also support WIndows 2008 for installing vCenter 4.0

    If you find this or any other answer useful please consider awarding points marking the answer correct or useful

  • Mobile AV support for dynamic access ASA policies

    We went just to the last image of the CSD, 3.6.6203 and ASA 8.4.4.1.  We have currently a DAP set up to scan a group policy for an AV means but wanted to start this run for all group policies and including several different flavors of AV (so anyone could connect from anywhere as long as a pre-approved AV is installed).  We leave about 20 different versions of different AV and I've tried a couple and they succeeded.

    My question is now trying to allow (or deny) AV that is installed on an Android Tablet (and possibly Apple devices).  The Tablet has avast Mobile Security installed and even if I select the seller: Alwil overall, he does not always recognize and refuses to the user.  I tested on a PC and it works fine.  Is there something I'm missing or are mobile AV programs not included in the policies of the DAP?  Is that this is going to be considered in future versions of the CSD or ASA or we're going to continue to consider devices Android and Apple 'secured' and doesn't require the VA?  Thank you.

    Hello

    At this stage the CSD is not supported on Android / iOS devices.

    CDD + HostScan can be used to allow administrators to identify Apple iOS devices, but is limited to the communication of the operating system.

    You can submit an enhacement request to your account team.

    Portu.

    Please note any workstation that you be useful.

  • SQL logical support for pl/sql block

    Hi all
    I have need of your suggestions and comments for the below question:

    I have two tables: table A and table b.

    Table has two columns as id and charges:

    Counties of ID
    -------------------------
    99 10
    13 999
    9999 7

    Table B has two columns Id and stopped:

    Order of identification
    _______________
    99 1
    2 999
    3 9999


    We need update of the order in the Table B such that Id with the highest number in table A stopped as 1 in the table B and it continue to increase enforcement for other Ids based on reducing the counts in table A. It will be like a job serving daily and search counts in table A and update the order in table B, according to her.
    It seems simple, but I don't get it. Please help me on this by writing a PL/SQL block.
    I'd really appreciate all your comments and your responses.

    Concerning
    Dev

    Hello

    Here's a way to do it:

    MERGE INTO     stat     dst
    USING (
         SELECT       s.id
         ,       ROW_NUMBER () OVER ( ORDER BY SUM (m.counts)
                                        DESC
                                  NULLS LAST
                             )     AS orders
         FROM             stat     s
         LEFT OUTER JOIN  main     m  ON  s.id  = m.id
         GROUP BY  s.id
          )               src
    ON     (src.id     = dst.id)
    WHEN MATCHED THEN UPDATE
    SET     dst.orders     = src.orders
    ;
    

    As you can see, it is similar to the solution to your original problem.
    In the original problem, id in the table (primary) source was unique; now, it is not, and we are interested in the SUM of all values of counts, so we can use GROUP BY and the SUM aggregate function. When used in the same query, aggregation (such as the SUM above) functions are calculated before analytical functions (for example, ROW_NUMBER), so the aggregate functions can be nested within analytical functions.
    The big change is that now the subquery source produces a line for each stat line, or not this ID exists in the hand, and he ignores any ID at hand which does not exist in stat, using an outer join. "stat LEFT OUTER JOIN main" means that all ranks of stat will appear in the results, even if there is no game in hand, but the bottom lines will be in the results only if they have a match in the stat.
    ROW_NUMBER assigns unique, coinsectuive whole, exactly as you requested. If there is a tie (two or more ID having exactly the same SUM (account)) then ROW_NUMBER will assign numbers separate, consecutive lines. It will be arbitrary in what id receives the lower number.

  • No support for transport = dt_shmem debugging?

    I have the feeling that I must be missing something obvious, but are there no support to attach the debugger through the shared memory transport? I'm starting a Java outside JDev application with '-agentlib:jdwp = transport = dt_shmem, address = oc4j server =, suspend = n ', and I want to attach the debugger, but just can't see how to get there. The "Attach to being debugged JPDA" dialogue box appears to lock onto the socket transport.

    The JDev debugger does not support debugging using a connector dt_shmem.
    At present, there are no plans to support. Of concern is that it is a Windows solution only.

    Keimpe Bronkhorst
    Team JDev IDE

  • Dynamic SQL and NULL

    If testrh2 of the table has the following columns and data
    col1-> NULL
    col2-> 2

    and table testrh has the columsn and the following data

    col1-> NULL

    How to write a dynamic SQL statement to join on null values? I wrote the following as a starting point block.

    declare
    cursor c1 is select col1 isis.testrh;
    lval varchar2 (1000);
    lval2 varchar2 (1000);
    Start
    to r1 c1 loop
    lval: = 'select col2 from isis.testrh2 where col1 =' | R1.Col1;
    run immediately lval in lval2;
    dbms_output.put_line (lval2);
    end loop;
    end;

    arizona9952 wrote:

    How to write a dynamic SQL statement to join on null values? I wrote the following as a starting point block.

    Identical to static SQL:

    lval: = ' select col2 from isis.testrh2 where col1 =: 1 or (col1 is null and: 1 is nothing)';
    run immediately in lval2 using r.col1 lval, r.col1;

    SY.
    PS I guess that's a simplified version of a logic more complex. Otherwise ther is not necessary for dynamic SQL statements.

    Published by: Solomon Yakobson October 2, 2010 17:06

  • SQL Developer 3.0 EA 1 Advanced support for the type of data in the unit tests

    Hello

    According to SQL Developer 3.0 EA 1 New Feature List (http://www.oracle.com/technetwork/developer-tools/sql-developer/rel3-featurelist-ea1-166831.html#ut)
    the EA 1 version 3.0 supported advanced data types in the unit tests. This means support the ANYDATA and RECORD types? I installed version 3.0 of EA 1 to CentOS linux, but it seems that those advanced types are not supported yet. When I try to add a unit test for a function that returns the record type, I get quick error: "the return of PL/SQL RECORD type is not supported. Cannot test (function_name) because 1 arguments have not supported for types". Also if I try to unit test procedure which parameter is of type ANYDATA, I get quick error: "the type UNDEFINED P_DATA argument is not supported. Cannot test (procedure_name) because 1 arguments have not supported for types". Are those advanced data types supported in SQL Developer 3.0 FINAL version?

    Thank you
    Miikka L

    Edited by: user12844253 the 27.10.2010 16:31

    Hi Mikka,

    Only simple PL/SQL records are currently supported i.e. those containing no optional or repeating components and where all components are themselves supported. This restriction is in place, due to the fact that we are using JDBC as a parameter mechanism which does not directly support the passage the PL/SQL record type.

    ANYTYPE and ANYDATA are currently not supported because they have a dynamic value type and must be set programmatically. In the future, it would be possible to support these via the dynamic value and and validation features.

    This will remain for the final version.

    Kind regards
    Richard

  • TMS support for SQL (standard/express) 2012

    Is there a timetable yet for 2012 SQL support for MSDS?  I have a situation where he would have preferred to use SQL 2012 rather than 2008.

    That said, someone has actually tried it and if yes are there any problems or "traps"?

    I guess while I'm, what about Windows Server 2012 support?

    Hello Anthony.

    Research on forums a few Windows and SQL 2012 support questions.  This is a debate which answer your questions both...

    https://supportforums.Cisco.com/message/4046686

  • PDF IFilter support for 8.1 Windows and SQL Server 2014

    Hello

    We use Adobe PDF iFilter Version 64 11.0.01 (here: https://www.adobe.com/support/downloads/detail.jsp?ftpID=5542) full-text support for PDF files on SQL Server and Windows Server 2012 2012. This works also on Windows Server R2 from 2012 to 2014 of SQL-Server even if both is not listed in the list of the applications/OS supported. But it does not work for the combination of 8.1 to Windows and SQL-Server, 2014.

    Can anyone provide a solution to make it work for this combination, or know when it will be officially supported?

    Kind regards

    Stefan

    Hi stefankainz663,

    Please see this KB for the workaround iFilter PDF search doesn't work on Windows 8 x 64.

    Kind regards
    Nicos

  • VMware converter 4 support for partitions on dynamic disks

    I currently have a server physical windows 2003 which has its system and data partitions defined as dynamic disks (C and D partitions lie on disk 0-dynamic) not well why it's set up this way, it was built just like that.

    The goal is to convert this virtual server and I read many forums stating that dynamic disks are not supported for vmware converter, but some cases have succeeded where the target score was a record time-basic-but-now-dynamics.

    Is this the case? and if so, what alternatives can be tried to virtualize the server.

    Dynamic disks are supported for Windows.  The resulting virtual machine will only basic disks in a hot clone.

    I would just suggest that you make a clone of hot regular and do a slight reduction in the size of the disc resulting (even if it is 1 MB).

    Second, ensure that the system starts out of the c:\ partition and it is marked as a partition active and has a file boot.ini in the root.

    Kind regards

    Jonathan

    B.SC., RHCT, VMware vExpert 2009

    NOTE: If your question or problem has been resolved, please mark this thread as answered and awarded points accordingly.

  • Dynamic recovery for the dynamic sql query

    Hi all

    I want to create a query dynamically and to fetch it in a dynamic cursor record... The structure of the record should be the same as that of the query...
    Can you suggest any method to do this.

    for example

    OPEN < dynamic news > TO < dynamic stmt >;
    LOOP
    FETCH < dynamic news > < DYNAMIC rec >;
    ---
    END LOOP;
    CLOSE < dynamic news >;

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Thank you
    Merz

    Published by: merz Sep 12, 2011 17:02

    Published by: merz Sep 12, 2011 17:03

    Merz says:

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Is not possible. What you describe is called four dynamic sql type. For this type of synamic SQL, you use the DBMS_SQL package.

    SY.

  • Dynamic SQL question. What are these apostrophes for?

    Here is a solution provided by Boneist in the two questions relating to a so-called simple dynamic SQL thread
    declare
    v_rs date;
    
    begin
    for i in (select table_name from user_tables)
         loop
         execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||''''  into v_rs;
         dbms_output.put_line(i.table_name ||'----'||v_rs);
    end loop;
    end;
    When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenation
    ''' || i.table_name||''''
    First quote on the left is the final quote from SELECT (' select last_analyzed)

    Second quote from left to right - I think this is the quote from beginning to the name of the table ("DEPT)

    Quote from third starting on the left -?



    I have not understant what 4 quotes on the right of the concatenation of c. I know one of them is the quotation from the end (right) for the name of the table (like DEPT')

    JOE_humble wrote:
    When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenation

    Actually 4 quotes on the left quotation marks and 4 right...

    execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||''''  into v_rs;
                      ^                                                         ^^^                  ^^^^
                      |                                                         |||                  ||||
                       \________________________________________________________///                  \||/
                                                  |                                                   \|
                                                4 quotes                                            4 quotes
    

    Maybe better if you look at it like this...

    Suppose we use a character # to indicate the beginning and the end of our strings...

    execute immediate #select last_analyzed from user_tables where table_name = ''# || i.table_name||#''#  into v_rs;
    

    Now, you can see that we have two strings concatenated with the variable string representing the table name concatenated together.

    Within each of these channels, we have two single quotes. When the parser crosses the two single quotes like this, in the string, which converts a quotation mark in the resulting string, rather than taking this means the end of the string itself.

  • Difference between static &amp; dynamic sql

    Hello

    It is my first question in OTN.

    I have a pl/sql procedure with no insert statements.

    Insert into table values...

    If I turn all these insert statements in dynamic sql, my procedure will give more effective? (execution)

    Please help me.

    Thanks in adv

    Friend

    Hello

    8b00c42d-7716-467e-BCEF-c756fd9599e2 wrote:

    Hello

    It is my first question in OTN.

    Welcome to the Forum!

    To get the most out of this Forum, see the FAQ in the Forum: Re: 2. How can I ask a question on the forums?

    For all performance issues, see also this Forum FAQ page: Re: 3. how to improve the performance of my query? / my query is slow.

    I have a pl/sql procedure with no insert statements.

    Insert into table values...

    If I turn all these insert statements in dynamic sql, my procedure will give more effective? (execution)

    Probably not.  Dynamic SQL is generally less effective than static SQL, as well as being more difficult to code, debug and maintain.

    Is there a reason why you think that the dynamic SQL would be preferable in this case?  If so, what is it?

  • Dynamic SQL with dynamic identifiers

    Oracle 10gXE

    I have a table that is used to track student attendance. If the student is present on a given day, a record is inserted with the student ID and the date they frequented.

    presence of DESC
    Name of Type Null
    --------------- -------- ------
    ID NOT NULL NUMBER
    NUMBER OF STUDENT_ID
    SITE_ID NUMBER
    DATE OF ATTENDANCE_DATE

    I want to view a report (in TOP) which shows all students for a given site, the days when school was in session for this month (not Saturday, Sunday) and a X for the student who participated in that day or a null value if they do not have.

    ID # FNAME LNAME 3 4 5 6 7 10
    38754636 POE JANE X X X
    81248754 DOE KAYLA X X X X X
    43127409 RAO JOHN X X X X X

    In this example, days 3 and 7 of the month are from Monday to Friday and 8-9 have been excluded because they are on Saturday and Sunday.

    I am trying to find a way to dynamically generate a query for any month/year and returning to a report. The obstacle is that given that I don't know in advance which days in a month will be excluded, the identifiers in my select statement are not fixed.

    I found a query that returns a list of day numbers and dates for a given month. It looks like this:

    SELECT LEVEL lv, TO_DATE (TO_CHAR (LEVEL, '09')
    || TO_CHAR (EXTRACT (TO_DATE('01-SEP-11') MONTHS), '09')
    || To_char (EXTRACT (TO_DATE('01-SEP-11') YEAR), ' 9999'), 'dd.mm.yyyy') mon_day
    OF double WHERE ROWNUM < = EXTRACT (DAY OF LAST_DAY (TO_DATE('01-SEP-11')))
    CONNECT BY LEVEL = ROWNUM

    I combined this request with another brings my student attendance data and results that pivots in what I need. Then, I created a function that accepts the month and year as parameters and creates the combined request.

    SELECT c.ID student_id, c.last_name, c.first_name,.
    MAX (decode (mon_day, ' 01 - SEPT.-11', 'X', NULL)) '1', MAX (decode (mon_day, ' 02 - SEVEN.-11', 'X', NULL)) '2 ',.
    MAX (decode (mon_day, ' 05 - SEPT.-11', 'X', NULL)) '5', MAX (decode (mon_day, ' 06 - SEPT.-11', 'X', NULL)) "6."
    MAX (decode (mon_day, ' 07-SEP-11', 'X', NULL)) '7', MAX (decode (mon_day, ' 08 - SEPT.-11', 'X', NULL)) "8."
    MAX (decode (mon_day, ' 09 - SEPT.-11', 'X', NULL)) '9', MAX (decode (mon_day, 12-SEP-11', 'X', NULL)) "12."
    MAX (decode (mon_day, 13-SEP-11', 'X', NULL)) '13', MAX (decode (mon_day, 14-SEPT-11', 'X', NULL)) "14."
    MAX (decode (mon_day, 15-SEP-11', 'X', NULL)) '15', MAX (decode (mon_day, 16-SEP-11', 'X', NULL)) "16."
    MAX (decode (mon_day, 19-SEP-11', 'X', NULL)) '19', MAX (decode (mon_day, 20-7.-11', 'X', NULL)) "20."
    MAX (decode (mon_day, 21-SEP-11', 'X', NULL)) "21", MAX (decode (mon_day, 22-SEP-11', 'X', NULL)) '22 ',.
    MAX (decode (mon_day, 23-SEP-11', 'X', NULL)) '23', MAX (decode (mon_day, 26-SEP-11', 'X', NULL)) "26."
    MAX (decode (mon_day, 27-SEP-11', 'X', NULL)) '27', MAX (decode (mon_day, 28-SEP-11', 'X', NULL)) "28."
    MAX (decode (mon_day, 29-SEP-11', 'X', NULL)) '29', MAX (decode (mon_day, 30-SEP-11', 'X', NULL)) '30 '.
    (SELECT level lv, TO_DATE (TO_CHAR (LEVEL, '09')
    || TO_CHAR (EXTRACT (TO_DATE('01-SEP-11') MONTHS), '09')
    || To_char (EXTRACT (TO_DATE('01-SEP-11') YEAR), ' 9999'), 'dd.mm.yyyy') mon_day
    OF double WHERE ROWNUM < = EXTRACT (DAY OF LAST_DAY (TO_DATE('01-SEP-11')))
    CONNECTION LEVEL = ROWNUM) a, b of attendance, student c
    WHERE to_char(MON_DAY,'D') NOT IN (1.7)
    AND A.mon_day = b.attendance_date
    AND b.student_id = c.ID
    Group of c.ID, student_id, c.last_name, c.first_name

    Now I'm stuck on what I can pass this request in to get my result. What I've read, dynamic SQL method 4 would work if I incorporate Pro/C. I hope this isn't my only option. I have considered to try to do this in a function table in pipeline, but since the columns returned are not known in advance, I can't create a corresponding data type.

    I'm starting to wonder if I forgot a simpler method to achieve this.

    Published by: David Sumner on April 12, 2012 18:52

    Ignoring the actual query and looking at the dynamic SQL part of the question.

    There are 3 ways to run a dynamic select SQL in PL/SQL code.

    immediate execution requires a fixed number of bind variables, linking him in position and translates a single implicit output cursor extraction - requiring the projection of cursor to be known at the time of coding.

    REF CURSOR are essentially the same - the only exception being that it requires an extraction explicit coding process output cursor.

    DBMS_SQL differs in all of these respects. The connection is by name and not position. The connection is dynamic. Projection of the cursor must not be known at the time of coding. It is dynamically determined at runtime and fetch offers of release of the cursor with the projection of unknown SQL - coding time.

    Apex uses DBMS_SQL internally (in fact he uses DBMS_SYS_SQL properly run dynamic and specific patterns of Oracle SQL, as if a session connected as a scheme runs the SQL code). This allows the Apex to take a dynamic SQL that you enter a region (which can contain a variable number of bind variable), run it and make the projection of the cursor as an HTML report.

    Apex supports in turn also dynamic SQL - what you (Apex developer) to provide a dynamic SQL code for a region, instead of you having to provide SQL fixed (with bind variable) for the region in question.

    As Apex creates DBMS_SQL sliders, it doesn't have your SQL as a ref cursor or cursor DBMS_SQL. All they need is the source of the SQL statement. And that's what you create dynamically.

    So in the Apex, dynamic SQL means using a function from PL/SQL to return the source for Apex SQL analyze like a slider DBMS_SQL - instead of coding the source SQL statement in a fixed statement.

    So, using the option of function for an area considered in the Apex, allows you to provide the following in the code that must run to get the SQL statement for the report Apex (Apex running this as a dynamic function that returns a string):

    --// return the dynamic SQL for the report region
    return(
      case
        when :P1_OPTION = 1 then
          'select * from emp'
    
        when :P1_OPTION = 2 then
          'select * from dept where dept_id = :P1_DEPT_ID'
      end
    );
    

    You can also write a PL/SQL function that is stored in the database and call this function so that it can determine what is the dynamic SQL source code statement. For example

    --// calling database function to return the dynamic SQL for the report region
    return(
      GetDynamicReportSQL( page => 1, option => :P1_OPTION )
    );
    

    Dynamic SQL is fully supported by Apex - but does not require that you, the developer, to create the dynamic cursor and treat the dynamic linking and dynamic recovery of this slider.

    All you have to do is to provide the source code of this dynamic SQL (including the bind variable) to the Apex and it will do the whole thing from cursor for you.

Maybe you are looking for

  • Satellite Pro lack driver control of network

    If im points do not fingers but anyway my laptop has managed to lose its network controller driver (im blaming the cat.) My problem is to reinstall this driver requires a connection to the internet which, because of the missing driver, I don't have..

  • First HP no longer works HELP!

    IM serius problems with my first Hp. And I don't really know what to do.5 months ago I bought a Hp first.And half a month ago I have upgraded to the latest firmware, all normally!But two days ago I was doing some money and my computer is turned off!I

  • DV9 while initializing the message received, 736/736 (\Registery components of the Machine)

    While starting my laptop computer was, he got a blue screen with a message not to turn off my computter then only he finished scanning, ect.  This seemed normal because last night when I went to close, I got a message that does not turn off my comput

  • overflow in the interim results of data types

    Hi all I'm sorry, this is a very basic question... I have the following expression, giving me an unexpected result because overflow: D1 = RoundRealToNearestInteger (i1 * l1 / l2); D1 is of type double, l1, l2 of type long int and i1 of the type ssize

  • HP Officejet Pro 6830: HP Officejet Pro 6830 @hpeprint address not printing

    I just added my new HP Officejet Pro 6830 to my home network.  The printer is set up for my network with a Wi - Fi connection.  All updated software has been installed.  My operating system is Windows 10 (64-bit). When directly connected to my networ