-4

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);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user760946
  • 95
  • 1
  • 8
  • 5
    Please go read about PL/SQL (get a book, read the Oracle docs). The syntax is very different from MS SQL syntax. – Mat Mar 04 '12 at 18:18
  • PLS-00103: Encountered the symbol "@" when expecting one of the following: begin function pragma procedure subtype type – user760946 Mar 04 '12 at 18:21
  • m getting this error . i am trying to learn. But to do this to a single peice of code . i have to learn complete oracle. – user760946 Mar 04 '12 at 18:22
  • In future please use the documentation to answer these lame syntax questions rather than flooding SO with them. I've linked to the relevant section in my answer. – APC Mar 05 '12 at 04:21

2 Answers2

2

@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.

Community
  • 1
  • 1
APC
  • 144,005
  • 19
  • 170
  • 281
0
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...

APC
  • 144,005
  • 19
  • 170
  • 281
A.B.Cade
  • 16,735
  • 1
  • 37
  • 53