gpt4 book ai didi

sql - Oracle 无效使用类型名称或子类型名称

转载 作者:行者123 更新时间:2023-12-04 23:02:15 33 4
gpt4 key购买 nike

正在使用的这个块有什么问题?请帮助解决这个问题。
将根据 where 子句仅选择一行。

餐 table

Name Type          Nullable Default Comments 
---- ------------- -------- ------- --------
ID NUMBER(10)
NAME VARCHAR2(100) Y

PL/SQL 块:
declare
type clazzes_row_type is record
(clazz_rownum number,
clazz_id clazzes.id%type,
clazz_name clazzes.name%type);
begin
clazzes_row_type.clazz_rownum :=111;
select id,name into clazzes_row_type.clazz_id,clazzes_row_type.clazz_name
from clazzes where name ='leo1';
dbms_output.put_line(clazzes_row_type.clazz_id);
dbms_output.put_line(clazzes_row_type.clazz_rownum);
dbms_output.put_line(clazzes_row_type.clazz_name);
end;

异常(exception):
ORA-06550: line 8, column 1:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 8, column 1:
PL/SQL: Statement ignored
ORA-06550: line 9, column 21:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 9, column 75:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 1:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 22:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 11, column 1:
PL/SQL: Statement ignored
ORA-06550: line 12, column 22:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 12, column 1:
PL/SQL: Statement ignored
ORA-06550: line 13, column 22:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 13, column 1:
PL/SQL: Statement ignored

最佳答案

您应该声明一个具有指定类型的变量。并使用构造函数实例化您的变量:

declare
type clazzes_row_type is record
(clazz_rownum number,
clazz_id clazzes.id%type,
clazz_name clazzes.name%type);

myvariable clazzes_row_type;

begin
myvariable := clazzes_row_type(111, null, null);

或选择:
begin
select 111,id,name into myvariable from clazzes where name ='leo1';

关于sql - Oracle 无效使用类型名称或子类型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20573566/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com