Declare
   ver_id number;
   treeid nx_trees.tree_id%TYPE;
   rootnode nx_trees.root_node%TYPE;
   cursor tree_cursor is
       select tree_id, root_node from nx_trees;
Begin
   open tree_cursor;
   Loop
      FETCH tree_cursor into treeid, rootnode;
      EXIT WHEN tree_cursor%NOTFOUND;
      select nv.version_id into ver_id from nx_version nv,
       nx_module nm, nx_project np, nx_versions v
      where nv.project_id = np.project_id
      and   nv.module_id = nm.module_id
      and   v.module_name = nm.name
      and   v.project_name = np.name
      and   nv.version_number = v.version_number
      and   np.language_code = v.language_code
      and   v.tree_id = treeid;
      Insert into nx_node
         select  (node_id - rootnode +1),
                 node_type, object_type,
                 ros_groupid, ros_stringid, null,
                 (NVL(parent_node, rootnode - 1)
                                 - rootnode + 1),
                 ver_id
         from nx_nodes where tree_id = treeid;
   End Loop;
   CLOSE tree_cursor;
   COMMIT;
End;
/
