Solved

call another MySQL SP from within a MySQL SP

Posted on 2013-11-22
8
379 Views
Last Modified: 2013-11-26
Dear all,

can I simply called a SP within another SP ? like

CREATE PROCEDURE `create_auditriggers` (IN databaseName VARCHAR(40))  	
BEGIN  
DECLARE a, b, finished  INT DEFAULT 10;
DECLARE temptable VARCHAR(50);	
DECLARE today TIMESTAMP DEFAULT CURRENT_DATE;
DECLARE v1, v2, v3 TINYINT ;
DECLARE current_tablelist VARCHAR(50) DEFAULT ""; 
DECLARE fullexcutecmd VARCHAR(5000);
DECLARE fullexcutecmd2 VARCHAR(5000) ;

/*Declare and populate the cursor with a SELECT statement */  	
	
DECLARE tablename CURSOR FOR 	
SELECT DISTINCT TABLE_NAME 	
    FROM INFORMATION_SCHEMA.COLUMNS	
    WHERE TABLE_SCHEMA=databaseName;   	
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;     
/*Specify what to do when no more records found, notice that the handler declaration must appear after variable and cursor declaration inside the stored procedures*/  	
OPEN tablename;	

	get_tabeslist: LOOP	
 
   FETCH tablename INTO current_tablelist;	
         IF finished = 1 THEN 	
          LEAVE  get_tabeslist;	
          END IF;	
    
 call Create_BEFORE_DELETE_TRIGGER ('databaseName','QRTZ_BLOB_TRIGGERS')

  
  END LOOP  get_tabeslist;	
close tablename;                             

END $$
DELIMITER ;

Open in new window


or I need to do Concat to build the whole string of calling SP again:

SET @fullexcutecmd =  CONCAT(' call Create_BEFORE_DELETE_TRIGGER ('databaseName',dhfahfdfdsfl')
,';');  

PREPARE stmt FROM @fullexcutecmd;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;  

Open in new window

0
Comment
Question by:marrowyung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39670887
yes, you can call a procedure inside another procedure like this:

call Create_BEFORE_DELETE_TRIGGER ('databaseName','QRTZ_BLOB_TRIGGERS')

& if you define the inner procedure with "out" parameters, then the outer procedure can react to the result (if that is needed).
see: http://dev.mysql.com/doc/refman/5.0/en/call.html
0
 
LVL 1

Author Comment

by:marrowyung
ID: 39672461
For example please. It seems I don't have too.
0
 
LVL 1

Author Comment

by:marrowyung
ID: 39673656
it seems that we can't do IF NOT EXISTs then create trigger logic ?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 1

Author Comment

by:marrowyung
ID: 39673668
"& if you define the inner procedure with "out" parameters, then the outer procedure can react to the result (if that is needed).
see: http://dev.mysql.com/doc/refman/5.0/en/call.html "

is that mean somehting like, when it return something out,we can use set @variable = for that ?
0
 
LVL 1

Author Comment

by:marrowyung
ID: 39676665
0
 
LVL 1

Author Comment

by:marrowyung
ID: 39676984
"& if you define the inner procedure with "out" parameters, then the outer procedure can react to the result (if that is needed)."

how can we make use of it ?
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39677221
IF you need to

like any returned value, IF you need to make a decision later based on that value
0
 
LVL 1

Author Comment

by:marrowyung
ID: 39679709
I don't understand this:

"IF you need to make a decision later based on that value"

please give some example.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question