【发布时间】:2016-07-22 09:45:23
【问题描述】:
【问题讨论】:
-
这适用于哪个 RDBMS?请添加标签以指定您使用的是
mysql、postgresql、sql-server、oracle还是db2- 或其他完全不同的东西。 -
@osimerpothe 我已经发布了 sql-server 的答案...检查它是否正确..
标签: sql
【问题讨论】:
mysql、postgresql、sql-server、oracle 还是db2 - 或其他完全不同的东西。
标签: sql
CREATE DEFINER=`root`@`localhost` PROCEDURE `myproc`(IN `id` INT)
NO SQL
SELECT student.Student_Name, account.Balance
FROM student INNER JOIN account
ON student.Student_ID = account.Student_ID
WHERE student.Student_ID = id
您可以从 phpmyadmin 创建程序: How to write a stored procedure in phpMyAdmin?
【讨论】:
函数可以创建为:
CREATE FUNCTION function_name(@Student_ID int)
RETURNS @name_and_balanceTable TABLE
(
-- Columns returned by the function_name
Name nvarchar(50),
Balance int
)
AS
-- Returns the Name and Balance for particular Student_ID
BEGIN
-- Selecting the name and balance
SELECT
@Name = st.Student_Name,
@Balance = ac.Balance
FROM Student st JOIN Account ac ON st.Student_ID = ac.Student_ID
WHERE st.Student_ID = @Student_ID;
-- Insert these value into table
BEGIN
INSERT @name_and_balanceTable
SELECT @Name, @Balance;
END;
RETURN;
END;
这是用于 sql-server 的。 欲了解更多信息,请使用this link...
【讨论】: