我想将选择中的数字值分配给变量以用于进一步的计算 [英] I want to assign the number value from a select to a variable to be used for further calculation

查看:60
本文介绍了我想将选择中的数字值分配给变量以用于进一步的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将变量定义为整数,然后在select语句中将计算所得的值分配给该变量,以便可以在select语句中进一步使用该变量值.

Is there a way to define a variable as an integer and then within a select statement assign the calculated value to the variable, so that the variable value can then be used further in the select statement .

declare avg integer;
select
  Round(V_COMB_PROD_CRW1.PROD_HRS * 3600 / Decode(V_COMB_PROD_CRW1.TOTAL_CYCLES,
  0, 1, V_COMB_PROD_CRW1.TOTAL_CYCLES, 20, -3))  

我想将选择中的值移动到avg中,然后在选择中进一步使用avg.

I want to move the value from the select into avg and then use avg further on in the select.

推荐答案

每个人都应该使用SELECT...INTO,但不要忘记将其放在BEGIN...END部分中,不能放在声明部分中(每个人都忽略它)

As everyone say, you should use SELECT...INTO, but don't forget to put it in BEGIN...END section, it can't be in declaration section (everyone omit it)

declare avg integer;
BEGIN
select Round(V_COMB_PROD_CRW1.PROD_HRS * 3600 / Decode(V_COMB_PROD_CRW1.TOTAL_CYCLES, 0, 1, V_COMB_PROD_CRW1.TOTAL_CYCLES, 20, -3))  
INTO avg
From DUAL;
END;

这篇关于我想将选择中的数字值分配给变量以用于进一步的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆