# Use ? as placeholders for the values my $sth2 = $dbh->prepare(<fetchrow_array() ) { my ($id, $name, $title, $dept) = @row; # Now when executing, just pass the values you want to the execute # statement, and DBI will pass the properly-quoted values to the # DBD backend in the order specified (i.e., $id will be used for # the first ?, $name for the second, etc.) $sth2->execute( $id, $name, $title, $dept ); } #### $dbh->do(" CREATE GLOBAL TEMPORARY TABLE HR.Tempest( ID INT, NAME VARCHAR2(25), TITLE VARCHAR2(50), DEPT VARCHAR2(100) ) ON COMMMIT PRESERVE ROWS "); $dbh->commit(); # Tell the database to select the rows of interest and populate the # temporary table with them $dbh->do(" INSERT INTO HR.Tempest SELECT e.employee_id, e.first_name, j.job_title, d.department_name FROM HR.employees e, HR.jobs j, HR.departments d WHERE e.job_id = j.job_id AND e.department_id = d.department_id "); $dbh->commit(); #### INSERT INTO HR.Tempest INSERT INTO HR.Tempest SELECT e.employee_id, e.first_name, j.job_title, d.department_name FROM HR.employees e JOIN HR.jobs j ON j.job_id = e.job_id JOIN HR.departments d ON d.department_id = e.department_id WHERE #### ---- We want to find employees making over $150K/yr in marketing or sales. ---- However, the department_id of marketing and sales teams are split into ---- dozens of regions, so we'll have to use the boss' department to ---- narrow the list of employees. That's fine, though, as we need the ---- bosses information, too. SELECT boss.employee_id as boss_id, boss.first_name as boss_name, boss_j.job_title as boss_title, boss_d.department_name as boss_dept, emp.employee_id as emp_id, emp.first_name as emp_name, emp_j.job_title as emp_title, emp_d.department_name as emp_dept, emp.salary as emp_salary ---- Standard table hookup for the boss FROM HR.employees boss JOIN HR.jobs boss_j ON boss_j.job_id = boss.job_id JOIN HR.departments boss_d ON boss_d.department_id = boss_e.department_id ---- Standard table hookup for the employee -- tie the employee to their boss JOIN HR.employees emp ON emp.boss_id = boss.employee_id JOIN HR.jobs emp_j ON emp_j.job_id = emp.job_id JOIN HR.departments emp_d ON emp_d.department_id = emp_e.department_id ---- Now select the employees we're looking for. WHERE boss.department_name IN ('MARKETING', 'SALES') AND emp.salary > 150000;