我无法创建和使用包
I can't create and using a Package
CREATE OR REPLACE PACKAGE Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE);
END Learning_package;
CREATE OR REPLACE PACKAGE BODY Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE)
IS
BEGIN
INSERT INTO people (C_Name, C_mail, C_age)
VALUES (name_person, mail_person, age_person);
END add_person;
END Learning_package;
/
BEGIN
Learning_package.add_person('john', 'fffff@all.com', 20);
END;
出现错误:
package body "Learning_package" has erros PL/SQL: could not find
program unit being called "Learning_package" at line 3
有人可以帮助我吗?
您能否在创建包后添加一个块终止符并将 AS
更改为 IS
(/)。
CREATE OR REPLACE PACKAGE Learning_package IS
END Learning_package;
/
包体也是如此。
您的代码很好,除了您需要:
- 确保您有一个包含预期列的
people
table;和
- 在每个 PL/SQL 语句末尾的新行中使用
/
语句终止符。
像这样:
CREATE OR REPLACE PACKAGE Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE);
END Learning_package;
/
CREATE OR REPLACE PACKAGE BODY Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE)
IS
BEGIN
INSERT INTO people (C_Name, C_mail, C_age)
VALUES (name_person, mail_person, age_person);
END add_person;
END Learning_package;
/
BEGIN
Learning_package.add_person('john', 'fffff@all.com', 20);
END;
/
注意:年龄不是一件好事,因为它很快就会变成 out-of-date。相反,您应该存储 date-of-birth,当您需要年龄时,您可以根据 date-of-birth 和今天的日期计算它。
db<>fiddle here
CREATE OR REPLACE PACKAGE Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE);
END Learning_package;
CREATE OR REPLACE PACKAGE BODY Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE)
IS
BEGIN
INSERT INTO people (C_Name, C_mail, C_age)
VALUES (name_person, mail_person, age_person);
END add_person;
END Learning_package;
/
BEGIN
Learning_package.add_person('john', 'fffff@all.com', 20);
END;
出现错误:
package body "Learning_package" has erros PL/SQL: could not find program unit being called "Learning_package" at line 3
有人可以帮助我吗?
您能否在创建包后添加一个块终止符并将 AS
更改为 IS
(/)。
CREATE OR REPLACE PACKAGE Learning_package IS
END Learning_package;
/
包体也是如此。
您的代码很好,除了您需要:
- 确保您有一个包含预期列的
people
table;和 - 在每个 PL/SQL 语句末尾的新行中使用
/
语句终止符。
像这样:
CREATE OR REPLACE PACKAGE Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE);
END Learning_package;
/
CREATE OR REPLACE PACKAGE BODY Learning_package AS
PROCEDURE add_person(name_person people.C_Name%type,
mail_person people.C_mail%type,
age_person people.C_age%TYPE)
IS
BEGIN
INSERT INTO people (C_Name, C_mail, C_age)
VALUES (name_person, mail_person, age_person);
END add_person;
END Learning_package;
/
BEGIN
Learning_package.add_person('john', 'fffff@all.com', 20);
END;
/
注意:年龄不是一件好事,因为它很快就会变成 out-of-date。相反,您应该存储 date-of-birth,当您需要年龄时,您可以根据 date-of-birth 和今天的日期计算它。
db<>fiddle here