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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:59:54+00:00 2026-06-01T06:59:54+00:00

Suppose I have an Oracle 11.2 database containing the following table: TABLE: SURVEY PARAMETER

  • 0

Suppose I have an Oracle 11.2 database containing the following table:

TABLE: SURVEY

PARAMETER    MALE   FEMALE 
--------------------------
SAMPLE_SIZE  102       95
AVG_WEIGHT   170      120
AVG_HEIGHT   5.9      5.4

Here’s an example minimal PL/SQL stored procedure that selects the average weight of males and places it (e.g. 170) into variable v_stat.

PROCEDURE get_stat (gender IN VARCHAR2) 
AS
    v_stat number;
BEGIN
    SELECT male INTO v_stat FROM survey WHERE parameter = 'avg_weight';
END get_stat;

Notice the IN parameter gender doesn’t do anything here. What I want is to pass in variable gender, which may equal either ‘male’ or ‘female’, and use gender somehow in the SELECT statement (instead of ‘male’). The goal is to pass in gender as a variable that may be used to return, for example, the average weight of, either male or female, as defined by gender.

I know I can probably use an IF/THEN/ELSE statement with two separate SELECT statements, but I wondered if there was an elegant way to use just one SELECT statement by changing ‘male’ in the above SELECT statement to something else?

Note that this is a re-do of my previous question here

How to programmatically set table name in PL/SQL?

that was (rightly) criticized for not being a realistic question.

  • 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-01T06:59:55+00:00Added an answer on June 1, 2026 at 6:59 am

    You’d need to use the same dynamic SQL approach that was suggested in your other question

    PROCEDURE get_stat (gender IN VARCHAR2) 
    AS
        v_sql   varchar2(1000);
        v_param varchar2(100) := 'AVG_WEIGHT';
        v_stat  number;
    BEGIN
        v_sql := 'SELECT ' || gender || ' FROM survey WHERE parameter = :1';
        EXECUTE IMMEDIATE v_sql
                     INTO v_stat
                    USING v_param;
    END get_stat;
    

    But you’d have the same general objections that were raised in your earlier question– the data model is fundamentally flawed. You would be much better served having a separate row for MALE and FEMALE survey results rather than having separate columns for male and female results.

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

Sidebar

Related Questions

Suppose that, I use Oracle database. If my table have a lot of data
Suppose I have an AFTER ALTER trigger on my Oracle database and I rename
Suppose I have a database table with two fields, foo and bar. Neither of
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
Suppose I have several enums representing ... for example database vendors: Unknown , Oracle
Currently on my oracle table, I have the following if condition on my procedure
Suppose I have two Oracle databases. We'll call them database A and database B.
Suppose I have an Oracle stored procedure of the following form: procedure validate_entity1(p_id number,
Suppose you have a standard org hierarchy table in Oracle. For simplicity sake, assume
Suppose we have a table A: itemid mark 1 5 2 3 and table

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.