在Oracle中,如何将表中的Count(*)读入变量?

时间:2014-05-14 22:10:18

标签: sql oracle

在Oracle中,您如何从表中读取Count(*)变量?

在Microsoft SQL Server中,您可以这样做

select @variable = count(*) from Table where x=1;

我在Oracle中尝试过类似的尝试无效:

SELECT v_count_of_rows_bad := Count(*) FROM SCHEMANAME.TABLENAME WHERE ...;

2 个答案:

答案 0 :(得分:2)

您使用SELECT INTO

SELECT COUNT(*)
  INTO v_count_of_rows_bad
  FROM schemaname.tablename
 WHERE ...

答案 1 :(得分:1)

Easy Peasie:

DECLARE
  v_count_of_rows_bad NUMBER;
BEGIN
  SELECT COUNT(*) INTO v_count_of_rows_bad FROM SCHEMANAME.TABLENAME WHERE ...;
END