如何计算 pl/sql 中的值

How to count values in pl/sql

我是 pl/sql 的新手,我正在尝试计算所有具有首字母 'H' 的员工
我的代码目前看起来像这样,但我在第 24 行收到错误,COUNT(v_initials);

declare

    cursor cursor_employee
    is 
    select * from cmp_employer_employees
    where rownum < 25
    order by employer_employee_id asc
    ;
    
    v_initials varchar(100);
    v_count number := 0;
    
begin
    
    for r_employee in cursor_employee loop
    
        v_initials := r_employee.INITIALS;
    
        if v_initials like '%H' 
        then
        
            COUNT(v_initials);
        
        end if;
    
    end loop;

end;

那里不需要循环 - 您可以从 table 查询 count(*),条件为:

SELECT COUNT(*)
FROM   employees
WHERE  initials LIKE '%H'

编辑
要回答评论中的问题,您可以使用 insert-select 语句将这些员工收集到另一个 table:

INSERT INTO employees_with_h
SELECT * 
FROM   employees
WHERE  initials LIKE '%H'

或者,如果您只需要几个特定的​​列:

INSERT INTO employees_with_h (target_col1, target_col2, etc)
SELECT col1, col2, etc
FROM   employees
WHERE  initials LIKE '%H'