[英]Apex Oracle success with compilation error
I am trying to create a body PACKAGE in SQL that contains 3 procedures for adding a customer, removing a customer and listing all customers. 我正在尝试在SQL中创建一个正文包,其中包含3个过程,用于添加客户,删除客户和列出所有客户。 But it gives me the ORA-24344 error.
但这给了我ORA-24344错误。
This is my code: 这是我的代码:
CREATE OR REPLACE PACKAGE BODY c_package AS
--Adds a customer
PROCEDURE addCustomer(c_id customers.id%type,
c_name customers.name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type)
IS
BEGIN
INSERT INTO customers(id,name,age,address,salary)
VALUES(c_id,c_name,c_age,c_addr,c_sal);
END addCustomer;
--Removes a customer
PROCEDURE delCutomer(c_id customers.id%TYPE) IS
BEGIN
DELETE FROM customers
WHERE id = c_id;
END delCustomer;
--Lists all customers
PROCEDURE listCustomer IS
CURSOR c_customers is
SELECT name FROM customers;
TYPE c_list is TABLE OF customers.name%type;
name_list c_list := c_list();
counter integer := 0;
BEGIN
FOR n IN c_customers LOOP
counter := counter + 1;
name_list.extend;
name_list(counter) := n.name;
dbms_output.put_line('Customer(' ||counter||') '||name_list(counter));
END LOOP;
END listCustomer;
END c_package;
The problem was that the PROCEDURE inside the PACKAGE BODY had to be ended with just an "END" not "END procedure_name". 问题是包装体内部的过程必须以“ END”而不是“ END procedure_name”结束。
This is the correct code: 这是正确的代码:
CREATE OR REPLACE PACKAGE BODY c_package AS
--Adds a customer
PROCEDURE addCustomer(c_id customers.id%type,
c_name customers.name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type)
IS
BEGIN
INSERT INTO customers(id,name,age,address,salary)
VALUES(c_id,c_name,c_age,c_addr,c_sal);
END;
--Removes a customer
PROCEDURE delCutomer(c_id customers.id%TYPE) IS
BEGIN
DELETE FROM customers
WHERE id = c_id;
END;
--Lists all customers
PROCEDURE listCustomer IS
CURSOR c_customers is
SELECT name FROM customers;
TYPE c_list is TABLE OF customers.name%type;
name_list c_list := c_list();
counter integer := 0;
BEGIN
FOR n IN c_customers LOOP
counter := counter + 1;
name_list.extend;
name_list(counter) := n.name;
dbms_output.put_line('Customer(' ||counter||') '||name_list(counter));
END LOOP;
END;
END c_package;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.