Possible to write a function that takes any type as parameter ?

I need to write a function that will take 2 parameters ( of any type - VARCHAR etc ) and return a boolean.
( Im trying to write a function that will do NULL processing.
something like..
if ( P1=P2 OR ( P1 IS NULL AND P2 IS NULL ) ) then
return true ;
end if;
return false ;
the function simply compares its parameters P1 & P2 and returns true if they are equal - including if both are NULL
Is this possible to write at all.
My code looks very ugly without this being wrapped in a function.

You may be able to use SYS.AnyData for this. However, dealing with the data would be confusing, so overloading the FUNCTION would most likely be a better idea.
This doesn't work, but it looked like fun, so i tried:
CREATE OR REPLACE FUNCTION Equal_Or_NULL(A SYS.AnyData, B SYS.AnyData)
RETURN PLS_INTEGER
AS
Local_A     VARCHAR2(4000);
Local_B     VARCHAR2(4000);
Junk          PLS_INTEGER;
BEGIN
IF A IS NULL AND B IS NULL THEN RETURN 1; END IF;
CASE A.GetTypeName
  WHEN 'SYS.NUMBER'     THEN Junk := A.GetNumber(Local_A); Junk := B.GetNumber(Local_B);
  WHEN 'SYS.DATE'     THEN Junk := A.GetDate(Local_A); Junk := B.GetDate(Local_B);
  WHEN 'SYS.CHAR'     THEN Junk := A.GetCHAR(Local_A); Junk := B.GetCHAR(Local_B);
  WHEN 'SYS.VARCHAR'     THEN Junk := A.GetVARCHAR(Local_A); Junk := B.GetVARCHAR(Local_B);
  WHEN 'SYS.VARCHAR2'     THEN Junk := A.GetVARCHAR2(Local_A); Junk := B.GetVARCHAR2(Local_B);
END CASE;
RETURN CASE WHEN Local_A = Local_B THEN 1 ELSE 0 END;
END Equal_Or_NULL;
/Overloading would be much simpler, as the arguments could be directly compared.
IMO, Do not do this. Hiding logic in a FUNCTION it for cosmetic purposes is a bad idea.

Similar Messages

  • Help with a store function that takes string array

    Hi All,
    I have a function that takes in two string arrays, status_array, and gender_array. You can see the partial code below. Somehow if the value for the string array is null, the code doesn't execute properly. It should return all employees, but instead it returns nothing. Any thoughts? THANKS.
    for iii in 1 .. status_array.count loop
    v_a_list := v_a_list || '''' || status_array(iii) || ''',';
    end loop;
    v_a_list := substr(v_a_list, 1, length(trim(v_a_list)) - 1);
    for iii in 1 .. gender_array.count loop
    v_b_list := v_b_list || '''' || gender_array(iii) || ''',';
    end loop;
    v_b_list := substr(v_b_list, 1, length(trim(v_b_list)) - 1);
    IF v_a_list IS NOT NULL and v_b_list IS NOT NULL THEN
    v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') and gender in (' || v_b_list || ')';
    ELSIF v_a_list IS NOT NULL and v_b_list IS NULL THEN
    v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') ';
    ELSIF v_a_list IS NULL and v_b_list is not null THEN
    v_sql_stmt := 'select distinct full_name from t_employee where gender in (' || v_b_list || ')';
    ELSE
    v_sql_stmt := 'select distinct full_name from t_employee';
    END IF;
    OPEN v_fullname_list FOR v_sql_stmt;
    RETURN v_fullname_list;

    I'd first recommend trying to avoid the dynamic sql.
    use an approach like
    [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] or
    [http://stackoverflow.com/questions/1625649/oracle-parameters-with-in-statement/1655743#1655743] or [http://stackoverflow.com/questions/1715978/how-to-use-an-oracle-associative-array-in-a-sql-query]
    but if that isn't in scope, do a
    dbms_output.putline(v_a_list) ;
    dbms_output.putline(v_b_list) ;
    dbms_output.putline(v_sql_stmt) ;around and see what it emits

  • Best way to write a function that returns query texts

    Hi, I need to write a function that will take a parameter containing table name and based upon it returns the text of a query. Here is what I am thinking of doing it but would like to get feedback whether there is a better way to do it.
    For example:
    FUNCTION getSQL(p_1 VARCHAR2, p_2 VARCHAR2) RETURN VARCHAR2
    IS
       sql varchar2(2000);
    BEGIN
    --Here i want IF THEN ELSE part and thes based upon it return a desired sql. There will be more than a dozen sqls that the function will return.
    IF p_1='Employee' Then
    sql:='Select * from employee Where employee_id=p_2;'
    Else If p_1='Departement' Then
    sql:='Select col1, col2, col3,';
    sql:=sql || ' col4, col5, col6';
    sql:=sql || ' Where dept_id=p_2';
    Else If.....
    Else If.....
    Else If.....
    Else If.....
    End IF;
    return sql;
    END;Edited by: dreporter on Sep 20, 2010 8:43 AM

    I'm never sure I understand the desire to put lots of cursors into a single stored procedure, given that they are inherently different things.
    However, assuming you have made the above decision, you should almost certainly look at using the overload of dbms_xmlgen.newcontext that accepts a cursor parameter rather than a string. This would allow you to return cursors from your function rather than strings, giving you the option to use bind variables (and prevent associated SQL injection) and perhaps not even do dynamic SQL at all, something like this perhaps...
    FUNCTION get_cursor (
       p_cursor_type VARCHAR2,
       p_cursor_parameter VARCHAR2)
       RETURN sys_refcursor
    IS
       v_sys_cursor sys_refcursor;
    BEGIN
       CASE p_cursor_type
          WHEN 'Employee' THEN
             OPEN v_cursor FOR
                SELECT empno, ename
                  FROM emp
                 WHERE empno = TO_NUMBER (p_cursor_parameter);
          WHEN 'Department' THEN
             OPEN v_cursor FOR
                SELECT deptno, dname
                  FROM dept
                 WHERE deptno = TO_NUMBER (p_cursor_parameter);
       END CASE;
       RETURN v_sys_cursor;
    END get_cursor;
    /

  • Need to write a query that takes more than 2 minutes to execute

    Hi ,
    I am using Oracle 10g as my DataBase.
    I am writing a small program for Testing purpose , in that my requirement is to write a query that takes more than 2 minutes to execute .Right now i have only a small Table called as "Users" with very less data .
    Please let me know how can i achieve this thing ??
    Thanks .

    So please tell me , how can i achieve this . Thanks in advance .P. Forstman's example above will probably be more reliable, but here's an example of my idea - harder to control timing (untested)
    select count(*)
      from dba_objects o, dba_tables t, dba_tab_columns tc
    where o.object_name||'' = t.table_name||''
       and o.owner||'' = t.owner||''
      and t.table_name||'' = tc.table_name
      and t.owner||'' = tc.owner||''

  • How to write a method that takes two arguments of same type

    Hi,
    I seldom do anything "advanced" in generics, but I've done my reading, and thought that I had an understanding of the basics, but I'm stuck on this. How do I write a method that takes two arguments that must be of exact same type.
    I've tried something like:
    public class GenericsTest1 {
        public static <T> void compare(T first, T second) {
    }But the compare method can in this case be called with e.g.
    String arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);I can restrict the call to something like GenericsTest1.<Long>compare(arg1, arg2), but I don't want to do it in the location that calls the method, and the method can still be invoked with subclasses of the specified type. E.g. this is valid (but I don't want it to be valid):
    Number arg1 = null;
    Long arg2 = null;
    GenericsTest1.<Number>compare(arg1, arg2);So I then changed the method into something like this:
    public class GenericsTest2 {
        public static <T, E extends T> void compare(T first, E second) {
    }It feels like I'm half way there now. Compare can't be called with e.g:
    Long arg1 = null;
    Number arg2 = null;
    compare(arg1, arg2);But this is still valid:
    Number arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);Hmm... So what to do? I only want the method to be callable when arg1 and arg2 is of exact same type. Everything else should give a compilation error.
    Kaj
    Ps. No, I don't have a need for this, I'm just curious.

    dannyyates wrote:
    I haven't gone through everything you've written, but I would expect that in the first instance, it's inferred <T> to be Object. This is a good reason to parameterise the class rather than the method wherever that makes sense.Thanks for you reply, but as I said this isn't related to anything that I'm going to use. I just want to know if it ca ben done with a static method and generics.
    Kaj

  • Deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE

    How can deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE in SQL?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by angelrip:
    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel<HR></BLOCKQUOTE>
    Do something like the following:
    cstmt = conn.prepareCall("{call customer_proc(?, ?)}");
    //Set the first parameter
    cstmt.setInt(1, 40);
    //Register to get the Cursor parameter back from the procedure
    cstmt.registerOutParameter(2, OracleTypes.CURSOR);
    cstmt.execute();
    ResultSet cursor = ((OracleCallableStatement)cstmt).getCursor(2);
    while(cursor.next())
    System.out.println("CUSTOMER NAME: " + cursor.getString(1));
    System.out.println("CUSTOMER AGE: " + cursor.getInt(2));
    cursor.close();
    null

  • Is it possible to write a report that calls a set of pages every morning?

    HI
    I have a short question concerning the report engine.
    Is it possible to use the EP report engine in order to write a script that would execute a certain set of iviews each morning?
    The idea is that the iViews in question always take a lot of time when called in the morning. Once loaded into the cache they load fast. So I would like to find a way of taking the burden to wait from the first user by implementing a report that runs every morning.
    Is this possible? If yes, where can I find some further information on that issue?
    Thanks for your help,
    greetings,
    Mingolo

    Hi,
    Don't know of any easy way of doing this internally,  but it should be little trouble to execute a browser script every morning.
    Basically you can create a link to the page(s) in question using the NavigationTarget url parameter. Then it is just to call iexplore.exe <url> . If you don't have SSO you need to automatically submit the login form but this is also possible (search for j_user on SDN).
    The browser script is then called from a scheduled task
    Dagfinn

  • Is it possible to write a script that changes swf export settings?

    I want to be able to export a swf file that uses a different text anti-alias setting. Is it possible to create a script that can set and export a swf file to my specifications?

    function(){return A.apply(null,[this].concat($A(arguments)))}
    Is it possible to create a script that can set and export a swf file to my specifications?
    It seems there isn't. A script cannot add basic functionality, only access it. In this case, you can't change the setting because there is no 'antialias text' setting in the SWF export settings.
    However, all is not lost. Google turned up this helpful page; it might be possible to edit your SWF after exporting and then re-save it.

  • Is it possible to create a component that takes two inputs?

    Hi Experts,
    Is it possible to create a custom JSF component that takes two input values and assigns them to a managed bean?
    For example, a component that displays two input boxes?
    The tag would look something like this:
    <my:component value1="#{bean.value1}" value2="#{bean.value2}" />I've tried, but I can't get the values to update the managed bean.
    I'm starting to doubt that it is possible, as their is only 1 setSubmittedValue method :(
    Thank you,
    Ristretto

    Hi Prosun Bondopadhyay  ,
                   Component controller is the base of a wda component. its can be considered as the base class. all the other views can be considered as the sub classes of component  controller. so without the base class there is no existence for sub class rt?
    like we can use all the methods and attributes of a component controller(main class) across all the view(sub class) and the viceversa is not possible.
    hence we cannot create a wda without component controller.
    Regards
    Sarath

  • ALV-Grid:  Is it possible to catch "LOCAL Function Codes" in any Event ??

    Hi,
    is it possible that i can catch a "Local Function Code" in ALV Grid with an Event??
    For example if you click to an Grid Button on the toolbar than it must call an Event!
    ..........BUTTON: Local APPEND (existing in ALV Toolbar)
    Function Code: '&LOCAL&APPEND'
    My Idea is:
    --- IF i click to the Button "Local APPEND" in the ALV toolbar, than it must after this command give me an Message( "It was Successfull" ).
    But the "Local Function Codes" dont called the Event "User_command" OR "After_user_command" is there any other Event for this "Local Function Codes"???
    Have anyone an idea?
    Thanks in forward.
    Ersin

    Hi,
    See following thread.
    http://scn.sap.com/thread/715996
    Thanks
    Santosh

  • Is it possible to write a script that would change triangles to circles?

    I have an Excel file that plots a scatter-plot graph using a logarithmic scale. Since it is not possible to create a logarithmic graph in Illustrator, I imported the graph into Excel as a PDF. However, each data point is a triangle, and I would like to use circles that I created using OBJECT>GRAPH>DESIGN. Is there an easy way to replace the triangles with these circles?
    If you need to see the current AI file, just let me know how to attach it.
    Thanks.

    To elaborate on what Monika wrote select all the triangles with the direct select tool and the shift key and do not group them then go to effect>Convert Shape Ellipse choose Absolute and enter your dimensions you can then give it a transform effect to give it a visual centering as in the screenshot and turn that into a graphic style which can be saved for future use.
    However remember if you wish to change the size or offset the graphic style will record the convert shape and transform in the appearance panel and it can be changed you can do it to one or all of the converted triangles.

  • Is it possible to write a script that samples an anchor points underlying color and applies it?

    I was wondering if anyone with scripting knowledge for Illustrator can think of a script that would sample the underlying color of anchor points in a selected gradient mesh and apply it to them? I was just thinking of ways to speed up the process of creating a vector drawing based on a picture so that all you would have to do is model your mesh and then let the script apply the colors.
    Thanks

    no can do, there's no access to mesh point with scripting, sorry about that.
    have you tried Mesh Tormentor? it is free!!!, but I don't know if it will help with your problem
    http://www.meshtormentor.com/

  • Writing a function to that sorts any object

    I am trying to write a function that sorts any type of array of objects. For example, I want to call
    NewArray = exampleclass.sort(ObjectOfAnyType).
    The sort function has to return a new array. I have run into two errors, however.
    Error #1
    as3.java [21:1] cannot resolve symbol
    symbol : variable Object
    location: class as3
    if (Object instanceof Comparable)
    ^
    Error #2
    as3.java [25:1] incompatible types
    found : java.lang.Object
    required: java.lang.Object[]
    Object [] rtn = obj.clone();
    *** Below is my source code ***
    import java.*;
    public class as3 {
    /** Creates new as3 */
    public static Object sort(Object [] obj)
         if (Object instanceof Comparable)
         if (Object instanceof Cloneable)
         Object [] rtn = obj.clone();
    for (int i = 0; i<obj.length-1; i++)
    for (int j=i+1; j<obj.length; j++)
    if (rtn.compareTo(rtn[j]) == 1)
    Object [] tmp = rtn[i];
    rtn[i] = obj[j];
    rtn[j] = tmp;
    else
    throw new ObjectIsNotComparableException("Object not comparable");
    Any help appreciated. Thanks!

    Changing from "Object" to the name "obj" fixed the
    statement:
    if (obj instanceof Cloneable) but not if (obj
    instanceof Comparable).
    I don't know what's causing this one yet... worry about that in a sec
    I am also getting one new error now:
    as3.java [28:1] cannot resolve symbol
    symbol : method compareTo (java.lang.Object)
    location: class java.lang.Object
    if (rtn[ i].compareTo(rtn[j])
    This one is because rtn[ i] (and rtn[j]) is an Object, which has no method compareTo. Try casting it to a Comparable...
    I think I just worked out why it let you go with the cloneable, but not with the comparable. obj is an array, and sure an array is cloneable, but how could you compare an array? Sure you can compare the elements in the array... So either check if obj[0] instanceof Comparable, or drop the test all together.
    Note: checking obj[0] will give you an exception if someone asks you to sort an array of 0 length (no elements)
    Hope this helps,
    Radish21

  • HELP needed to write a function returning 1 record from join tables

    Hi,
    I would like to have some help to write a function so It can return 1 result.
    I post my question in the APEX Express sextion but I think it's belong here.
    Mount Points and Home Directory
    Also, can I move a thread in another forum?
    thanks
    Roseline
    Edited by: user8772975 on 2009-09-19 21:43

    ok, I think I started to understand the functions. But I still can't figured out
    CONTEXT
    We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    I'm trying to build a search page who will allow for all DVDs and All images name related to the search result. Let say I search for:
    FIGARO
    I have this SQL query and I want to make a function that will return the same thing as:
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    ORDER BY "DVD".NAMEBasiccly, We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    So we have someting like that:
    TITLE: FIGARO
    DVD:        C2008-203
    Elements: 12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif
                    12l11202.tif, 12l12101.tif, 12l12102.tif
    DVD         C2008-204
    Elements: 12l12202.tif, 12l13101.tif, 12l13102.tif, 12l13201.tif, 12l13202.tif,
                   12l14101.tif, 12l14102.tif, 12l14201.tif, 12l14202.tif, 12l15101.tif,
                   12l15102.tif, 12l15201.tif
    DVD:       C2008-205
    Elements: 12l15202.tif, 12l16101.tif, 12l16102.tif, 12l16201.tif, 12l16202.tif,
                    12m01101.tif, 12m01102.tif, 12m01201.tifBased on what people on the forum told me, I now know that I have to use Pl/SQL so I have to write a function that will return the same thing as the prvious query.
    Is that exact?
    Based on this example,
    [http://plsql-tutorial.com/plsql-functions.htm|http://plsql-tutorial.com/plsql-functions.htm]
    I would write something like:
    CREATE FUNCTION my_super_function
    RETURN VARCHAR(2000);
    IS
    details VARCHAR(2000);
    BEGIN
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    RETURN details;
    END;
    / And then, use soemthing like:
    select my_super_function("DOSSIER"."ID") from "DOSSIER" "DOSSIER" where "DOSSIER"."TITLE" = :P3_SEARCHI'm kinda of lost. I spent the last 6 hours but I think that programming is a working progress.
    Any hint would be appreciated,
    thanks
    Roseline

  • How does "Unflatten From String" take a type and return a value of that type?

    http://zone.ni.com/reference/en-XX/help/371361E-01/glang/unflatten_from_string/
    How exactly does the "type" argument for "Unflatten From String" work? I need to create a VI that takes a type, passes it as an argument to several calls of the "Unflatten From String" function, and returns an array containing elements of the type originally passed. The "Unflatten From String" function seems to do some magic though, because the type of the "value" that it outputs changes depending on the type it is passed as input. How do I do the same magic in my VI?
    Ultimately, what I need to accomplish is an unflatten-list operation. Given a type T and a byte string of length L (which contains a concatenation of T elements that are flattened to their bytes), create a VI that unflattens all the types in the string and return an array of length (L / sizeof(T)) that contains each type.
    Note: performing the unflatten-list operation is trivial, but I cannot for the life of me figure out how to do it in a VI that takes a type and returns an array of the appropriate type. By the way, my data is being given to me from another source, so please don't bother suggesting that I should be flattening an array using LabVIEW's "Flatten To String" function in the first place. My data is not given in LabVIEW's array format: http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/flattened_data/
    Thanks a ton!
    -Wakka

    Take a look at this example:  You can see that the flattened string contains several bytes.  The first four bytes contain the length of array (number of elements).  Since the data type is U32, the next 32 bits (4 bytes) contains the value of the first element, and so on.  Could you possibly use this scheme to do what you want to do?  Other data types present different outputs.  You would have to experiment with them.
    - tbob
    Inventor of the WORM Global

Maybe you are looking for

  • Moving iTunes Music to external hard drive

    I am trying to move my iTunes music library to an external hard drive to free up space on my HD, but I'm having trouble. Tried the following, suggested by MacMuse: iTunes Preferences -> Advanced tab; Keep Music Folder organized ... should be enabled.

  • Correct JavaScript Error Detect Settings for Acrobat X

    Can someone tell me what the JavaScript preference settings should be on Acrobat X so Acrobat will detect errors/problems in my JavaScript scripts? Thanks

  • netui:imageButton BUG

    HI, there is problem while i use <netui:imageButton action="save" formsubmit="true"> ..... <netui:imageButton action="delete" formsubmit="true"> .... <netui:imageButton action="cancel" formsubmit="true"> ... this is generating the JavaScript method w

  • Calculating... Charged... Calculating... Charged... Calculating... (etc)

    It seems to confuse my computer when my battery is at 100%. The battery indicator in the status bar will flip back and forth between "Calculating" and "Charged" every few seconds, and even the light on the power adapter will switch from yellow to gre

  • MacPro2,1 optical out surround issues

    Hi I just bought some fancy Tritton AXPRO headphones for my gaming in bootcamp and windows 7. They need that i have Dolby Live support (5.1) on my optical out. (found out after i bought them) I dont know if the mac have this support. In the product d