我编写的程序将数据复制到txt文件程序中,如下所示
declare
empsfile utl_file.file_type;
cursor empscur is
select * from newemp;
begin
empsfile := utl_file.fopen('DIPRJDIR','EMPS.TXT','W');
for rec in empscur
loop
utl_file.put_line(empsfile,rec.EMPNO||rec.ENAME||rec.JOB||rec.MGR||rec.HIREDATE||rec.SAL||rec.COMM||rec.DEPTNO);
end loop;
UTL_FILE.FCLOSE(empsfile );
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( 'ERROR -->' || SQLERRM);
END;
/
上述progarm的输出是
7839KING PRESIDENT017-NOV-815000010
7698BLAKE MANAGER 783901-MAY-812850.5.530
7782CLARK MANAGER 783909-JUN-812450010
7566JONES MANAGER 783902-APR-812975020
7654MARTIN SALESMAN 769828-SEP-811250140030
7499ALLEN SALESMAN 769820-FEB-81160030030
7844TURNER SALESMAN 769808-SEP-811500030
7900JAMES CLERK 769803-DEC-81950030
7521WARD SALESMAN 769822-FEB-81125050030
7902FORD ANALYST 756603-DEC-813000020
7369SMITH CLERK 790217-DEC-80800020
7788SCOTT ANALYST 756609-DEC-823000020
7876ADAMS CLERK 778812-JAN-831100020
7934MILLER CLERK 778223-JAN-821300010
现在我的问题是我想根据上述字段的数据类型显示空间例如假设ENAME VARCHAR2(10)比数据中的名称是6字段而不是我必须显示4个空格请帮我。
答案 0 :(得分:1)
LPAD功能可以帮助你吗?
utl_file.put_line(empsfile,rec.EMPNO||LPAD(rec.ENAME,10,' ')||rec.JOB||rec.MGR||rec.HIREDATE||rec.SAL||rec.COMM||rec.DEPTNO);