MySQL Forums
Forum List  »  MySQL Workbench

Re: Error in SQL query
Posted by: Robin John
Date: April 03, 2019 11:25PM

One more question,

In the query below, is there a need to use COMMIT; somewhere.

Thanks

Robin John Wrote:
-------------------------------------------------------
> Hello Peter,
>
> Thank you for pointing in the right direction.
> Took me a while to understand Procedures but was
> definitely worth it. Also I learnt some other
> complexities of a database. Here is the query that
> worked for me:
> DELIMITER $$
> CREATE DEFINER=`root`@`localhost` PROCEDURE
> `AddText`()
> BEGIN
>
>
> DECLARE post_status INT DEFAULT 0;
>
> DECLARE post_counter INT;
>
> DECLARE post_total INT;
>
> DECLARE post_currentId INT;
> SELECT MIN(counter) FROM wp_text INTO
> post_counter;
>
>
> SELECT MAX(counter) FROM wp_text INTO post_total;
> WHILE(post_counter IS NOT NULL AND
> post_counter<=post_total)
> DO
> SELECT Id FROM wp_text WHERE counter =
> post_counter INTO post_currentId;
>
> SELECT Active from teksten WHERE Id =
> post_currentID INTO post_status;
>
> IF post_status = 1 THEN
>
> UPDATE wp_text
> set Active = "publish"
> WHERE counter = post_counter;
>
> ELSE
>
> UPDATE wp_text
> set Active = "pending"
> WHERE counter = post_counter;
>
> END IF;
>
> SET post_counter = post_counter + 1;
>
> END WHILE;
>
> END$$
> DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
378
April 03, 2019 01:51AM
170
April 03, 2019 02:09AM
233
April 03, 2019 11:12PM
Re: Error in SQL query
175
April 03, 2019 11:25PM
211
April 04, 2019 10:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.