sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.23k stars 392 forks source link

PL/SQL error parsing FOR x IN a..b LOOP #722

Open DuShuYuan opened 4 months ago

DuShuYuan commented 4 months ago

Input data

PLSQL v15.2.0

declare
  -- record 自定义所需的字段
  TYPE record_emp IS RECORD(
       v_empno STUDENT_INFO.sno%TYPE,   --引用emp中empno的类型
       v_ename STUDENT_INFO.sname%TYPE,
       v_sal STUDENT_INFO.bank%TYPE    
  );
BEGIN
  --构造方法,进行初始化一个空数组
  v_emp_array := emp_array();

  -- 遍历数组
  --first() 返回第一个元素下标,始终返回1
  --last() 返回最后一个元素下标,始终返回count()结果
  dbms_output.put_line('first()和last()遍历数组');
  FOR i IN v_emp_array.first() ..v_emp_array.last() LOOP
    dbms_output.put_line('员工号:'||v_emp_array(i).v_empno||' 员工名:'||v_emp_array(i).v_ename);
    END LOOP;

END;

error position

FOR i IN v_emp_array.first() ..v_emp_array.last() LOOP -- error token: ..
nene commented 4 months ago

Thanks for reporting, should be a simple thing to fix as similar syntax is supported for Transact-SQL.

Though the formatting of this kind of procedural SQL code is really very poorly supported by SQL Formatter.

fara-nak commented 1 week ago

@nene is there a workaround for this?

nene commented 1 week ago

None that I know of :(