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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:51:24+00:00 2026-06-15T14:51:24+00:00

So say I have a user defined function: CREATE FUNCTION ADDRESS_EXISTS_FULL ( line_1 VARCHAR(64),

  • 0

So say I have a user defined function:

CREATE FUNCTION ADDRESS_EXISTS_FULL (
    line_1 VARCHAR(64),
    line_2 VARCHAR(64),
    city VARCHAR(64),
    state VARCHAR(32),
    zip VARCHAR(10),
    type INT(3)
)
RETURNS INT(1)
DETERMINISTIC
READS SQL DATA
BEGIN
    DECLARE aid INT;

    SET aid = NULL;

    SELECT addressid INTO aid FROM dlp.address as a
        WHERE a.line_1 = line_1
            AND a.line_2 = line_2
            AND a.city = city
            AND a.state = state
            AND a.zip = zip
            AND a.address_type = type
            LIMIT 1;

    RETURN IF(aid IS NOT NULL, 1, 0);

END$$

How do I make it so that some of these are not necessary? Like say if type is not needed, is there anyway to call

 SELECT ADDRESS_EXISTS_FULL(l1,l2,c, s, z)

or would that fail? And how do I make that function work?

Thanks.

Note: I don’t need this function stored, it’s a one off so it’s in one big mysql script file.

  • 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-15T14:51:25+00:00Added an answer on June 15, 2026 at 2:51 pm

    You can rewrite the query inside stored function body to something like

    SELECT addressid INTO aid FROM dlp.address as a
        WHERE (a.line_1 = p_line_1 OR p_line_1 IS NULL)
            AND (a.line_2 = p_line_2 OR p_line_2 IS NULL)
             --.... etc
            LIMIT 1;
    

    Thus, if you pass null for a particular parameter, it will be ignored. Also, I’d recommend avoiding naming parameters exactly the same as fields in the table – it may lead to very subtle bugs (In the query above I prepended ‘p_’ to each parameter).
    Finally, I’d not use DETERMINISTIC keyword for a function that is non-deterministic by nature.

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

Sidebar

Related Questions

I have two user defined collection types. The first type has the columns: CREATE
How do I make something like user-defined __repr__ in Python? Let's say I have
Let's say we have a function that changes a password for a user in
Say that I have some user-defined complex struct, like struct usrStruct{ double a; T1
I have in my application a user defined function which takes a comma separated
I have been able to create php function to determine a list of zip
Let's say I have User model and Post model. Post model contains field user_id
Let's say I have a user that entered 12 links into the database but
Let's say I have an user registration form. In this form, I have the
For instance, let's say I have a User model. Users have things like logins,

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.