在 oracle 中声明行类型记录时无效的 SQL 语句
invalid SQL statement while declaring a rowtype record in oracle
我正在尝试在 oracle 中显示记录行类型,我得到了
SQL 错误 [900] [42000]:ORA-00900:第 7 行的 SQL 语句无效
此处:
intraftrecord xyz%rowtype;
我想不通。
CREATE OR REPLACE PROCEDURE intraftresponseprocedure
IS
CURSOR xyz IS
select REGEXP_REPLACE(RESPONSE_PARAM , '-', '') from (
select RESPONSE_PARAM from AUDIT_LOG WHERE ACTIVITY ='Intra Bank Funds Transfer' order by id asc
);
intraftrecord xyz%rowtype;
BEGIN
OPEN xyz;
LOOP
FETCH xyz INTO intraftrecord;
EXIT WHEN intraftrecord%notfound;
dbms_output.put_line(intraftrecord);
END LOOP;
END;
您必须在打印语句中指定列名 -
CREATE OR REPLACE PROCEDURE intraftresponseprocedure
IS
CURSOR xyz IS
select REGEXP_REPLACE(RESPONSE_PARAM , '-', '') col1 from (
select RESPONSE_PARAM from AUDIT_LOG WHERE ACTIVITY ='Intra Bank Funds Transfer' order by id asc
);
intraftrecord xyz%rowtype;
BEGIN
OPEN xyz;
LOOP
FETCH xyz INTO intraftrecord;
EXIT WHEN xyz%notfound;
dbms_output.put_line(intraftrecord.col1);
END LOOP;
END;
三期-
- 具有
%found
属性的是游标,而不是记录。
dbms_output.put_line()
将单个 varchar2 作为参数,而不是 xyz%rowtype
- 你需要参考
intraftrecord
你想显示的具体属性,所以游标需要给它起一个名字。
固定版本:
create or replace procedure intraftresponseprocedure
as
cursor xyz is
select regexp_replace(response_param, '-', '') as response
from ( select response_param
from audit_log
where activity = 'Intra Bank Funds Transfer'
order by id asc );
intraftrecord xyz%rowtype;
begin
open xyz;
loop
fetch xyz into intraftrecord;
exit when xyz%notfound;
dbms_output.put_line(intraftrecord.response);
end loop;
end;
游标也可以简化,不需要显式声明和获取游标和记录。简化版:
create or replace procedure intraftresponseprocedure
as
begin
for r in (
select regexp_replace(response_param, '-', '') as response
from audit_log
where activity = 'Intra Bank Funds Transfer'
order by id asc
)
loop
dbms_output.put_line(r.response);
end loop;
end;
我正在尝试在 oracle 中显示记录行类型,我得到了
SQL 错误 [900] [42000]:ORA-00900:第 7 行的 SQL 语句无效
此处:
intraftrecord xyz%rowtype;
我想不通。
CREATE OR REPLACE PROCEDURE intraftresponseprocedure
IS
CURSOR xyz IS
select REGEXP_REPLACE(RESPONSE_PARAM , '-', '') from (
select RESPONSE_PARAM from AUDIT_LOG WHERE ACTIVITY ='Intra Bank Funds Transfer' order by id asc
);
intraftrecord xyz%rowtype;
BEGIN
OPEN xyz;
LOOP
FETCH xyz INTO intraftrecord;
EXIT WHEN intraftrecord%notfound;
dbms_output.put_line(intraftrecord);
END LOOP;
END;
您必须在打印语句中指定列名 -
CREATE OR REPLACE PROCEDURE intraftresponseprocedure
IS
CURSOR xyz IS
select REGEXP_REPLACE(RESPONSE_PARAM , '-', '') col1 from (
select RESPONSE_PARAM from AUDIT_LOG WHERE ACTIVITY ='Intra Bank Funds Transfer' order by id asc
);
intraftrecord xyz%rowtype;
BEGIN
OPEN xyz;
LOOP
FETCH xyz INTO intraftrecord;
EXIT WHEN xyz%notfound;
dbms_output.put_line(intraftrecord.col1);
END LOOP;
END;
三期-
- 具有
%found
属性的是游标,而不是记录。 dbms_output.put_line()
将单个 varchar2 作为参数,而不是xyz%rowtype
- 你需要参考
intraftrecord
你想显示的具体属性,所以游标需要给它起一个名字。
固定版本:
create or replace procedure intraftresponseprocedure
as
cursor xyz is
select regexp_replace(response_param, '-', '') as response
from ( select response_param
from audit_log
where activity = 'Intra Bank Funds Transfer'
order by id asc );
intraftrecord xyz%rowtype;
begin
open xyz;
loop
fetch xyz into intraftrecord;
exit when xyz%notfound;
dbms_output.put_line(intraftrecord.response);
end loop;
end;
游标也可以简化,不需要显式声明和获取游标和记录。简化版:
create or replace procedure intraftresponseprocedure
as
begin
for r in (
select regexp_replace(response_param, '-', '') as response
from audit_log
where activity = 'Intra Bank Funds Transfer'
order by id asc
)
loop
dbms_output.put_line(r.response);
end loop;
end;