中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Oracle vs PostgreSQL Develop(17) - ARRAY

發布時間:2020-08-11 19:06:03 來源:ITPUB博客 閱讀:273 作者:husthxd 欄目:關系型數據庫

PostgreSQL可用ARRAY來替代Oracle中的collection type,包括associative array/Varrays (Variable-Size Arrays)/Nested Tables

Oracle
簡單舉個例子:

drop table if exists employee;
create table employee(id int,name varchar(30),department varchar(30),salary float);
insert into employee(id,name,department,salary) select rownum,substrb(object_name,1,30),substrb(object_name,1,30),1000 from dba_objects;
DECLARE
   TYPE EmpTabTyp IS TABLE OF employee%ROWTYPE
      INDEX BY PLS_INTEGER;
   emp_tab EmpTabTyp;
   i int := 0;
BEGIN
   /* Retrieve employee record. */
   for c1 in (select * from employee) loop
     emp_tab(i).id := c1.id;
     emp_tab(i).name := c1.name;
     emp_tab(i).department := c1.department;
     emp_tab(i).salary := c1.salary;
     i := i+1;
   end loop;
   -- SELECT * INTO emp_tab(100) FROM employee WHERE id = 100;
END;
/

更簡單的做法是使用bulk collection

DECLARE
   TYPE EmpTabTyp IS TABLE OF employee%ROWTYPE
      INDEX BY PLS_INTEGER;
   emp_tab EmpTabTyp;
   i int := 0;
BEGIN
   /* Retrieve employee record. */
   select id,name,department,salary bulk collect into emp_tab from employee;
END;
/

PostgreSQL
使用ARRAY


drop type record_of_employee;
CREATE TYPE record_of_employee AS (id int,name varchar(30),department varchar(30),salary float);
do
$$
declare
  employees record_of_employee[];
begin
  select array_agg(employee) into employees from employee limit 1;
  raise notice 'id is %',employees[1].id;
  raise notice 'name is %',employees[1].name;
end
$$;

對于Associative array indexed by string,PG的數組則替代不了.

DECLARE
  -- Associative array indexed by string:
  TYPE population IS TABLE OF NUMBER  -- Associative array type
    INDEX BY VARCHAR2(64);            --  indexed by string
...

參考資料
PL/SQL Collections and Records
Oracle PL/SQL Collections: Varrays, Nested & Index by Tables
Collections in Oracle PL/SQL
Working with Collections
Take a Dip into PostgreSQL Arrays

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

萨嘎县| 沁水县| 绩溪县| 科尔| 噶尔县| 沾益县| 德庆县| 湖口县| 镇赉县| 安吉县| 繁峙县| 南溪县| 开鲁县| 利辛县| 麻栗坡县| 黑山县| 通渭县| 唐海县| 赣州市| 南丹县| 乌兰县| 景谷| 姜堰市| 开化县| 莲花县| 江门市| 临朐县| 荆州市| 古田县| 东乌珠穆沁旗| 沾化县| 临沂市| 大洼县| 桃园市| 汝阳县| 金湖县| 札达县| 黎城县| 屯昌县| 高碑店市| 盐边县|