One of Oracle statement optimizations

Source: Internet
Author: User

 PublicList<tddepartment>CREATEZTREEDEP (String compid) {List<TdDepartment> DD =NewArraylist<tddepartment>(); Find SQL statements for all child departments
String SQL = "Select Dep_id,dep_name,super_id,folder from Td_department" + "Start with super_id in (" + "Select dep_id from Td_department" + "where VALID_FL AG = ' Y ' and comp_id = ' "+compid+" ') connect by prior dep_id = super_id ";
Find the SQL statement for the department itself String parentsql = "Select dep_id, Dep_name,super_id,folder from td_department" + "where Valid_flag = ' Y ' and comp _id = ' "+compid+" ' ";
epdb DB=Newepdb (); ArrayList<HashMap> Parentdeparts =Db.gethashdata (Parentsql); ArrayList<HashMap> departs =db.gethashdata (SQL); if(Parentdeparts = =NULL|| Parentdeparts.size () <= 0) return NULL;
Add a department to the listfor (int i=0; i<parentdeparts.size (); i++) {String dep_id = Parentdeparts.get (i ). Get ("dep_id"). ToString (); String dep_name = Parentdeparts.get (i). Get ("Dep_name"). ToString (); String super_id = Parentdeparts.get (i). Get ("super_id"). ToString (); Tddepartment td = New Tddepartment (); Td.setid (dep_id); Td.setpid (super_id); Td.setname (Dep_name); if (Parentdeparts.get (i). Get ("folder") = null) {String folder = Parentdeparts.get (i). Get ("folder"). toString (); if ("Y". Equals (folder)) {Td.setopen ("true");//non-leaf nodes need to be expanded}else{Td.set Open ("false"); }}//Cancel loop read//td.setchild (createdepartments (dep_id)); Dd.add (TD); } //Add child departments to list for (int i=0; i<departs.size (); i++) {String dep_id = Departs.get (i). Get ("dep_id"). ToString (); String dep_name = Departs.get (i). Get ("Dep_name"). ToString (); String super_id = Departs.get (i). Get ("super_id"). ToString (); Tddepartment td = New Tddepartment (); Td.setid (dep_id); Td.setpid (super_id); Td.setname (Dep_name); if (Departs.get (i). Get ("folder") = null) {String folder = Departs.get (i). Get ("folder"). ToString (); if ("Y". Equals (folder)) {Td.setopen ("true");//non-leaf nodes need to be expanded}else{ Td.setopen ("false"); }}//Cancel loop read//td.setchild (createdepartments (dep_id)); Dd.add (TD); } returnDD; }

Need to optimize points:

Think one: Optimize with SQL statement optimization

Thinking two: Optimizing by means of program recursion

One of Oracle statement optimizations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.