Question

I have this code in sql, it runs perfectly on sql server 2005. But when i run this code in isql plus, it gives error, what changes should I make to run it.

code is---

DECLARE @stu_Name VARCHAR(50), @stu_Address VARCHAR(50)
SELECT @stu_Name = g.stu_Name,@stu_Address= g.stu_address 
FROM student as g
WHERE unique_no = 's121' 
INSERT INTO 
   dbo.student(stu_no, stu_name, dateofbirth,stu_unique_no, stu_name,stu_address)
VALUES
     (13, 'John', '1990-12-12','s121', @stu_Name, @stu_Address);
Was it helpful?

Solution

@A.B.Cade gives the efficient way of doing things. Of course, his syntax would have worked in SQL Server too. So preseumably the object of the exercise is to exactly translate the T-SQL into PL/SQL.

DECLARE 
    l_stu_Name. student.stu_Name%type;
    l_stu_Address student student.stu_address%type;
BEGIN
    SELECT stu_Name, stu_Address
    into  l_stu_Name, l_stu_address 
    FROM student as g
    WHERE unique_no = 's121' ;
    INSERT INTO 
       dbo.student(stu_no, stu_name, dateofbirth,stu_unique_no, stu_name,stu_address)
    VALUES
         (13, 'John', '1990-12-12','s121', l_stu_Name, l_stu_Address);
END;
/

You should know that the Oracle documentation is comprehensive, online and free. You should learn to navigate it. find it here. questions.

OTHER TIPS

INSERT INTO 
   dbo.student(stu_no, stu_name, dateofbirth,stu_unique_no, stu_name,stu_address)
SELECT 13, 'John', to_date('1990-12-12','yyyy-mm-dd'),g.unique_no, g.stu_Name, g.stu_address
FROM student as g
WHERE unique_no = 's121';

didn't check it but this is a start...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top