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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:46:11+00:00 2026-06-14T08:46:11+00:00

I have 2 tables, Driver and Mechanic and in both table they have a

  • 0

I have 2 tables, Driver and Mechanic and in both table they have a same column Employee#

How do i check both tables using PL/SQL so that an employee in Driver table cannot appear in the Mechanic table by comparing the employee#. And if it happens, it would display a message “Employee# cant be both driver and mechanic!”

I do know that i could simply just compare both table using:

SELECT Employee#
FROM Driver
INTERSECT
SELECT Employee#
FROM Mechanic

But its a requirement for me to use PL/SQL.

I’ve tried using cursor but i cant seem to make it run through the entire column. Here are my code:

declare
cursor c1 is select employee# from driver;
cursor c2 is select employee# from mechanic;
driverenum number(30);
mechanicenum number(30);
begin
open c1;
fetch c1 into driverenum;
close c1;
open c2;
fetch c2 into mechanicenum;
close c2;
if driverenum in (mechanicenum) then
dbms_output.put_line(driverenum);
end if;
end;
/                                                                      
  • 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-14T08:46:12+00:00Added an answer on June 14, 2026 at 8:46 am

    If the only requirement is that you use PL/SQL

    DECLARE
      TYPE emp_nt IS TABLE OF driver.employee#%type;
    
      l_drivers   emp_nt;
      l_mechanics emp_nt;
      l_both      emp_nt;
    BEGIN
      SELECT employee#
        BULK COLLECT INTO l_drivers
        FROM driver;
    
      SELECT employee#
        BULK COLLECT INTO l_mechanics
        FROM mechanic;
    
      l_both := l_drivers MULTISET INTERSECT l_mechanics;
    
      FOR i IN 1 .. l_both.count
      LOOP
        dbms_output.put_line( 'Employee ' || l_both(i) || 
                                ' is employed as both a driver and a mechanic' );
      END LOOP;
    END;
    

    This approach would potentially occupy quite a bit of space in the PGA if there are a large number of rows in either table. But normally it would be almost as efficient as the SQL solution.

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

Sidebar

Related Questions

I have an ETL that is importing tables from Oracle to SQL 2008 using
I have tables linked by FK, I query on the first table using entity
I have a view defined in SQL server 2008 that joins 4 tables together.
i have tables driver, cars and trailers they are all in relationship. and main
I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile
I am writing an if/else alternative using a table driven method. I have the
I'm using jQuery to drive my AJAX UI. I have a table of data,
I have a web-site that generates some simple tabular data as html tables, many
I have two tables. Table 1: supportstatus clientid company status Table 2: client clientid
We have an application that creates a number of Visual Foxpro (DBF) tables. Each

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.