How to do this recursion ?! Select & nbsp; a, (select & nbsp; B & nbsp; from & nbsp; c & nbsp; where & nbsp ;...) & nbsp; as & nbsp; d, efrom & nbsp; f, (select & nbsp; j & nbsp; from & nbsp; h & nbsp; how to do this recursion ?!
select a,
(select b from c where ...) as d,
e
from f,(select j from h where ...) as i
where ....
I want to replace the content after select in the outer select... from... and keep the content after from. Finally changed:
select count(*)
from f,(select j from h where ...) as i
where ....
In fact, this is equivalent to the replacement of xml/html nodes, similar to the recursive problem. after thinking for a long time, I did not expect a solution.
------ Solution --------------------
Regular... no
If you just want to get the number of returned rows, you can always do this:
Select count (*) from (
-- Your SQL --
Select,
(Select B from c where...) as d,
E
From f, (select j from h where...) as I
Where ....
) Tmp
If you want to strictly replace it, perform syntax analysis, consider single double quotation marks, parentheses, and so on ....
------ Solution --------------------
I don't know if you want to write SQL commands or replace strings.
If you want to replace strings, you can write
$ S = <TXT
Select,
(Select B from c where...) as d,
E
From f, (select j from h where...) as I
Where ....
TXT;
$ Ar = preg_split ('/(\(? \ Bselect \ B
------ Solution --------------------
\ Bfrom \ B)/I ', $ s,-1, PREG_SPLIT_NO_EMPTY
------ Solution --------------------
PREG_SPLIT_DELIM_CAPTURE );
$ N = 0;
$ St = array ();
For ($ I = 0; $ I
$ T = strtolower ($ ar [$ I]);
If ($ t = 'select'
------ Solution --------------------
$ T = '(select '){
$ St [] = $ I;
}
If ($ t = 'from '){
If (count ($ st) = 1) break;
Array_pop ($ st );
}
}
For ($ I --; $ I >$ st [0] + 1; $ I --) unset ($ ar [$ I]);
$ Ar [$ st [0] + 1] = "count (*) \ n ";
Echo join ('', $ ar );
Select count (*)
From f, (select j from h where...) as I
Where ....