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

  • Home
  • SEARCH
  • 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 7760787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:58:56+00:00 2026-06-01T13:58:56+00:00

I created the following simple PL/SQL stored procedure example to ask a specific question.

  • 0

I created the following simple PL/SQL stored procedure example to ask a specific question. This procedure inserts an employee name and id number into a table called employees_???. The ??? is explained below.

PROCEDURE hire_employee (emp_id IN INTEGER, name IN VARCHAR2, country IN VARCHAR2) 
AS
BEGIN
    INSERT INTO employees_??? VALUES (emp_id, name, 1000);
END hire_employee;

What I need is to set the table name based on the IN variable country. For example,

If country = ‘usa’, I want the INSERT line to read:

INSERT INTO employees_usa VALUES (emp_id, name, 1000);

If country = ‘germany’, I want the INSERT line to read:

INSERT INTO employees_germany VALUES (emp_id, name, 1000);

If country = ‘france’, I want the INSERT line to read:

INSERT INTO employees_france VALUES (emp_id, name, 1000);

etc…

Is there a way to do this in PL/SQL by substituting something in place of employee_??? so only one line of code for INSERT is used? Or is using a case or if/then/else statement the best way?

  • 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-01T13:58:57+00:00Added an answer on June 1, 2026 at 1:58 pm

    To answer your question, you have to use execute immediate and create your statement dynamically.

    create or replace procedure hire_employee (
            emp_id IN INTEGER
          , name IN VARCHAR2
          , country IN VARCHAR2 ) is
    
       -- maximum length of an object name in Oracle is 30
       l_table_name varchar2(30) := 'employees_' || country;
    
    begin
        execute immediate 'insert into ' || l_table_name
                           || ' values (:1, :2, 1000)'
          using emp_id, name;
    end hire_employee;
    

    However, this is a massively over-complicated way of storing the data. If you want to select all data you have to union large numbers of tables.

    It would be far better to normalise the database properly and add country to an employees table.

    Something like the following:

    create table employees (
        emp_id number(16)
      , country varchar2(3) -- ISO codes
      , name varchar2(4000) -- maximum who knows what name people might have
      , < other_columns >
      , constraint pk_employees primary key ( emp_id )
        );
    

    Your procedure then becomes a very simple insert statement:

    create or replace procedure hire_employee (
           emp_id in integer
         , name in varchar2
         , country in varchar2 ) is
    
        insert into employees
        values ( emp_id, country, name, 1000 );
    
    end hire_employee;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created following stored procedure in my SQL server 2005 database for general pagination:
We have the following simple Stored Procedure that runs as an overnight SQL server
I am creating a simple stored procedure in VS 2010/SQL Server 2008 as follows:
Why can the Linq to SQL designer not understand the following stored procedure and
I have the following data returned buy a simple SQL query. The Number of
I've created a simple .NET MVC project, following the walkthrougth on MSDN.com. I'm confused
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I am using the following code snippets to insert values using stored procedure. the
I am trying to write a simple Oracle Stored Procedure: CREATE OR REPLACE PROCEDURE
i have a simple oracle stored procedure proc1 as follows: CREATE OR REPLACE PROCEDURE

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.