使用 PLSQL 创建记录
Creating a Record using PLSQL
我正在尝试创建一个非常基本的程序。我只需要为 table 中的单行创建一条记录。我错过了什么?我收到的错误代码是 "encountered the symbol declare when expecting...."
Create or Replace Procedure Luke as
Declare
Type type_basket is record(Term_code section.term_code%type,
Subject_Code section.subject_code%type,
Course_Number section.course_number%type,
Section section.section%type);
Rec_Basket type_basket;
Begin
Select term_code, subject_code, course_number, section into Rec_basket
from Enrollment
where term_code=201201 and course_number=105;
dbms.output_put.line(rec_basket.term_code);
end;
DECLARE
只需要 anonymous blocks and subblocks, you don't use it to declare stored procedure variables:
Note:
The declarative part of a subprogram does not begin with the keyword DECLARE, as the declarative part of an anonymous block does.
所以删除那行:
Create or Replace Procedure Luke as
Type type_basket is ...
Rec_Basket type_basket;
Begin
Select ...
end;
/
您可以使用 %rowtype
变量而不是显式声明记录类型,并且 select 将整行放入其中,但我假设您的作业专门针对记录。
我正在尝试创建一个非常基本的程序。我只需要为 table 中的单行创建一条记录。我错过了什么?我收到的错误代码是 "encountered the symbol declare when expecting...."
Create or Replace Procedure Luke as
Declare
Type type_basket is record(Term_code section.term_code%type,
Subject_Code section.subject_code%type,
Course_Number section.course_number%type,
Section section.section%type);
Rec_Basket type_basket;
Begin
Select term_code, subject_code, course_number, section into Rec_basket
from Enrollment
where term_code=201201 and course_number=105;
dbms.output_put.line(rec_basket.term_code);
end;
DECLARE
只需要 anonymous blocks and subblocks, you don't use it to declare stored procedure variables:
Note:
The declarative part of a subprogram does not begin with the keyword DECLARE, as the declarative part of an anonymous block does.
所以删除那行:
Create or Replace Procedure Luke as
Type type_basket is ...
Rec_Basket type_basket;
Begin
Select ...
end;
/
您可以使用 %rowtype
变量而不是显式声明记录类型,并且 select 将整行放入其中,但我假设您的作业专门针对记录。