我想在plsql中創建一個字典對象。 (11g) 字典對象將有三個字段:employee_id,manager_id,持續時間 由於查詢次數,我不想創建表。我想訪問內存中的項目。使用字典(類似於Python字典)
我將使用批量收集將2百萬行插入此字典對象。 後來我想訪問百科對象,如:(334員工ID) dictEmp [334] .manager_id = 8 或返回dictEmp [334] .duration
您能否提供任何文件? 感謝
我想在plsql中創建一個字典對象。 (11g) 字典對象將有三個字段:employee_id,manager_id,持續時間 由於查詢次數,我不想創建表。我想訪問內存中的項目。使用字典(類似於Python字典)
我將使用批量收集將2百萬行插入此字典對象。 後來我想訪問百科對象,如:(334員工ID) dictEmp [334] .manager_id = 8 或返回dictEmp [334] .duration
您能否提供任何文件? 感謝
聽起來像PL/SQL中的關聯數組。
declare
type employee_t is table of emp_demo%rowtype index by pls_integer;
l_employees employee_t;
begin
for r in (
select * from emp_demo
)
loop
l_employees(r.employee_id) := r;
end loop;
dbms_output.put_line('Manager for employee 334 is: ' || l_employees(334).manager_id);
dbms_output.put_line('Manager''s manager is ' || l_employees(l_employees(334).manager_id).employee_name);
end;
測試數據:
create table emp_demo
(employee_id integer primary key
, employee_name varchar2(40)
, manager_id integer
, hiredate date
, duration integer);
insert all
into emp_demo values (8, 'Clark', 5, date '2015-04-02', 18)
into emp_demo values (334, 'Jones', 8, date '2015-01-05', 12)
into emp_demo values (455, 'Smith', 7, date '2015-02-04', 14)
into emp_demo values (566, 'Patel', 6, date '2015-03-03', 16)
select * from dual;
比方說您可以遍歷列表的列[EMPLOYEE_ID,MANAGER_ID,持續時間]列表(稱爲員工):
desired_dict = {}
for employee_id, manager_id, duration in employees:
desired_dict[employee_id] = {"manager_id" : manager_id, "duration" : duration }
#or even better
desired_dict = {employee_id : {"manager_id" : manager_id, "duration" : duration }
for employee_id, manager_id, duration in employees}
#now, you can access an employee like:
some_manager = desired_dict[334]['manager_id']
some_duration = desired_dict[334]['duration']
但你可能想使用類似pandas 和做類似:
import pandas as pd
employees_data = pd.DataFrame(employees, columns=['employee_id', 'manager_id', 'duration'])
employees_data.index = employees_data['employee_id']
desired_dict = employees_data.to_dict()
我認爲存在誤解。想在oracle plsql中實現python dict結構 – user125687
看起來極像一個[臨時表]的作業(http://www.dba-oracle.com/t_temporary_tables_sql.htm)。 – 9000
爲您需要的每個索引創建您的對象的'dict'地圖,並以您的結婚方式。不要使用其他結構過度複雜化,因爲你不會獲得更好的性能,然後使用本地Python'dict'查找。 – zwer
類似[this](https://repl.it/IRaL/2)? – Olian04