oracle shortest_path

CREATE OR REPLACE PACKAGE shortest_path_pkg

AS

TYPE node_dist_rt IS RECORD(fpoint INT, dvalue INT);

TYPE node_dist_tt IS TABLE OF node_dist_rt INDEX BY PLS_INTEGER;

TYPE graph_node_rt IS RECORD(NAME VARCHAR2(100), isvisited BOOLEAN);

TYPE graph_node_tt IS TABLE OF graph_node_rt INDEX BY PLS_INTEGER;

TYPE graph_dist_tt IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;

TYPE graph_dist_nt IS TABLE OF graph_dist_tt INDEX BY PLS_INTEGER;

PROCEDURE add_node(graph_nodes IN OUT graph_node_tt,NAME VARCHAR2);

FUNCTION  get_minnode(graph_nodes IN graph_node_tt, graph_dists IN graph_dist_nt, dnode INT) RETURN PLS_INTEGER;

PROCEDURE add_node_dist(graph_dist_inst IN OUT graph_dist_nt, snode INT, enode INT, dvalue INT);

PROCEDURE cals_min_gdist(graph_nodes IN OUT graph_node_tt, graph_dist_inst IN graph_dist_nt, snode IN OUT INT);

PROCEDURE INIT_dist_inst(graph_dist IN OUT graph_dist_nt, nodes_cnt INT);

END;

CREATE OR REPLACE PACKAGE BODY shortest_path_pkg

AS

PROCEDURE add_node(graph_nodes IN OUT graph_node_tt, NAME VARCHAR2)

AS

tmp_node graph_node_rt;

BEGIN

tmp_node.name := NAME;

tmp_node.isvisited := FALSE;

graph_nodes(graph_nodes.count + 1) := tmp_node;

END add_node;

FUNCTION get_minnode(graph_nodes IN graph_node_tt, graph_dists IN graph_dist_nt, dnode INT) RETURN PLS_INTEGER

AS

dest_node PLS_INTEGER := -1;

minval    PLS_INTEGER := 999999999;

BEGIN

FOR tlvl IN 1..graph_dists(dnode).count LOOP

IF NOT graph_nodes(tlvl).isvisited AND graph_dists(dnode)(tlvl) < minval THEN

minval := graph_dists(dnode)(tlvl);

dest_node := tlvl;

END IF;

END LOOP;

RETURN dest_node;

END get_minnode;

PROCEDURE add_node_dist(graph_dist_inst IN OUT graph_dist_nt, snode INT, enode INT, dvalue INT)

AS

BEGIN

graph_dist_inst(snode)(enode) := dvalue;

graph_dist_inst(enode)(snode) := dvalue;

END add_node_dist;

PROCEDURE INIT_dist_inst(graph_dist IN OUT graph_dist_nt, nodes_cnt INT)

AS

BEGIN

FOR i IN 1..nodes_cnt LOOP

FOR j IN 1..nodes_cnt LOOP

graph_dist(i)(j) := 999999999;

END LOOP;

END LOOP;

END init_dist_inst;

PROCEDURE cals_min_gdist(graph_nodes IN OUT graph_node_tt, graph_dist_inst IN graph_dist_nt, snode IN OUT INT)

AS

tmp_cnt INT := 0;

dest_node INT;

node_dist_nt node_dist_tt;

node_dist_rec node_dist_rt;

tmp_dist INT;

BEGIN

FOR i IN 1..graph_nodes.count LOOP

node_dist_rec.fpoint := snode;

node_dist_rec.dvalue := graph_dist_inst(snode)(i);

node_dist_nt(i) := node_dist_rec;

END LOOP;

WHILE (tmp_cnt < graph_nodes.count) LOOP

dest_node := get_minnode(graph_nodes,graph_dist_inst, snode);

IF(dest_node = -1) THEN

raise_application_error(-20001, ‘there exists a gap‘);

END IF;

graph_nodes(dest_node).isvisited := TRUE;

tmp_dist := graph_dist_inst(snode)(dest_node);

FOR i IN 1..graph_nodes.count LOOP

IF(node_dist_nt(i).dvalue>(tmp_dist+graph_dist_inst(dest_node)(i))) THEN

node_dist_nt(i).dvalue := tmp_dist + graph_dist_inst(dest_node)(i);

node_dist_nt(i).fpoint := dest_node;

END IF;

END LOOP;

snode := dest_node;

tmp_cnt := tmp_cnt + 1;

END LOOP;

FOR i IN 1..node_dist_nt.count LOOP

dbms_output.put_line(‘节点‘||graph_nodes(i).name||‘,  父节点:  ‘||node_dist_nt(i).fpoint||‘ 距离:‘||node_dist_nt(i).dvalue);

END LOOP;

END cals_min_gdist;

END;

时间: 2024-10-04 15:19:58

oracle shortest_path的相关文章

oracle安装故障:完美解决xhost +报错: unable to open display “”

oracle安装 先切换到root用户,执行xhost + 然后再切换到oracle用户,执行export DISPLAY=:0.0 出现乱码执行export LANG=US_en 在这里给大家介绍下两种情况的常见问题: 一种是本地运行的命令,另一种则是远程ssh命令安装. DISPLAY科普 DISPLAY变量是用来设置将图形显示到何处.比如CENTOS,你用图形界面登录进去,DISPLAY自动设置为DISPLAY=:0.0表示显式到本地监视器,那么通过终端工具(例如:xshell)进去,运行

Sqlserver通过链接服务器访问Oracle的解决办法

转自http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 一.创建sqlserver链接服务(sqlserver链接oracle)  首先sqlserver 链接oracle可以通过两个访问接口: “MSDAORA” 和“OraOLEDB.Oracle” 1.“MSDAORA”访问接口是由Microsoft OLE DB Provider for Oracle提供的,这里建议不使用此接口进行链接.通过该访问接口建立的链接服务器在进行查询orac

win7 64位系统 PB连接oracle数据库出现“oracle library oci.dll could not be loaded”问题的解决方法

今天与大家分享一个自己的学习笔记,希望能给遇到同样问题的人带来帮助. 不知道大家在win7 64位系统下用 PB连接oracle数据库时,是否遇到过“oracle library oci.dll could not be loaded”问题. 今天,在win7 64位系统下用 PB连接oracle数据库时,一直出现上述错误,在百度上找了很久,都没有找到一个完整的解决方案,咨询了很多人,(他们都说是我的PB和oracle没装好,但我装的时候没出现任何问题,一切都很顺利,而且PB和oracle都能正

Oracle 10g通过创建物化视图实现不同数据库间表级别的数据同步

摘自:http://blog.csdn.net/javaee_sunny/article/details/53439980 目录(?)[-] Oracle 10g 物化视图语法如下 实例演示 主要步骤 在A节点创建原表和物化视图日志 在B节点创建连接A节点的远程链接 在B节点处创建目标表和与目标表名称相同的物化视图 在B节点处刷新物化视图 升级采用存储过程定时任务JOB方式定时刷新物化视图 进一步优化 文章更新记录 参考文章 Oracle 10g 物化视图语法如下: create materia

Oracle静默安装

测试CentOS 6.5_x64下静默安装Oracle 11g R2数据库 [一.下载地址] http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html Oracle 11g 联机文档: http://www.oracle.com/pls/db112/homepage [二.系统要求] 内存:1G(官方最低要求1G) 硬盘:40G(企业版安装所需4.29G和1.7G数据文件) 检查的命令 内

ORACLE实际执行计划与预估执行计划不一致性能优化案例

  在一台ORACLE服务器上做巡检时,使用下面SQL找出DISK_READ最高的TOP SQL分析时,分析过程中,有一条SQL语句的一些反常现象,让人觉得很奇怪: SELECT SQL_ID,        SQL_TEXT,        DISK_READS,        BUFFER_GETS,        PARSING_SCHEMA_NAME,        EXECUTIONS FROM   V$SQLAREA ORDER  BY DISK_READS DESC; 在SQL D

PL/SQL developer 连接oracle数据库报错“initialization error could not load oci.dll”

声明:PL/SQL 版本:PL/SQL Developer 9.0.6 (http://files.allroundautomations.com/plsqldev906.exe) 报错提示如图: 原因:PL/SQL只对32位OS进行支持,解决方法是额外加载一个oci.dll文件 解决办法:1.下载OCI.DLL相关库文件.地址: (需注册Oracle账号) http://www.oracle.com/technetwork/topics/winsoft-085727.html ----->  

20、oracle用户管理恢复

下面会一一讲解控制文件.redo文件及非归档模式.归档模式数据文件丢失的情况下,如何恢复数据? (1)控制文件(controlfile)丢失 在做恢复实验之前,先备份好数据. 案例1.模拟一个控制文件丢失 select name from v$controlfile; SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------

oracle数据库(新建数据库)超小白篇

用过Mysql.sqlserver.Oracle 不知道有没有比oracle建库还复杂的 显示:win10系统 1.找到文件夹Oracle-OraDb10g_home1 2.选择Database Configuration Assistant,运行程序 3.选择下一步 ...................................................................................结束..............................