How to create a oracle sql script spool file(如何创建一个 oracle sql 脚本假脱机文件)
问题描述
我有一个关于假脱机程序结果的问题.我的示例 sql 脚本如下所示.
I have a question about spooling the the results of my program. My sample sql script looks like this.
  whenever sqlerror exit failure rollback
  set heading off
  set arraysize 1
  set newpage 0
  set pages 0
  set feedback off
  set echo off
  set verify off
 declare
 ab varchar2(10) := 'Raj';
 cd varchar2(10);
 a number := 10;
 c number;
 d number;
 begin
 c := a+10;
 select ab,c into cd,d from dual;
 end;
 SPOOL 
 select cd,d from dual;
 SPOOL OFF
 EXIT;
上面的脚本不起作用,但我想做这样的事情,在开始结束块中我们计算一些值,我想假脱机这些结果.
The above script does not work, but I want to do something like this where in the begin end block we compute some values and i want to spool those results.
谢谢.
推荐答案
这会将匿名块的输出假脱机到名为 output_<YYYYMMDD>.txt 的文件中,该文件位于本地的根目录中PC C:驱动器,其中 
This will spool the output from the anonymous block into a file called output_<YYYYMMDD>.txt located in the root of the local PC C: drive where <YYYYMMDD> is the current date:
SET SERVEROUTPUT ON FORMAT WRAPPED
SET VERIFY OFF
SET FEEDBACK OFF
SET TERMOUT OFF
column date_column new_value today_var
select to_char(sysdate, 'yyyymmdd') date_column
  from dual
/
DBMS_OUTPUT.ENABLE(1000000);
SPOOL C:output_&today_var..txt
DECLARE
   ab varchar2(10) := 'Raj';
   cd varchar2(10);
   a  number := 10;
   c  number;
   d  number; 
BEGIN
   c := a+10;
   --
   SELECT ab, c 
     INTO cd, d 
     FROM dual;
   --
   DBMS_OUTPUT.put_line('cd: '||cd);
   DBMS_OUTPUT.put_line('d: '||d);
END; 
SPOOL OFF
SET TERMOUT ON
SET FEEDBACK ON
SET VERIFY ON
PROMPT
PROMPT Done, please see file C:output_&today_var..txt
PROMPT
希望能帮到你...
在您评论后为游标的每次迭代输出一个值(我意识到在这个例子中每个值都相同,但您应该了解我正在做的事情的要点):
After your comment to output a value for every iteration of a cursor (I realise each value will be the same in this example but you should get the gist of what i'm doing):
BEGIN
   c := a+10;
   --
   FOR i IN 1 .. 10
   LOOP
      c := a+10;
      -- Output the value of C
      DBMS_OUTPUT.put_line('c: '||c);
   END LOOP;
   --
END; 
这篇关于如何创建一个 oracle sql 脚本假脱机文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何创建一个 oracle sql 脚本假脱机文件
 
				
         
 
            
        - 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
 
						 
						 
						 
						 
						 
				 
				 
				 
				