Home > Back-end >  Insert data into existing table using stored procedure
Insert data into existing table using stored procedure

Time:01-04

I create a student table and I try to insert data into that student table using a stored procedure.

Please help me to insert data using stored procedure.

CREATE TABLE students
(
    student_id   integer not null ,
    student_name varchar(100),
    student_age  integer,
    mobile_no    varchar(20)
);

CREATE PROCEDURE sp_student
    (@student_id   int,
     @student_name varchar(100),
     @student_age  varchar(100),
     @mobile_no    varchar(20)) 
AS
BEGIN
    INSERT INTO students (student_id, student_name, student_age, mobile_no)
    VALUES (@student_id, @student_name, @student_age, @mobile_no);
END;

I didn't get answer above I mentioned query, help me to solve this.

CodePudding user response:

I assume you are on LUW. Remove the AS in your CREATE PROCEDURE ... statement:

CREATE PROCEDURE sp_student(
                            @student_id   int,
                            @student_name varchar(100),
                            @student_age  varchar(100),
                            @mobile_no    varchar(20)
                            )
BEGIN
...

See CREATE PROCEDURE (SQL) statement

  • Related