English 中文(简体)
我怎样才能将民族解放军的价值观列入Oracle/PLSQL?
原标题:How can I count only NULL values in Oracle/PLSQL?
  • 时间:2010-05-15 19:53:06
  •  标签:
  • oracle
  • plsql

我怎样才能将民族解放军的价值观列入Oracle/PLSQL?

我只想计算出无效价值。 是否有这样的职能?

最佳回答

我不知道Oracle specifally,但ANSI,COUNT(rowName),不计算NUL Value,而是COUNT(*)。 因此,你可以写

SELECT COUNT(*) FROM YourTable WHERE YourColumn IS NULL

你们的兄弟们把你们的兄弟们带到民族解放军。

问题回答

As an alternative to mdma s response. If you don t want to put a filter in the where you can

SELECT COUNT(case when xxx IS NULL THEN 1 end) cnt_xxx_null
FROM table

Oracle 指出:

All aggregate functions except COUNT(*) and GROUPING ignore nulls. You can use the NVL function in the argument to an aggregate function to substitute a value for a null.

举例来说,采用家庭结构:

SQL> select empno, sal, comm
  2  from emp;

     EMPNO        SAL       COMM
---------- ---------- ----------
      7369        800
      7499       1600        300
      7521       1250        500
      7566       2975
      7654       1250       1400
      7698       2850
      7782       2450
      7788       3000
      7839       5000
      7844       1500          0
      7876       1100
      7900        950
      7902       3000
      7934       1300

14 rows selected.

可以看出,商业一栏有4项已知的数值(即不作废)和10项不知名的数值(即Null)。

作为<编码>(your_column_name) 忽视你需要把不为人知的价值观替代你们可以提到的东西。 可通过NVL功能来实现。

SQL> select count(nvl(comm, -1)) "number of null values"
  2  from emp
  3  where nvl(comm, -1) = -1;

number of null values
---------------------
                   10

我将“-1”的价值作为“别名”用于我的无效价值,因为我知道,“-1”不是一栏中的现有价值。

http://www.un.org。

根据强有力的建议。 可从上述例子中删除该条款,并使用NVL2功能如下:

SQL> select count(nvl2(comm,null,-1)) "number of null values"
  2  from emp
  3  /

number of null values
---------------------
                   10

如果你想把其他价值计算到null。 然后使用COALESCE功能将改进执行时间。

北美荷兰语和哥莱斯语之间的甲骨质差异

SELECT COUNT(COALESCE( _COLUMN, 1)) AS CNT FROM _TABLE

我可能会试图推翻无效,见结果。

SELECT
 COUNT(DECODE(YourField, null, 1, null)) Nulls,
 count(*) Everything,
 COUNT(YourField) NotNulls
FROM YourTable

一切均应平等

select count(nvl(values, 0)) from emp where values is null;

职能:

create or replace function xxhrs_fb_count_null
return number
as
l_count_null number;
begin
  select count(*) into l_count_null from emp where comm is null;
  return l_count_null;
end;

使用:

select xxhrs_fb_count_null from dual

I believe your requirement is as below: Table emp has 100 rows. Against 20 employees, HIRE_DATE column is NULL. So basically, you want to get 20 as output. This is another method apart from the answers given by other contributors in this forum.

-- COUNT (1) would return 100
-- COUNT (hire_date) would return 80
-- 100 - 80 = 20
SELECT   COUNT (1) -
                 COUNT (hire_date)
                 AS null_count
FROM      emp;




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...