2017-09-24 117 views
0

我在嘗試將此代碼從SQL Server遷移到Oracle,但出現很多錯誤;請任何人都可以幫助我?將表變量從SQL Server 2008 R2遷移到Oracle 11g

代碼在SQL Server:

DECLARE @tblFacultad TABLE 
(IdFacultad INT, 
    NomFacultad VARCHAR(200) 
); 

INSERT INTO @tblFacultad (IdFacultad, NomFacultad) 
    SELECT IdFacultad, NomFacultad 
    FROM FACULTAD_local 

SELECT * FROM @tblFacultad 

代碼在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; 

當我運行在Oracle中的代碼,我得到這個錯誤:

ORA-03001: unimplemented feature
03001. 00000 - "unimplemented feature"
*Cause: This feature is not implemented.
*Action: None.
Error en la línea: 11, columna: 54

+0

[PL/SQL Developer](https://www.allroundautomations.com/plsqldev.html)是一個使用Oracle SQL和PL/SQL的桌面工具,類似於[SQL Developer](http:// www .oracle.com/technetwork/developer-tools/sql-developer/what-is-sqldev-093866.html)或Toad。我認爲你在這裏問的是[Oracle SQL](http://www.oracle.com/technetwork/database/database-technologies/sql/overview/index.html)。 –

回答

1

你可以用」在Oracle SQL中定義像這樣的表變量。您可以定義集合類型,然後可以將其用作PL/SQL代碼中的表列類型或(更常見)類型。例如:

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; 
/

輸出:

Array contains 2 elements: 
1 F1 
2 F2 

注意,create type陳述SQL,和起始declare的部分是一個PL/SQL塊。在與Oracle合作時,我們必須瞭解這種區別。無論我使用PL/SQL Developer,Toad,文本編輯器還是其他任何東西都沒有區別。

相關問題