当前位置:网站首页>Traversal of Oracle stored procedures

Traversal of Oracle stored procedures

2022-07-07 20:10:00 Jianghu crab

The following content mainly introduces Oracle Stored procedure , How to use for Loop through the spliced SQL sentence , And implement .

  1. The cycle of writing
    notes : For the sake of brevity , In the following code block “SQL sentence ” Of SQL It will be shown below .
FOR ARR IN (SQL sentence ) LOOP 

--  Console printing ( During the official run , It is suggested to delete or comment )
DBMS_OUTPUT.PUT_LINE(ARR.SS);
	
--  perform sql
EXECUTE IMMEDIATE ARR.SS;

END LOOP; 

Don't tangle with the following statement , Just see what you like . Mainly to express the final implementation SQL How did you get it .( Splicing sql You cannot add a semicolon at the end of a statement , Otherwise execution sql Will make mistakes )

SELECT 'UPDATE SCHOOL_ROll SET ROLL = '|| S.ROLL || 'WHERE ID = ' || S.ID FROM STUDNETS AS S
  1. Complete stored procedure statements
CREATE 
	OR REPLACE PROCEDURE "SP_OA_SL" AS BEGIN
	
	--  Traverse SQL Execution results 
	FOR ARR IN ( SQL sentence  ) LOOP
		
		--  Console printing ( During the official run , It is suggested to delete or comment )
		DBMS_OUTPUT.PUT_LINE ( ARR.SS ); 
		
        --  perform sql
	    EXECUTE IMMEDIATE ARR.SS;
	
    END LOOP;
END;
原网站

版权声明
本文为[Jianghu crab]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071803104649.html