Я не уверен, какую версию вы ищете - это та, которая перебирает все PLT_NO в таблице, или та, которая должна принимать PLT_NO в качестве параметра. Вот оба варианта, посмотрите, поможет ли какой-либо из них.
Первый использует курсор курсора FOR; это легче поддерживать, поскольку Oracle выполняет большую часть грязной работы за вас (открытие курсора, выборка, выход из цикла, закрытие курсора).
create or replace procedure update_qty
is
begin
for cur_r in (select plt_no, count(slab_no) v_qty
from prod_result
group by plt_no
)
loop
if cur_r.v_qty > 0 then
update plt_result r set
r.qty = cur_r.v_qty
where r.plt_no = cur_r.plt_no;
end if;
end loop;
end;
Второй принимает PLT_NO в качестве параметра:
create or replace procedure update_qty
(par_plt_no in prod_result.plt_no%type)
is
v_qty number;
begin
select count(p.slab_no)
into v_qty
from prod_result p
where p.plt_no = par_plt_no;
if v_qty > 0 then
update plt_result r set
r.qty = v_qty
where r.plt_no = par_plt_no;
end if;
end;
Просто выполните (int) myLongValue
. Он будет делать именно то, что вы хотите (отбрасывая MSB и принимая LSB) в unchecked
контексте (который является компилятором по умолчанию). Он вызовет OverflowException
в проверенном
контексте, если значение не помещается в int
:
int myIntValue = unchecked((int)myLongValue);
Это может быть преобразование с
, Преобразовывают. Метод ToInt32
, Но это бросит OverflowException, если это значение будет внешний диапазон Типа Int32. Базовый тест покажет нам, как он работает:
long[] numbers = { Int64.MinValue, -1, 0, 121, 340, Int64.MaxValue };
int result;
foreach (long number in numbers)
{
try {
result = Convert.ToInt32(number);
Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
number.GetType().Name, number,
result.GetType().Name, result);
}
catch (OverflowException) {
Console.WriteLine("The {0} value {1} is outside the range of the Int32 type.",
number.GetType().Name, number);
}
}
// The example displays the following output:
// The Int64 value -9223372036854775808 is outside the range of the Int32 type.
// Converted the Int64 value -1 to the Int32 value -1.
// Converted the Int64 value 0 to the Int32 value 0.
// Converted the Int64 value 121 to the Int32 value 121.
// Converted the Int64 value 340 to the Int32 value 340.
// The Int64 value 9223372036854775807 is outside the range of the Int32 type.
Здесь существует более длительное объяснение.
Следующее решение усечет к интервалу. MinValue/int. MaxValue, если значение вне Целочисленных границ.
myLong < int.MinValue ? int.MinValue : (myLong > int.MaxValue ? int.MaxValue : (int)myLong)
Convert.ToInt32(myValue);
Хотя я не знаю, что он будет делать, когда '