In the following example, we have an example already running in PHP. The scenario of the issue is the setting up of a "navigation link" based on a data structure.
$node = '006002009'; // Esta informação é obtida dinamicamente.
$segmentos = strlen($node)/3;
$sql = 'SELECT ACESSO_SCRIPT FROM ACESSO_ADMIN WHERE ACESSO_NIVEL';
$or = '';
SQL command concatenation loop
for($x = 0; $x < $segmentos; $x++){
$comp = $x+1;
$sql.= $OR.'="'.substr($node,0,($indent*$comp)).'" ';
$or = ' OR ACESSO_NIVEL';
}
The result of the loop generates the string:
SELECT ACESSO_SCRIPT FROM ACESSO_ADMIN WHERE ACESSO_NIVEL="006" OR ACESSO_NIVEL="006002" OR ACESSO_NIVEL="006002009"'
The challenge is to achieve the same concatenation of the above loop within the Stored Procedure.
Recalling that the SP would receive as a parameter only the value of $node
. This value is of variable length and follows a composition rule in 3-digit segments.