Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:38:50+00:00 2026-06-17T09:38:50+00:00

Consider a table with 3 columns Value1 operator value2 abc = xyz 1 !=

  • 0

Consider a table with 3 columns

Value1   operator     value2
abc          =               xyz
1            !=               2
5            >                8
9            <=              11
xyz          is not Null
{null val}   is null

I want to write a genric function which returns the validated result either true or false
by validating value1 with value2 using the operator
or check value1 in case of ‘is null’ and ‘is not null’ operators (Last two cases)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:38:51+00:00Added an answer on June 17, 2026 at 9:38 am

    You could do something like this with dynamic SQL (note that in reality you’d need to add a bunch of logic to prevent SQL injection attacks)

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace function evaluate( p_val1 in varchar2,
      2                                       p_op   in varchar2,
      3                                       p_val2 in varchar2 )
      4    return varchar2
      5  is
      6    l_result varchar2(1);
      7    l_sql_stmt varchar2(1000);
      8  begin
      9    if( p_val2 is not null )
     10    then
     11      l_sql_stmt := 'select (case when :1 ' || p_op || ' :2 then ''Y'' else ''N'' end) from dual';
     12      execute immediate l_sql_stmt
     13         into l_result
     14        using p_val1, p_val2;
     15    else
     16      l_sql_stmt := 'select (case when :1 ' || p_op || ' then ''Y'' else ''N'' end) from dual';
     17      execute immediate l_sql_stmt
     18         into l_result
     19        using p_val1;
     20    end if;
     21    return l_result;
     22* end;
    SQL> /
    
    Function created.
    
    SQL>  select evaluate( 'xyz', 'is not null', null )
      2     from dual;
    
    EVALUATE('XYZ','ISNOTNULL',NULL)
    --------------------------------------------------------------------------------
    Y
    
    SQL> select evaluate( 'abc', '=', 'xyz' )
      2    from dual;
    
    EVALUATE('ABC','=','XYZ')
    --------------------------------------------------------------------------------
    N
    

    Since you are storing the data in a table, that implies that each column is a VARCHAR2. My guess, though, is that you don’t always want to use string comparison semantics. For example, the string ‘9’ is greater than the string ’11’ while the number 9 is less than the number 11. If you want to use something other than string comparison semantics, you’d need to add code that inspected the parameters and applied whatever logic you would like to determine what comparison semantics you want to apply and then generated the appropriate dynamic SQL statement.

    I would strongly question the wisdom of the requirement, however. First off, it makes little sense from a data model standpoint to store numeric data in a VARCHAR2 column– when you find yourself trying to mix string and numeric data in the same column, you’ve almost always made a data model mistake. I would also be hard-pressed to imagine what business problem you are trying to solve that would involve this sort of dynamic function– it seems likely that there is a better way to solve whatever problem you are attempting to solve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following table: CREATE TABLE Participations ( roster_id INTEGER NOT NULL, round_id INTEGER
Consider a table: a b c d key1 value1 value2 value3 key2 value1a value3a
Consider i have a user table and I have three columns mobilePhone , homePhone
Consider a table or CTE structured like this: Name Num ---- ---- Abc 12
Consider a fact table of the form: CREATE TABLE Fact1 ( Dim1 int NOT
Please consider this sql statements Create table abc (A int, B int ) insert
Consider this example - the table item has two columns, key and value .
I want to check if a particular row exists in Data table or not.
Consider a table with 3 columns: ID (unique, taken from an Oracle sequence), CATEGORY
I just stuck to update the below table columns. Consider below scripts. declare @Table1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.