2012-03-04 60 views
-4

我在sql中有這樣的代碼,它在sql server 2005上運行完美。但是,當我在isql plus中運行此代碼時,它會給出錯誤,我應該如何更改才能運行它。如何在oracle中運行這段sql代碼?

代碼---

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); 
+5

請閱讀關於PL/SQL(閱讀一本書,閱讀Oracle文檔)。該語法與MS SQL語法有很大不同。 – Mat 2012-03-04 18:18:11

+1

你得到了什麼錯誤? – emaillenin 2012-03-04 18:18:14

+0

PLS-00103:遇到下列其中一項時遇到符號「@」: begin函數pragma過程子類型<標識符> – user760946 2012-03-04 18:21:44

回答

2

@ A.B.Cade給the efficient way of doing things。當然,他的語法也可以在SQL Server中工作。因此,練習的目的就是將T-SQL完全轉換爲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; 
/

您應該知道Oracle文檔是全面的,在線的和免費的。你應該學會導航它。 find it here。的問題。

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'; 

沒有檢查它,但是這是一個開始......