Oracle vs PostgreSQL Develop(17) - ARRAY
发表于:2025-11-08 作者:千家信息网编辑
千家信息网最后更新 2025年11月08日,PostgreSQL可用ARRAY来替代Oracle中的collection type,包括associative array/Varrays (Variable-Size Arrays)/Neste
千家信息网最后更新 2025年11月08日Oracle vs PostgreSQL Develop(17) - ARRAY
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
例子
做法
参考资料
数组
资料
参考
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
坦克世界怎么添加到服务器
戴尔t420服务器最大内存
吃鸡手游一直显示服务器维护中
安徽大数据软件开发大概多少钱
如何用云盘建立数据库
2018年网络安全题集
游戏每日任务数据库表的设计
条形码数据库下载
普陀区项目软件开发收费套餐
软件开发工作效率评价
漫画主题手抄报网络安全
云开发的数据库代码在哪里
数据库加密了怎么处理回来
我的世界服务器怎么给玩家标签
数据库1104
寻找手机软件开发合作
游戏服务器租赁哪家便宜
哈尔滨东塔网络安全特训营哪家好
深圳智能软件开发平台
关于网络安全的故事50字
黑客文化与网络安全期末测试答案
数据库配置还原
ef core数据库查询优化
生态环境局网络安全自查自评报告
网络服务器地址设置
软件开发 女 33岁了
联想服务无法连接至服务器
下载管理服务器
服务器储存客户信息
游戏服务器租赁哪家便宜