将结果SQL查询表复制到另一个表中

时间:2018-10-10 20:31:03

标签: oracle stored-procedures plsql

我正在蟾蜍里工作。在这里,我想创建一个过程,其中将根据执行的选择查询创建一个新表。但我收到此错误:

  

[错误] PLS-00103(15:21):PLS-00103:遇到以下情况之一时遇到了符号“ CREATE”:

  ( - + case mod new not null <an identifier>
   <a double-quoted delimited-identifier> <a bind variable>
   continue

以下是我的过程代码,到目前为止,有人可以指导我哪里出错了。

create or replace procedure fire
is
  v_full_name VARCHAR2(500);
  sal varchar(200);
  jobid varchar(100);
  cpct varchar(50);
  mgid varchar(25);
  did varchar(20);
  cid varchar(20);
  rid varchar(20);
  lid varchar(20);

  Begin

  execute immediate create table resquery as

  (
 select HR.EMPLOYEES.FIRST_NAME||' '||HR.EMPLOYEES.LAST_NAME AS 
 Full_Name,HR.EMPLOYEES.SALARY as sal,HR.EMPLOYEES.JOB_ID as ji,
 HR.EMPLOYEES.COMMISSION_PCT as cmpct,HR.EMPLOYEES.MANAGER_ID as 
 mgid,HR.EMPLOYEES.DEPARTMENT_ID as dep,HR.COUNTRIES_EXTERNAL.COUNTRY_ID as 
 country,HR.DW_REGION.R_ID as region,
 HR.LOCATIONS.LOCATION_ID as loc
 into v_full_name,sal,jobid,cpct,mgid,did,cid,rid,lid
 from HR.EMPLOYEES
 join HR.DEPARTMENTS ON 
 HR.EMPLOYEES.DEPARTMENT_ID=HR.DEPARTMENTS.DEPARTMENT_ID
 join HR.LOCATIONS    ON HR.DEPARTMENTS.LOCATION_ID=HR.LOCATIONS.LOCATION_ID
 join HR.COUNTRIES_EXTERNAL ON HR.LOCATIONS.COUNTRY_ID=HR.COUNTRIES_EXTERNAL.COUNTRY_ID
 join HR.DW_REGION    ON HR.COUNTRIES_EXTERNAL.REGION_ID=HR.DW_REGION.R_ID
 where HR.COUNTRIES_EXTERNAL.COUNTRY_ID='US'
 AND trunc(HR.EMPLOYEES.HIRE_DATE) BETWEEN TO_DATE('16/08/2002','DD/MM/YYYY') AND 
 TO_DATE('07/12/2007','DD/MM/YYYY'))




  end
  /

1 个答案:

答案 0 :(得分:0)

立即执行需要一个字符串。将CREATE语句括在引号中。 另外,立即执行是命令,并且必须后跟分号。

const