How to oracle stored procedures, why there are two similar pieces of code, instead of writing a paragraph?

BEGIN
   AN_O_RET_CODE := 0;
   AC_O_RET_MSG  := "";
   select COUNT (*) INTO COUNTALL from (
       select kf_id,o.name kf_name,sessionid,decode(score,"1","","2","","0","",score) as satis,to_char(create_time,"yyyy-mm-dd HH:MM:ss")
       from tb_zxkf_evaluate e
       left join tb_sso_oper o on e.kf_id = o.logincode
       where to_char(create_time,"yyyymmdd") between BEGINDATE and ENDDATE
   );
  limit2:=limit1;
  if limit1<0 then
    limit2:=COUNTALL;
  end if;
  --/*  */
  OPEN CUR_RET FOR
  SELECT * FROM (SELECT  ROWNUM AS ROW_NUM,WM.* FROM(
         select kf_id,o.name kf_name,sessionid,decode(score,"1","","2","","0","",score) as satis,to_char(create_time,"yyyy-mm-dd HH:MM:ss") as create_time
         from tb_zxkf_evaluate e
         left join tb_sso_oper o on e.kf_id = o.logincode
         where to_char(create_time,"yyyymmdd") between BEGINDATE and ENDDATE
  )WM order by create_time desc) WHERE ROW_NUM BETWEEN  start1  AND  limit2;
  EXCEPTION
    WHEN OTHERS THEN
        AN_O_RET_CODE := -1;
        AC_O_RET_MSG  := ":" || SQLCODE || CHR(13) || ":" || SQLERRM;
END ZXKF_SatisDet;
Apr.11,2021

although the two statements are similar, the two sql statements obviously do not come from the same content, one is to get the total amount of data, and the other is to query the data. As for why it is not written together, it is obvious that there is a logical treatment in front of it, and we need to proceed to the next step according to the specific situation. Although it can also be written as a sentence, it is obviously not as clear as this.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37c0a-2c0d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37c0a-2c0d6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?