how to write procedure to insert data in to the table in phpmyadmin?

前端 未结 3 1480
鱼传尺愫
鱼传尺愫 2020-12-31 20:18

I have created table as below:

student:
+----+------+-----------+--------+
|uid | name | user_name | branch |
+----+------+-----------+--------+
|    |               


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 20:24

    # Switch delimiter to //, so phpMyAdmin will not execute it line by line.
    DELIMITER //
    CREATE PROCEDURE usp_rateChapter12
    
    (IN numRating_Chapter INT(11) UNSIGNED, 
    
     IN txtRating_Chapter VARCHAR(250),
    
     IN chapterName VARCHAR(250),
    
     IN addedBy VARCHAR(250)
    
    )
    
    BEGIN
    DECLARE numRating_Chapter INT;
    
    DECLARE txtRating_Chapter VARCHAR(250);
    
    DECLARE chapterName1 VARCHAR(250);
    
    DECLARE addedBy1 VARCHAR(250);
    
    DECLARE chapterId INT;
    
    DECLARE studentId INT;
    
    SET chapterName1 = chapterName;
    SET addedBy1 = addedBy;
    
    SET chapterId = (SELECT chapterId 
                       FROM chapters 
                       WHERE chaptername = chapterName1);
    
    SET studentId = (SELECT Id 
                       FROM students 
                       WHERE email = addedBy1);
    
    SELECT chapterId;
    SELECT studentId;
    
    INSERT INTO ratechapter (rateBy, rateText, rateLevel, chapterRated)
    VALUES (studentId, txtRating_Chapter, numRating_Chapter,chapterId);
    
    END //
    
    //DELIMITER;
    

提交回复
热议问题