Mysql 关于创建过程的数据库帮助
您好,我正在尝试使用Oracle My SQL Developer创建一个过程 这是我的桌子Mysql 关于创建过程的数据库帮助,mysql,database,Mysql,Database,您好,我正在尝试使用Oracle My SQL Developer创建一个过程 这是我的桌子 CREATE TABLE Product( ProductID int, ProductName varchar2(100), ProductFinish varchar2(100), ProductStandardPrice int, ProductLineID int, PRIMARY KEY (ProductID)); 正在插入的数据
CREATE TABLE Product(
ProductID int,
ProductName varchar2(100),
ProductFinish varchar2(100),
ProductStandardPrice int,
ProductLineID int,
PRIMARY KEY (ProductID));
正在插入的数据
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (1, 'End Table', 'Cherry', 175, 1);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (2, 'Coffee Table', 'Natural Ash', 200, 2);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (3, 'Computer Desk', 'Natural Ash', 375, 2);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (4, 'Entertainment Center', 'Natural Maple', 650, 3);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (5, 'Writers Desk', 'Cherry', 325, 1);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (6, '8-Drawer Desk', 'White Ash', 750, 2);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (7, 'Dining Table', 'Natural Ash', 800, 2);
INSERT INTO Product (ProductID, ProductName, ProductFinish, ProductStandardPrice, ProductLineID) VALUES (8, 'Computer Desk', 'Walnut', 250, 3);
我要创建的程序
CREATE PROCEDURE ProductLineSale
AS
SELECT *,
CASE WHEN ProductStandardPrice >= 400 THEN (ProductStandardPrice * 0.9)
ELSE (ProductStandardPrice * 0.85)
END AS SalePrice
FROM product
GO;
EXEC ProductLineSale;
选择*
我犯了那个错误。请你帮忙好吗。我还是个新手
编辑:提议的程序是可行的,但是,我仍然被卡住了。
该过程处于无效状态,因此我无法调用它并
我试图通过Netbeans从JSP访问数据库
请原谅我的许多错误,下面是我来自Netbeans的代码
<%@ page import = "java.sql.*"%>
<%@ page import = "java.io.*"%>
<% Class.forName("oracle.jdbc.driver.OracleDriver");%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page connected successfully!</h1>
<%
String url = "jdbc:oracle:thin:@129.7.240.3:1521:ORCL";
Connection basic = DriverManager.getConnection(url, "myname", "myname#");
Statement statement = basic.createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM myname.PRODUCT");
%>
<table width="95%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999">
<TR>
<TH bgcolor='#DAA520'> <font size='2'/>ProductID</TH>
<TH bgcolor='#DAA520'> <font size='2'/>ProductNAME</TH>
<TH bgcolor='#DAA520'> <font size='2'/>ProductFINISH</TH>
<TH bgcolor='#DAA520'> <font size='2'/>ProductSTANDARDPRICE</TH>
<TH bgcolor='#DAA520'> <font size='2'/>ProductLINEID</TH>
<TR>
<% while (result.next()) {%>
<TR>
<TD> <font size='2'/><center><%= result.getString(1)%></center<>/TD>
call ProductLineSale();
</TR>
<% }%>
</table>
<h1>Table supposed to be above this<h1>
</body>
</html>
JSP页面
JSP页面连接成功!
产品ID
产品名称
成品油
产品标准价格
ProductLINEID
调用ProductLineSale();
桌子应该在这上面
非常感谢对于MySQL,您创建过程的语法不正确。您需要指示参数(本例中没有),并将
作为
删除。因为您只有一条语句,所以不需要用BEGIN
和END
来包围它,但我已经包含了它们,以备将来扩展该过程时使用。请注意,根据您输入过程的环境,您可能需要或不需要分隔符
语句
DELIMITER //
CREATE PROCEDURE ProductLineSale ()
BEGIN
SELECT *,
CASE WHEN ProductStandardPrice >= 400 THEN (ProductStandardPrice * 0.9)
ELSE (ProductStandardPrice * 0.85)
END AS SalePrice
FROM Product;
END
//
DELIMITER ;
要运行该过程,请使用CALL
语句:
CALL ProductLineSale()
示例数据的输出:
ProductID ProductName ProductFinish ProductStandardPrice ProductLineId SalePrice
1 End Table Cherry 175 1 148.75
2 Coffee Table Natural Ash 200 2 170.00
3 Computer Desk Natural Ash 375 2 318.75
4 Entertainment Natural Maple 650 3 585.0
5 Writers Desk Cherry 325 1 276.25
6 8-Drawer Desk White Ash 750 2 675.0
7 Dining Table Natural Ash 800 2 720.0
8 Computer Desk Walnut 250 3 212.50
不,实际上,我正在为MySQL Developer中的一个表进行操作。我把它用于一项作业,在表格上运行一个程序来计算销售总额。然后,我将继续使用netbeans在JSP上显示该表。我被困在某个地方,但我还是挺过去了。再次感谢您的帮助。您使用的是ms sql server,但没有显示错误提示。所以请提供准确的错误信息,我在这里没有看到任何程序性的东西,那么你为什么想要一个程序呢?好的,那么你给出的程序工作得很好。然而,当我调用它时,它告诉我它处于无效状态。我正试图将其放入Oracle SQL developer中,并通过netbeans在web上运行它。到目前为止,我要编辑的代码就是我所在的地方。@JeremySNero这是一个与netbeans编程有关的完全不同的问题,而不是您需要帮助的MySQL过程。如果这解决了您原来的问题,您应该将其标记为已接受,并提出一个有关编程问题的新问题,必要时再参考此问题。