目標機器存儲過程創建失敗
可能是少一個空格的問題
也就是那個 DELIMITER //
在 DELIMITER與 // 之間, 有一個空格.
DELIMITER//
CREATEPROCEDUREHelloWorld()
BEGIN
SELECT'HelloWorld';
END//
DELIMITER;
callHelloWorld();
+-------------+
|HelloWorld|
+-------------+
|HelloWorld|
+-------------+
1rowinset(0.00sec)
QueryOK,0rowsaffected(0.00sec)註:如果HelloWorld都失敗,那麼首先需要檢查資料庫的存儲引擎
mysql>showvariableslike'%storage_engine%';
+----------------+--------+
|Variable_name|Value|
+----------------+--------+
|storage_engine|MyISAM|
+----------------+--------+
1rowinset(0.00sec)
存儲引擎為InnoDB的資料庫,能使用存儲過程。
mysql>showvariableslike'%storage_engine%';
+----------------+--------+
|Variable_name|Value|
+----------------+--------+
|storage_engine|InnoDB|
+----------------+--------+
1rowinset(0.01sec)
B. db2創建存儲過程報錯
首先第一個錯誤,分號,應該是英文分號; 而不是中文;
C. 創建存儲過程報錯如下: 警告: 創建的過程帶有編譯錯誤。
1. 創建完存儲過程(在命令行),可以用showerr看具體錯誤
2. 可以在PLSQL中,輸入"全班排名", 然後俺右鍵->編輯,看到具體錯誤
3. 你的sql從from後一直到group by的分號;是多餘的,即便單獨在SQL窗口也會報錯
SQL應該改成
select b.學號,a.姓名, avg(a.成績) 平均分,sum(a.成績) 總分
from 成績信息表 a
join 學籍信息表 b on (a.學號=b.學號)
join 班級信息表 c on (c.班級號=b.班級號)
where c.班級名稱=class
group by b.學號
order by avg(成績) ,b.學號 desc;
4. 存儲過程不能直接用SQL,要用游標或select……into方式
比如:
create or replace procere 全班排名(
class in char(8)
)
as
cursor cur(p_class char(8)) is
select b.學號,a.姓名, avg(a.成績) 平均分,sum(a.成績) 總分
from 成績信息表 a
join 學籍信息表 b on (a.學號=b.學號)
join 班級信息表 c on (c.班級號=b.班級號)
where c.班級名稱=class
group by b.學號
order by avg(成績) ,b.學號 desc;
rs cur%rowtype;
begin
for rs in cur(class) loop
dbms_output.put_line(rs.學號||','||rs.姓名||','||rs.平均分||','||rs.總分);
end loop;
end;
D. 調用存儲過程失敗
SqlConnection conn=new SqlConnection(「connectionString」);
SqlDataAdapter da = new SqlDataAdapter();
da.selectCommand = new SqlCommand();
da.selectCommand.Connection = conn;
da.selectCommand.CommandText = "NameOfProcere";
da.selectCommand.CommandType = CommandType.StoredProcere;
param = new SqlParameter("@ParameterName", SqlDbType.DateTime);
param.Direction = ParameterDirection.Input;
param.Value = Convert.ToDateTime(inputdate);
da.selectCommand.Parameters.Add(param);