Procedure "complex"

Asked

Viewed 207 times

5

Hello.

I’m learning procedures and I have a question:

DELIMITER $$

CREATE PROCEDURE `atualiza_telefone` (IN telefone INT)
BEGIN  

IF (telefone IS NULL) THEN
SELECT * FROM cliente; 

ELSE UPDATE cliente
SET telefone = "4444-4444"
WHERE seg_nome = 'Binatti';
END IF;

END $$

DELIMITER ;

I would like to, in case the phone is updated, put to make a SELECT * FROM cliente, to show that your phone has been updated.

Can someone help me? Grateful!

  • More to serve your select? you will show where it was changed ?

  • It would serve to show the table with the new values.

  • Okay, will you do this through an application? only this parameter does proc have? if it is you don’t need the IF (telefone IS NULL) THEN
SELECT * FROM cliente; for you call the proc you have to pass the parameter this way will never be IS NULL

  • The if I put it just to understand how it worked. I tried to play as many things as possible. It was just to see how I would react.

  • Come on, in what situation would you call one PROCEDURE updating if not to update the data. If you have an application updating your client, for example, you probably already have his data in your change form, when you call your Proc you inform what is being changed. So that you would return what was changed if you already have in your application?

  • Okay, I get what you mean. select soon after updating the data. I wanted to understand this stop of two instructions in a single clause, you know? I don’t get your reason for being "unnecessary", but I wanted to know how it works.

  • Well, by the standard

Show 2 more comments

2 answers

1

Inside the IF, just after the WHERE, I would try the following:

IF (phone IS NOT NULL) THEN

    UPDATE cliente
    SET telefone = "4444-4444"
    WHERE seg_nome = 'Binatti;
    SELECT * FROM CLIENTE

0

I go this way not exactly as an answer, but by formatting.

Well, by the standard PROCEDURES should not return values, but if you are going to do this you have to select it in the final statement.

See if it works.

Now if your intention is;

I wanted to understand this stop of two instructions in a single cloister, understands?

You need to explain better what you want.

DELIMITER $$

CREATE PROCEDURE `atualiza_telefone` (IN telefone INT)
BEGIN  

    IF (telefone IS NOT NULL) THEN

        UPDATE cliente
        SET telefone = "4444-4444"
        WHERE seg_nome = 'Binatti';

    ELSE 

        SELECT * FROM cliente; 

    END IF;


END $$

DELIMITER ;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.