This discussion is archived
1 Reply Latest reply: Mar 21, 2013 12:47 PM by CraigB RSS

is there a difference between these if statements ?

newbi_egy Explorer
Currently Being Moderated
db and dev 10g rel2
hi all,
i'm trying to open a form from another one through a button
- the calling form has the scott.dept table and the button .
- the called form has the scott.emp table .

when i write the code like so :
declare 
     pl paramlist ; 
begin 
     pl := get_parameter_list('tmp') ; 
     if not id_null(pl) 
          then 
          destroy_parameter_list(pl) ;                                        -- notice the if statement .
     end if ; 
     pl := create_parameter_list('tmp') ; 
     add_parameter(pl,'p_deptno',text_parameter,:dept.deptno) ; 
open_form('d:\newform.fmx',activate,no_session,pl) ; 
end ; 
it works so fine .
but , when i change it to this :
declare 
     pl paramlist ; 
begin 
     pl := get_parameter_list('tmp') ; 
     if not id_null(pl) 
          then 
          destroy_parameter_list(pl) ; 
          else 
     pl := create_parameter_list('tmp') ;                                -- notice the if statement (else)
     add_parameter(pl,'p_deptno',text_parameter,:dept.deptno) ; 
open_form('d:\newform.fmx',activate,no_session,pl) ; 
          end if ;
          end ; 
or this
declare 
     pl paramlist ; 
begin 
     pl := get_parameter_list('tmp') ; 
     if not id_null(pl) 
          then 
          destroy_parameter_list(pl) ; 
     elsif id_null(pl)
          then 
     pl := create_parameter_list('tmp') ;                     -- notice the if statement (elsif)
     add_parameter(pl,'p_deptno',text_parameter,:dept.deptno) ; 
open_form('d:\newform.fmx',activate,no_session,pl) ; 
          end if ;
          end ; 
it does not work unless i push the button twice ,
although the three ways are the same , and the trigger is the same as well (when-button-pressed)
  • 1. Re: is there a difference between these if statements ?
    CraigB Guru
    Currently Being Moderated
    Use the first PL/SQL code block you listed:
    declare 
         pl paramlist ; 
    begin 
         pl := get_parameter_list('tmp') ; 
         if not id_null(pl) 
              then 
              destroy_parameter_list(pl) ;          -- notice the if statement .
         end if ; 
         pl := create_parameter_list('tmp') ; 
         add_parameter(pl,'p_deptno',text_parameter,:dept.deptno) ; 
    open_form('d:\newform.fmx',activate,no_session,pl) ; 
    end ;
    You have to push the button twice because the 2nd and 3rd PL/SQL Blocks will only create the parameter list (PL) if the PL doesn't already exist. Apparently, it exists so you destroy it with the first button click and create it with the second. You always want the CREATE_PARAMETER_LIST() to be called so your Condition should end after testing if an existing PL was found.

    Craig...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points