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 6602393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:52:18+00:00 2026-05-25T18:52:18+00:00

I’m dong some SQL work this week and I normally write Java. I need

  • 0

I’m dong some SQL work this week and I normally write Java.

I need to add some if’s into my SQL like so, but don’t want to do any string concatenation.

This should be an easy one: I just don’t know the SQL syntax

I want to make all those “AND” statements “if” conditions for params I’m passing in

Would I have to do something like this:

     IF p_sac IS NOT NULL
 THEN
    stmt := stmt || ' AND nsns.sac = ''' || p_sac || '''';
 END IF;

 IF p_value1 IS NOT NULL
 THEN                                                        
    stmt := stmt || ' AND UPPER(value1s.value1) LIKE ''' || UPPER(p_value1) || ''' ';
 END IF;

Or is there an alternative to this above?

Basically I’ve got this:

FUNCTION summarize_item_search_data (p_obj_code IN VARCHAR2,  p_value1 IN VARCHAR2,
                                                               p_sac IN NUMBER,    p_job_type_id    IN NUMBER,
                                                               p_value4 IN NUMBER)
  RETURN sys_refcurvalue2
  IS
  result_cur   sys_refcurvalue2;  
BEGIN

     OPEN result_cur FOR

       SELECT DISTINCT jp.id, jp.row_top.mwslin AS mwslin, jp.obj_code, jp.jobload_year, jp.row_top.fiscal_year AS fiscal_year,
                                      nsns.sac, value1s.value1, nsns.nsn,
         DECODE( jp.row_top.nsn_id, NULL, jp.row_top.nomenclature ,nsns.nomenclature) AS nomenclature, jp.row_top.value4 AS value4
        FROM scabs sch, jobs JP, master_nsn nsns, master_value1 value1s, TABLE(value1s.group_id) (+) ntab, 
                 groups pgds
  WHERE jp.row_top.nsn_id = nsns.id(+) AND nsns.value1_id = value1s.id(+)
-- stmt := stmt || ' AND ''' || p_year || ''' = ntab.fiscal_year(+)';
        AND ntab.group_id = pgds.id(+)    
        AND nsns.sac = p_sac
        AND UPPER(value1s.value1) LIKE UPPER(p_value1) 
        AND UPPER(jp.obj_code) = UPPER(p_obj_code)
        AND jp.row_top.value4 <=   p_value4
        AND jp.row_top.job_type_id =p_job_type_id


  RETURN result_cur;
  END summarize_item_search_data;
  • 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-05-25T18:52:19+00:00Added an answer on May 25, 2026 at 6:52 pm

    Just put it all into your WHERE clause as conditions:

    WHERE
        (p_sac IS NULL OR nsns.sac = p_sac) AND
        ....
    

    If performance suffers greatly then you might want to look into using dynamic SQL, but I would start with the approach above.

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

Sidebar

Related Questions

This should be an easy problem but... I need to format a currency for
OK, I hope I explain this one correctly. I have a struct: typedef struct
I'm trying to extract a bunch of lines from a CSV file and write
I have the below xml <ResultCollection> <Result Id=551550 Pass=23 Fail=0 Owner=Dong/> <Result Id=551565 Pass=4
this is a general form code <form name=search_form action= method=POST> <input type=text name=search_text> <input
So this is new, I'm trying to create clean CSS, here's my code example:
What am I dong wrong here? return $em->createQuery( SELECT p FROM SomeBundle:Page p WHERE
Basically I want to be able to do be able to parse a JavaScript-like
The data file looks like: x=a1, y=b1, z=c1 x=a2, y=b2, z=c2 ... I want
I'm not an C++ expert and still do not have a great intuitive grasp

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.