Arbitrarily a query SQL translates to the corresponding number of query result sets

Source: Internet
Author: User

The original idea: like a pair of parentheses, suppose to meet the select on the stack, if you meet from the stack, until the stack is empty, get the position at this time. For string interception.

Implementation method: Meet the character S and after 5 characters elect + 1, meet the character F and 3 characters in a row for ROM-1, when the counter result is 0 o'clock, return the position of the current character, and then the string interception can be:

/****   * Get intercept location   * @param selectsql   * @return * * * public  static  int   Getsubindex (String  selectsql) {System.out.println (Selectsql.length ()); int count = 0;for (int i=0;i<selectsql.length (); i++) {char  c = Selectsql.charat (i); if (c = = ' s ') {if (Selectsql.charat (i+1) = = ' E ' &&selectsql.charat (i+2) = = ' L ' &&   Selectsql.charat (i+3) = = ' E ' &&selectsql.charat (i+4) = = ' C ' &&   selectsql.charat (i+5) = = ' t ') {count++;i=i+5;} Else{continue;}} else if (c = = ' F ') {if (Selectsql.charat (i+1) = = ' R ' &&selectsql.charat (i+2) = = ' O ' &&   Selectsql.charat (i+3) = = ' m ') {                count--;                i=i+3;            System.out.println (count);    if (count = = 0) {    System.out.println (i);    return i+1;}    } Else{continue;}} else {continue;}} return-1;  }

To perform a character intercept operation:

  /** *   string intercept   * @param insql   * @return * */public  static  string   getoutsql (string insql) {  int  index = getsubindex (insql);  if (Index! =-1) {  String outsql  = "SELECT count ( -1) from" + insql.substring (index);  return outsql;  } else{  System.out.println ("Not a  corrent sql");  Return  "Not a corrent sql";  }  }



Arbitrarily a query SQL translates to the corresponding number of query result sets

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.