Share with together

独乐乐不如众乐乐

博客园 首页 新随笔 联系 订阅 管理
1.  You should know that log files must be stored in the Server Side. So you should intall the Oracle Server Version .After installation ,you should find the append program named "Oracle - OraDb10g_home1" while not "Oracle - OraClient10g_home1".
2. You should make sure that installation is OK, My Computer-> Right Clik "Manage"-> "Local users and groups" -> Click "Groups"  ,if you find the "ORA_DBA(Members can connect to the Oracle database as a DBA without a password)" showed in list, Congratulation! Now, you should add Administrator Account to the "ORA_DBA".


3. Now you should Create Directory to store the log file.
-- Create directory
create or replace directory PLSQL_OUTPUT
  as 'C:\';
4.After completed creating directory, you should grant privildge to the User.
e.g.  Oracle's Administror Account: OracleAdmin,User Account:User001
log as OracleAdmin ,then execute:

GRANT READ,WRITE ON DIRECTORY PLSQL_OUTPUT TO User001;

5.Create a Procedure to Test it.

--------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE P_WRITE_T_KOJO_HIMMOKU_JOKEN AS
 V_FILE UTL_FILE.FILE_TYPE;
 V_BUFFER VARCHAR2(32767);
BEGIN
  V_FILE:=UTL_FILE.FOPEN('PLSQL_OUTPUT','T_KOJO_HIMMOKU_JOKEN'||TO_CHAR(SYSDATE,'YYYY-MM-DD')||'.CSV','A',32767);
  V_BUFFER := 'DEL_FLG, KOJI_CD, HIMMOKU_CD, STD_HATCHUTEN, DFT_STD_ZAIKO';
  UTL_FILE.PUT_LINE(V_FILE,V_BUFFER);
  FOR I IN
  (
  SELECT
   '"'||DEL_FLG||'","'||KOJI_CD||'","'||HIMMOKU_CD||'","'||STD_HATCHUTEN||'","'||DFT_STD_ZAIKO||'"' RESULT
  FROM T_KOJO_HIMMOKU_JOKEN
  )
  LOOP
  UTL_FILE.PUT_LINE(V_FILE, I.RESULT);
  END LOOP;
  UTL_FILE.FCLOSE(V_FILE);
END;
--------------------------------------------------------------------

6.Now run the Procedure:

begin
  -- Call the procedure
  p_write_t_kojo_himmoku_joken;
end;

7.Result:

C:\T_KOJO_HIMMOKU_JOKEN2008-06-06.CSVT_KOJO_HIMMOKU_JOKEN2008-06-06.CSV

DEL_FLG, KOJI_CD, HIMMOKU_CD, STD_HATCHUTEN, DFT_STD_ZAIKO
"0","100","0803260010","40","50"
"0","100","3007070001","2999.99999","3999.99999"
"0","200","3007070001","99.99999","400"
"1","100","9999999999","0","0"
DEL_FLG, KOJI_CD, HIMMOKU_CD, STD_HATCHUTEN, DFT_STD_ZAIKO
"0","100","0803260010","40","50"
"0","100","3007070001","2999.99999","3999.99999"
"0","200","3007070001","99.99999","400"
"1","100","9999999999","0","0"


PS:Table Structure:

CREATE TABLE T_KOJO_HIMMOKU_JOKEN
(
    DEL_FLG                        VARCHAR2(1) NOT NULL,
    KOJI_CD                        VARCHAR2(3) NOT NULL,
    HIMMOKU_CD                     VARCHAR2(10) NOT NULL,
    STD_HATCHUTEN                  NUMBER(12,5) DEFAULT 0,
    DFT_STD_ZAIKO                  NUMBER(12,5) DEFAULT 0,
    KOBAI_LT                       NUMBER(3,0) DEFAULT 0,
    DFT_KOBAI_CD                   VARCHAR2(10) DEFAULT ' ',
    DFT_SOSHIKI_CD                 VARCHAR2(10) DEFAULT ' ',
    DFT_BASHO_CD                   VARCHAR2(6) DEFAULT ' ',
    DFT_SOKO_CD                    VARCHAR2(3) DEFAULT ' ',
    DFT_ZONE_CD                    VARCHAR2(2) DEFAULT ' ',
    INIT_LT                        NUMBER(3,0) DEFAULT 0,
    TANAOROSHI_TANKA               NUMBER(7,2) DEFAULT 0,
    HARAIDASHI_TANKA               NUMBER(7,2) DEFAULT 0,
    CRT_DATE                       NUMBER(8,0) DEFAULT 0,
    CRT_TIME                       NUMBER(6,0) DEFAULT 0,
    CRT_TANTO                      VARCHAR2(5) DEFAULT ' ',
    CRT_IPAD                       VARCHAR2(20) DEFAULT ' ',
    CRT_FUNC                       VARCHAR2(10) DEFAULT ' ',
    UPD_DATE                       NUMBER(8,0) DEFAULT 0,
    UPD_TIME                       NUMBER(6,0) DEFAULT 0,
    UPD_TANTO                      VARCHAR2(5) DEFAULT ' ',
    UPD_IPAD                       VARCHAR2(20) DEFAULT ' ',
    UPD_FUNC                       VARCHAR2(10) DEFAULT ' ',
    CONSTRAINT T_KOJO_HIMMOKU_JOKEN_PK PRIMARY KEY (KOJI_CD, HIMMOKU_CD) USING INDEX
        PCTFREE 10
        INITRANS 2
        MAXTRANS 255
        TABLESPACE USERS
        STORAGE(INITIAL 64K MINEXTENTS 1 MAXEXTENTS 2147483645 BUFFER_POOL DEFAULT)
        LOGGING
)
PCTFREE 10
MAXTRANS 255
TABLESPACE USERS
STORAGE(INITIAL 64K MINEXTENTS 1 MAXEXTENTS 2147483645 BUFFER_POOL DEFAULT)
NOCACHE
LOGGING
/
posted on 2008-06-06 16:14  寒枫  阅读(796)  评论(0编辑  收藏  举报