[英]Migrate table variables from SQL Server 2008 R2 to Oracle 11g
I'm trying migrate this code from SQL Server to Oracle but I get many errors; 我正在尝试将此代码从SQL Server迁移到Oracle,但出现很多错误; please can anyone help me?
请任何人能帮助我吗?
Code in SQL Server: SQL Server中的代码:
DECLARE @tblFacultad TABLE
( IdFacultad INT,
NomFacultad VARCHAR(200)
);
INSERT INTO @tblFacultad (IdFacultad, NomFacultad)
SELECT IdFacultad, NomFacultad
FROM FACULTAD_local
SELECT * FROM @tblFacultad
Code in Oracle: Oracle中的代码:
CREATE OR REPLACE TYPE objFacultad AS OBJECT
(
IdFacultad NUMBER,
NomFacultad varchar(255)
)
/
CREATE OR REPLACE TYPE tblFacultad is table of objFacultad;
/
SELECT IDFACULTAD,NOMFACULTAD BULK COLLECT INTO tblFacultad FROM FACULTAD;
When I run the code in Oracle, I get this error: 在Oracle中运行代码时,出现以下错误:
ORA-03001: unimplemented feature
ORA-03001:未实现的功能
03001. 00000 - "unimplemented feature"03001. 00000-“未实现的功能”
*Cause: This feature is not implemented.*原因:未实现此功能。
*Action: None.*操作:无。
Error en la línea: 11, columna: 54错误,错误:11,列:54
You can't define table variables like this in Oracle SQL. 您无法在Oracle SQL中定义这样的表变量。 You can define collection types, which can then be used as table column types or (more usually) as types within PL/SQL code.
您可以定义集合类型,然后将其用作表列类型,或者(通常)用作PL / SQL代码中的类型。 For example:
例如:
create or replace type objfacultad as object
( idfacultad number
, nomfacultad varchar(255)
)
/
create or replace type tblfacultad is table of objfacultad;
/
declare
demo_t tblfacultad;
begin
select objfacultad(idfacultad,nomfacultad) bulk collect into demo_t
from ( select 1 as idfacultad, 'F1' as nomfacultad from dual
union all
select 2 as idfacultad, 'F2' as nomfacultad from dual ) facultad;
dbms_output.put_line('Array contains ' || demo_t.count || ' elements:');
for r in (
select f.idfacultad, f.nomfacultad
from table(demo_t) f
)
loop
dbms_output.put_line(r.idfacultad || ' ' || r.nomfacultad);
end loop;
end;
/
Output: 输出:
Array contains 2 elements:
1 F1
2 F2
Note that the create type
statements are SQL , and the section starting declare
is a PL/SQL block. 请注意,
create type
语句是SQL ,开始declare
部分是一个PL / SQL块。 When working with Oracle we have to be aware of this distinction. 使用Oracle时,我们必须意识到这种区别。 Whether I used PL/SQL Developer, Toad, a text editor or anything else makes no difference.
无论我使用PL / SQL Developer,Toad,文本编辑器还是其他工具,都没有区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.