PL / SQL:ORA-00904:无效的标识符&PL / SQL:忽略的语句&PLS-00364:循环索引变量的使用无效

问题描述 投票:0回答:1
@C:\Users\4\Desktop\dbdrop;
@C:\Users\4\Desktop\dbcreate;
SET SERVEROUTPUT ON;
 begin
     for cur_r in
      (select order_id, company_name, order_date
        from orders
        where order_date < trunc(sysdate)
          and rownum <= 5
        )
     loop
        dbms_output.put_line('------------');
       dbms_output.put_line('Order ID   = ' || cur_r.order_id);
       dbms_output.put_line('Order date = ' || to_char(cur_r.order_date, 'dd.mm.yyyy'));
       dbms_output.put_line('Company    = ' || cur_r.company_name);
     end loop;
   end;
  /

错误报告-

ORA-06550:第3行,第27列:PL / SQL:ORA-00904:“ COMPANY_NAME”:不合法的识别符ORA-06550:第3行,第10列:PL / SQL:SQL语句被忽略ORA-06550:第10行,第49列:PLS-00364:循环索引变量'CUR_R'使用无效ORA-06550:第10行,第7列:PL / SQL:语句被忽略ORA-06550:第11行,第58列:PLS-00364:循环索引变量'CUR_R'使用无效ORA-06550:第11行,第8列:PL / SQL:语句被忽略ORA-06550:第12行,第49列:PLS-00364:循环索引变量'CUR_R'使用无效ORA-06550:第12行,第7列:PL / SQL:语句被忽略06550。00000-“%s行,%s列:\ n%s”*原因:通常是PL / SQL编译错误。*操作:

Here is the ORDERS table
CREATE TABLE ORDERS
(
    ORDER_ID        NUMBER(9)   NOT NULL,
    CUSTOMER_CODE   VARCHAR(5)  NOT NULL,
    EMPLOYEE_ID     NUMBER(9)   NOT NULL,
    ORDER_DATE      DATE        NOT NULL,
    REQUIRED_DATE   DATE,
    SHIPPED_DATE    DATE,
    SHIP_VIA        VARCHAR(40),
    FREIGHT         NUMBER(10,2)    DEFAULT 0,
    SHIP_NAME       VARCHAR(40),
    SHIP_ADDRESS    VARCHAR(60),
    SHIP_CITY       VARCHAR(15),
    SHIP_REGION     VARCHAR(15),
    SHIP_POSTAL_CODE    VARCHAR(10),
    SHIP_COUNTRY    VARCHAR(15),
    CONSTRAINT PK_ORDERS PRIMARY KEY (ORDER_ID),
    CONSTRAINT FK_CUSTOMER_CODE FOREIGN KEY (CUSTOMER_CODE) REFERENCES CUSTOMER(CUSTOMER_CODE),  
    CONSTRAINT FK_EMPLOYEE_ID FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID),  
    CONSTRAINT FK_SHIP_VIA FOREIGN KEY (SHIP_VIA) REFERENCES SHIPPER(COMPANY_NAME)  
);
plsql plsqldeveloper
1个回答
0
投票

在SQL Developer中,您不能复制/粘贴我以前在SQL * Plus中写的内容;您将省略行号(和SQL>提示),仅使用此代码:

set serveroutput on
begin
  for cur_r in
    (select order_id, ship_via as company_name, order_date
     from orders
     where order_date < trunc(sysdate)
       and rownum <= 5
    )
  loop
    dbms_output.put_line('------------');
    dbms_output.put_line('Order ID   = ' || cur_r.order_id);
    dbms_output.put_line('Order date = ' || to_char(cur_r.order_date, 'dd.mm.yyyy'));
    dbms_output.put_line('Company    = ' || cur_r.company_name);
  end loop;
end;
/
© www.soinside.com 2019 - 2024. All rights reserved.