昨天我发的帖子~~
昨天大概扫了下存储过程的写法,有很多地方不会写!!!
自己写了一下,但感觉不对,请教一下应该怎么写??
create or replace Procedure "GetInvoiceStat"(buyerID in nvarchar2(50),buyerID out nvarchar2(50),GiveInputMoney out NUMBER(10,2),GiveOutputMoney out NUMBER(10,2),GiveMoneyNow out NUMBER(10,2),MoneyNow out NUMBER(10,2),AllInvoiceMoney out NUMBER(10,2),...省略)
is
begin
select buyerID into buyerID,MoneyNow into MoneyNow from buyerinfo a where a.buyerID=buyerID;
select sum(price) into AllInvoiceMoney from invoicelog b where b.buyerID=BuyerID;
select sum(price) into GiveInputMoney from payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID;
select sum(price) into GiveOutMoney from payhistory c2 where c2.buyerid=buyerID and c2.category='2' and c2.flag3 in('8','9') group by buyerID;
...省略
return;
end;这只是我要统计的一部分,其中要输出的字段buyerID ,GiveInputMoney ,GiveOutputMoney ,GiveMoneyNow ,MoneyNow ,AllInvoiceMoney ...省略
感觉这么写不对
要想得出结果上面的应该怎样改?????
而里面GiveMoneyNow =GiveInputMoney -GiveOutputMoney ,这在存储过程中怎么写???
昨天大概扫了下存储过程的写法,有很多地方不会写!!!
自己写了一下,但感觉不对,请教一下应该怎么写??
create or replace Procedure "GetInvoiceStat"(buyerID in nvarchar2(50),buyerID out nvarchar2(50),GiveInputMoney out NUMBER(10,2),GiveOutputMoney out NUMBER(10,2),GiveMoneyNow out NUMBER(10,2),MoneyNow out NUMBER(10,2),AllInvoiceMoney out NUMBER(10,2),...省略)
is
begin
select buyerID into buyerID,MoneyNow into MoneyNow from buyerinfo a where a.buyerID=buyerID;
select sum(price) into AllInvoiceMoney from invoicelog b where b.buyerID=BuyerID;
select sum(price) into GiveInputMoney from payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID;
select sum(price) into GiveOutMoney from payhistory c2 where c2.buyerid=buyerID and c2.category='2' and c2.flag3 in('8','9') group by buyerID;
...省略
return;
end;这只是我要统计的一部分,其中要输出的字段buyerID ,GiveInputMoney ,GiveOutputMoney ,GiveMoneyNow ,MoneyNow ,AllInvoiceMoney ...省略
感觉这么写不对
要想得出结果上面的应该怎样改?????
而里面GiveMoneyNow =GiveInputMoney -GiveOutputMoney ,这在存储过程中怎么写???
解决方案 »
- c# 接口 JOSN
- 求救 帮我看看怎么改 急急急!!接口怎么不能声明啊
- 基于ASP.NET+Csharp+SQL开发网站后,写毕业论文选题的问题!急~~!
- 请教各位高手如何在c#中显示多页的tif 格式的文件呀,用picturebox 只能显示第一页, 使用printdocument 打印时也只能打印一页
- 求《c#与水晶报表实例》一书--100分相送
- web上怎么让owc能够载入一个.xls文档
- 未将对象的引用设置到对象的实例,怎么解决啊
- 求教| 符号的问题
- 怎样将textbox中第N个字符值变成另一个值??
- 以前没有用过asp现在在看asp+,我用下面的代码把一些中文字段插入数据库得到的都是?,请问我如和进行字符集转换
- 怎么样更改多行文本框某一行的文本
- [WinFrom]
表内示例数据及想要的结果帖一下
最好发到SQL版块去
很快就应该可以得到参考答案
返回多个值 需要
@res int output
http://blog.163.com/ysx_email/blog/static/1694213620106186514287/
GiveMoneyNow(输出字段) =GiveInputMoney (输出字段)-GiveOutputMoney(输出字段) ,这在存储过程中怎么写???
如果传入值buyerID改为'id1','id2'...这种形式应该怎么改??
{
conn.Open();
SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
MyCommand.Parameters["@a"].Value = 20;
MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
MyCommand.Parameters["@b"].Direction = ParameterDirection.Output;
MyCommand.ExecuteNonQuery();
Response.Write(MyCommand.Parameters["@b"].Value.ToString());
} http://topic.csdn.net/u/20091204/21/722689e1-7824-497c-b709-4b1118264633.html
set GiveMoneyNow(输出字段) =GiveInputMoney (输出字段)-GiveOutputMoney(输出字段)
(
@GiveInputMoney int output
略.....
)
as
select @GiveInputMoney=sum(price) into GiveInputMoney from payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID;
略...
go类似这样的吧...
set GiveMoneyNow into GiveMoneyNow =GiveInputMoney (这是存储过程中得到的数据,后面是否应该加点什么??)-GiveOutputMoney(同GiveInputMoney )
当buyerID='id1','id2',...时
可以使用select @GiveInputMoney=sum(price) into GiveInputMoney from payhistory c1 where c1.buyerID in (buyerID )...这样的写法吗??数据能对的上吗??
如果不行应该怎么改呢?
create or replace Procedure GetInvoiceStat(buyerID in nvarchar2(,buyerID out nvarchar2,GiveInputMoney out NUMBER,GiveOutputMoney out NUMBER,GiveMoneyNow out NUMBER,MoneyNow out NUMBER,AllInvoiceMoney out NUMBER,...省略)
as
begin
select buyerID,buyerID into buyerID,MoneyNow from buyerinfo a where a.buyerID=buyerID;
select sum(price) into AllInvoiceMoney from invoicelog b where b.buyerID=BuyerID;
select sum(price) into GiveInputMoney from payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID;
select sum(price) into GiveOutMoney from payhistory c2 where c2.buyerid=buyerID and c2.category='2' and c2.flag3 in('8','9') group by buyerID;
...省略
return;
end;
给你提几点
一存储过程名字不要双引号
二参数没必要给它设个范围,自己找麻烦
三is不是这里用的,应该为as
四怎么会有两个into,如果需要,可以把字段查两遍
五第三、四行sql语句你使用聚合函数了还用啥group by 可能还有其它问题没解决
更正:
select @GiveInputMoney=sum(price) from payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID;//应该是没有 into GiveInputMoney 的..
二参数没必要给它设个范围,自己找麻烦
三is不是这里用的,应该为as
四怎么会有两个into,如果需要,可以把字段查两遍
五第三、四行sql语句你使用聚合函数了还用啥group by
不太明白,我昨晚看了几个orcl的事例
1:存储过程名字都加双引号
2:参数没必要给它设个范围什么意思呢???
3:orcl里貌似是用is的
4:需要输出多个参数,最后很有可能是输出List<参数,参数...>这种样子的
5:因为考虑到可能要改成buyerid in ('','',''....)的样子
oracle 中的变量赋值 是 :=eg:DECLARE Variable VARCHAR2(4000); Variable:='Sandy';
GiveMoneyNow:=GiveInputMoney-GiveOutMoney//后面这俩值是求出来的,怎么搞???
还有我现在是传入一个buyerID,如果传入的是List<string>lstBuyerID这个怎么弄??
还有我这现在是返回多个参数,而我希望是返回这多个参数的集合List<参数1,参数2...>怎么搞???
快疯了
...
我理解力不强
难道是这样??
GiveMoneyNow:=(select sum(price) into GiveInputMoney from py_payhistory c1 where c1.buyerID=buyerID and c1.category='1' and c1.flag2='PayRecordFlag2_10' group by buyerID)-(select sum(price) into GiveOutMoney from py_payhistory c2 where c2.buyerid=buyerID and c2.category='2' and c2.flag3 in('8','9') group by buyerID);
....我后边还有一个公式是:x=a-b-c-d的那我不累死了还有
oracle 存储过程 可以返回数组的退一步, 不使用数组 你还可以使用 字符串拼接的方式 eg: 'buyerID1,buyerID2,buyerID3'什么意思?不大明白....
buyerID='buyerID1,buyerID2,buyerID3'??这样
那我有多个(大概会有20条左右)统计查询
select 输出字段 from biao where buyerID in (buyerID) group by buyerID
我怎样把得出的这些字段按ID连接成完整的数据呢???
select sum(price) into GiveOutMoney from py_payhistory c2 where c2.buyerid=buyerID and c2.category='2' and c2.flag3 in('8','9') group by buyerID;然后 GiveMoneyNow:=GiveInputMoney-GiveOutMoney就可以了.多条的时候 ,你需要先学习一下 如何在存储过程中使用循环了解了之后,很容易的