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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:52:55+00:00 2026-06-16T02:52:55+00:00

I have a question regarding usage of functions in a sql query. I have

  • 0

I have a question regarding usage of functions in a sql query.

I have the following function for getting username from a table

CREATE OR REPLACE
  FUNCTION get_info(
      p_emp_no employees.emp_id%TYPE)
    RETURN VARCHAR2
  AS
    o_userid employees.emp_name%TYPE;
  BEGIN
    SELECT emp_name INTO o_userid FROM employees WHERE emp_id = p_emp_no;
    RETURN o_userid;
  END;
  /

when I use the above function in sql code as

select product_no, get_info(p.raised_by)
from products p, employees e
where p.raised_by  = e.emp_no

execution takes more time than the below sql

select product_no, e.emp_name
from products p, employees e
where p.raised_by  = e.emp_no

The second query is faster than the first query.

So is it advisable to use functions to get username from a table or use direct column name and use join to link with employees table?

Reason why I asked is there could be multiple references to employees table to get username for raised_by, created_by, modified_by etc. So I thought it would be better to use a function to get emp_name instead of multiple joins with employees table.

Any insight into this is highly appreciable.

Thanks

  • 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-16T02:52:56+00:00Added an answer on June 16, 2026 at 2:52 am

    Using a join is the way to go. Using the function will trigger a separate query with a separate index lookup for each row result, greatly slowing down the results.

    I understand your desire to avoid multiple joins, but in your example, three joins would be better than three function calls.

    Think of it this way. The function is doing it’s own join on

    WHERE emp_id = p_emp_no

    And it is not only doing it once, but a separate join for EVERY SINGLE ROW!

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

Sidebar

Related Questions

I have a question regarding the usage of functions in a command in bash.
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
I have question regarding the use of function parameters. In the past I have
I have a question regarding a race condition scenario. The question: Consider the following
I have a question regarding nested doseq loops. In the start function, once I
I have a specific question regarding the usage of profiler. I am new to
I am going over C and have a question regarding const usage with pointers.
I have a question regarding interfaces. I understood that you cannot create instances of
I have a question regarding the usage of using statements around ObjectContext objects in
I have a basic question regarding the usage of ConverterParameter. In the sense -

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.