DBMS_OUTPUT.put_line  to file

Hi
I have a PL/SQL code wiht DBMS_OUTPUT , I must print result in file
  DECLARE
    myvar   integer;
  BEGIN
    bla
    bla
    etc
   DBMS_OUTPUT.PUT_LINE ('my data is ' : myvar);
END ;How can I do ?
tks

For 10gR2, per line limit is 32767. The total output now is (supposedly) unlimited
It used to be 1000000.
Rules and Limits
The maximum line size is 32767 bytes.
The default buffer size is 20000 bytes. The minimum size is 2000 bytes and the
maximum is unlimited.
Check this packages doc for more information.

Similar Messages

  • DBMS_OUTPUT.PUT_LINE Issue

    Hi All,
    I have created one simple package to create the log file. It's generating the log file but it's not writing anything in the log file. Please let me know what's wrong.
    I'm using Windows 2000 and Oracle 9i
    Here is the Code :
    CREATE OR REPLACE PACKAGE pkg_LoadData AS
    v_exists     BOOLEAN;
    v_error_buf VARCHAR2(100);
    n_retcode     NUMERIC;
    Procedure Sch_A;
    v_MessageLog UTL_FILE.FILE_TYPE;
    END pkg_LoadData;
    CREATE OR REPLACE PACKAGE BODY pkg_LoadData AS
    PROCEDURE Sch_A_Pos_R AS
    v_DBName           VARCHAR2(100);
    v_LogDir          VARCHAR2(100);
    v_LogFileName          VARCHAR2(100);
    v_StartTime     VARCHAR2(100);
    v_EndTime          VARCHAR2(100);
    v_ProcName      VARCHAR2(100) := 'pkgLoadData.Sch_A:';
    v_Space               VARCHAR2(1) := ' ';
    v_Record_Count NUMBER(10) := 0;
    v_FileOpenMode VARCHAR2(1) := 'W'; --Write
    BEGIN
    v_LogFileName := 'status.log';
    IF (UTL_FILE.IS_OPEN(v_MessageLog)) THEN
    DBMS_OUTPUT.PUT_LINE(v_LogFileName || ' file is already opened...');
    ELSE
    v_MessageLog := UTL_FILE.FOPEN('PKGDIR', v_LogFileName, v_FileOpenMode);
    -- PKDIR's value is C:\xxxxx
    DBMS_OUTPUT.PUT_LINE('Opening log file ' || v_LogFileName);
    END IF;
    v_StartTime := 'Procedure ' ||v_ProcName||' started at '|| TO_CHAR(SYSDATE, 'dd-Mon-yy hh:mi:ss');
    DBMS_OUTPUT.PUT_LINE(v_StartTime);     
    v_EndTime := 'Procedure ' || v_ProcName ||' completed at '|| TO_CHAR(SYSDATE, 'dd-Mon-yy hh:mi:ss');
    DBMS_OUTPUT.PUT_LINE(v_EndTime);
    UTL_FILE.FCLOSE(v_MessageLog);
    END Sch_A;
    END pkg_LoadData;
    /

    When I searched init.ora file. I found only one file
    with name init.ora.2102007193333
    in that I have added
    utl_file_dir = *
    Well that looks like a backup file so it'll have no effect.
    Which is probably a good thing, as adding "*" to your utl_file_dir setting opens your operating system up to being hacked!!!
    There is no need, any longer, to set the utl_file_dir parameter, and you should never set it to "*".
    All that is required is to create a directory object on the database and grant the relevant permissions to that object.

  • Printing messages in Log File and Output File using Dbms_output.put_line

    Hi,
    I have a requirement of printing messages in log file and output file using dbms_output.put_line instead of fnd_file.put_line API.
    Please let me know how can I achieve this.
    I tried using a function to print messages and calling that function in my main package where ever there is fnd_file.put_line. But this approach is not required by the business.
    So let me know how I can achieve this functionality.
    Regards
    Sandy

    What is the requirement that doesn't allow you using fnd_file.put_line?
    Please see the following links.
    https://forums.oracle.com/forums/search.jspa?threadID=&q=Dbms_output.put_line+AND+Log+AND+messages&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=%22dbms_output.put_line+%22+AND+concurrent&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Dbms_output.put_line not displaying anything

    I am running the below code (ssn_run.sql) using sqlplus 10.2.0.1.0 on my windows XP professional client PC.
    The database is a Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit running on Solaris
    I cracked my head for about one hour but couldn't figure out this :
    accept input_ssn prompt 'Enter SSN :'
    set feedback on
    set serveroutput on
    set echo on
    set term on
    set heading on
    set pagesize 0
    set linesize 10000
    set verify on
    undefne sdate input_ssn
    col sdate new_value sdate
    col input_ssn new_value input_ssn
    select to_char(sysdate,'YYYYMMDD') sdate from dual;
    spool C:\PERSON_DATA_&&sdate._&&input_ssn..TXT
    select 'REPORT GENERATED ON : '||SYSDATE FROM DUAL;
    begin
    select personid into v_personid from person where SIN = '&&input_ssn';
    INSERT INTO PERSON_OLD
    (PERSONID, TITLE, FNAME, MNAME, LNAME, ACFM, SIN, UNAME, AKANAME, DCFM,
    IROWID, SUFFIX, PTYPE, OLD_SSN)
    SELECT PERSONID, TITLE, FNAME, MNAME, LNAME, ACFM, SIN, UNAME,
    AKANAME, SIN FROM PERSON WHERE SIN = '&&input_ssn';
    INSERT INTO MEMBER_OLD
    (CLNT, MKEY, PERSONID, MEMNO, OLD_MEMNO)
    SELECT CLNT, MKEY, PERSONID, MEMNO,MEMNO
    FROM MEMBER WHERE PERSONID IN(SELECT PERSONID FROM PERSON WHERE SIN = '&&input_ssn');
    UPDATE PERSON SET FNAME = TRANSLATE(SIN,'0123456789','ACEGIKMOQS'),
    LNAME = TRANSLATE(SIN,'0123456789','SQOMKIGECA'),
    UNAME = TRANSLATE(SIN,'0123456789','ACEGIKMOQS')||' '||TRANSLATE(SIN,'0123456789','SQOMKIGECA'),
    AKANAME=NULL WHERE SIN = '&&input_ssn';
    UPDATE MEMBER SET MEMNO = MKEY WHERE PERSONID IN(SELECT PERSONID FROM PERSON WHERE SIN = '&&input_ssn');
    for i in(select personid person_other from person_relation where relpersonid in(select personid from
    person where PERSONID = v_personid))
    loop
    dbms_output.put_line('i.person_other is : '||i.person_other);
    UPDATE MEMBER SET MEMNO = MKEY WHERE PERSONID = i.person_other;
    end loop;
    EXCEPTION
    WHEN OTHERS THEN
         ecode := SQLCODE;
         emesg := SQLERRM;
         dbms_output.put_line('Error while data scrubbing: Error code is : ' || ' - ' || ecode);
         dbms_output.put_line('Error message is :' || ' - ' || emesg);
    end;
    spool off;
    set term on
    set feedback on
    set HEADING on
    set verify on
    --End of code
    The SELECT statement that comes in the for loop should return data as v_personid has a value. (I tested this by a select statement)
    However, I am just not able to display the line which comes in the inner loop :
    dbms_output.put_line('i.person_other is : '||i.person_other);
    The result of this dbms output put_line neither shows up on the screen, nor it gets written to the spool file...I am stumped with this...
    The other dbms_output put_lines that display error displays okay, but not the one in the inner loop.... Can someone help me out if you see any obvious issues here........
    Also my UPDATE MEMBER statement inside the for loop doesn't do anything whereas it was supposed to update a row !!
    Thanks

    You could display the number the query return by adding;
    v_count number;After you assign v_personid;
    dbms_output.put_line('v_personid  is : '||v_personid );
    (select count(*)
    into v_count
    from person_relation
    where relpersonid in(
       select personid
       from person
       where PERSONID = v_personid)).
    dbms_output.put_line('v_count  is : '||v_count );

  • Dbms_output.put_line not working

    Hi, i am trying to use dbms_output.put_line to execute a sql in a bat script on windows...i get no errors , but the "alter tablespace" just prints but does not execute.
    What exactly am i missing? Part of the script shown below..
    thanks
    set HFILE=%SCRIPT_HOME%\remove_bkupmode.sql
    echo connect sys/%INTPWD% as sysdba >>%HFILE%
    echo set termout off heading off feedback off >>%HFILE%
    echo set linesize 300 pagesize 0 >>%HFILE%
    echo set serveroutput on size 1000000 >>%HFILE%
    echo spool %SCRIPT_HOME%\cleanup.sql >>%HFILE%
    echo Declare >>%HFILE%
    echo cursor c1 is SELECT t.name FROM V$DATAFILE d, V$TABLESPACE t, V$BACKUP b WHERE d.TS#=t.TS# AND b.FILE#=d.FILE# AND b.STATUS='ACTIVE'; >>%HFILE%
    echo Begin >>%HFILE%
    echo for tbs in c1 loop >>%HFILE%
    echo   dbms_output.put_line(' alter tablespace '^|^|tbs.name ^|^|' end backup;');  >>%HFILE%
    echo end loop; >>%HFILE%
    echo dbms_output.put_line('exit;'); >>%HFILE%
    echo End; >>%HFILE%
    echo / >>%HFILE%
    echo spool off >>%HFILE%
    echo exit; >>%HFILE%
    START /wait SQLPLUS /NOLOG @%HFILE%

    thanks guys...did i bring back memories?
    yeah its an old script. part of an old hot backup script i inherited, for a 24/7 live 9.2.0.1 database that can't be upgraded due to customizations lol
    i setup rman, but since i'n still new to rman, i wanted to continue with the user- managed hot backups
    this script will run afer the backup, just in case, to ensure that no tablespaces are left in backup mode.
    J

  • Output from dbms_output.put_line splits and move to next line

    Hi All,
    I am printing out a list using dbms_output.put_line its like
    One or more of following Required Parameters are missing:
    1. Primary Field
    2. Structure Field
    3. Structure
    Table
    4. List File Name
    5. Query Directory
    6. Query String
    but I don't know why third option is splitting and moving to second line. any idea? its not that long even then.
    thanks

    set linesize 150
    or set it as per your requirement

  • Dbms_output.put_line  and sqlplus : output truncated to 100 Characters.

    HI all,
    please see the following script where the variable length is more than a 100 charecters...
    When i run this in sqlplus with SERVEROUTPUT ON, i see the ouput being truncated to 100 charecters.
    sql> ed
    Wrote file afiedt.buf
      1  declare
      2     l_var varchar2(400);
      3  begin
      4     l_var := 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh
      5     dbms_output.put_line(length(l_var));
      6     dbms_output.put_line(l_var);
      7* end;
      8  /
    130
    abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvI think I am looking for a sqlplus "SET XXXX..." command, but my search has been futile so far.
    Please advice.
    Thanks,
    John.

    Thanks for your reply .. Frank.
    Sorry... I Previewed the post but did not notice my code being truncated in my sqlplus sesssion.
    The actual script has the output to 130 charecters. but when i close the edit (afeidt.buf) and execute it, the display only shows 100 charecters...
    My SQLPLUS version is 9.2.0.1.
    I am using the "WE8ISO8859P1" charecter set.
    declare
        l_var varchar2(500) := 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz';
    begin
        dbms_output.put_line(length(l_var));
        dbms_output.put_line(l_var);
    end;
    130
    abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv
      1  declare
      2      l_var varchar2(500) ;
      3  begin
      4      for i in 1 .. 5 loop
      5          l_var := l_var || 'abcdefghijklmnopqrstuvwxyz';
      6      end loop;
      7      dbms_output.put_line(length(l_var));
      8      dbms_output.put_line(l_var);
      9* end;
    sql> /
    130
    abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv

  • Enhancement possiblity in dbms_output.put_line..!

    hey,
    I am having a strange client requirement.
    I am using dbms_output.put_line for output.But I was getting buffer flow error.
    Then i used utl_file to write log into a file but when due to some permission problem for FTP log file from unix directory to computer I can't use utl_file.
    Is there any possibility in dbms_output that if buffer flow error raise then
    2nd log file generate with new name and remaining log data written in new log file.
    My code in generally is below..
    SET BUFFER 1000000
    SET SERVEROUTPUT ON
    spool LMG_DBmigration_CP_DATA_Log.log
    Declare
    begin
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    end;
    spool off
    exit;
    any idea ...?
    rgds,
    pc

    hey Saubhik,thanks for your answer.
    In my code,SET BUFFER 1000000 in 1st line.
    Is there any impact of this line on log buffering error?
    I am running my code via batch file..
    SET BUFFER 1000000
    SET SERVEROUTPUT ON
    spool LMG_Log.log
    Declare
    begin
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    stmnts for DBMS_OUTPUT.PUT_LINE;
    end;
    spool off
    exit;

  • How to spool DBMS_OUTPUT.PUT_LINE from SqlPlus?

    Hi,
    i have a stored procedure test:
    procedure test is
    begin
    dbms_output.put_line('Test');
    dbms_output.put_line('Test2');
    dbms_output.put_line('Test3');
    dbms_output.put_line('Test4');
    dbms_output.put_line('Test5');
    end;
    I start the stored procedure out of sqlplus:
    spool C:\Temp\test.spl;
    exec test;
    commit;
    spool off;
    exit;
    My problem is no Test or Test2 appeared in the spool file.
    What should i do?
    thanks a lot

    create or replace procedure hmm as
    begin
    dbms_output.put_line('Test1');
    dbms_output.put_line('Test2');
    dbms_output.put_line('Test3');
    dbms_output.put_line('Test4');
    dbms_output.put_line('Test5');
    end;
    spool C:\Temp\test.spl;
    exec hmm;
    spool off;File content is:
    Test1
    Test2
    Test3
    Test4
    Test5
    PL/SQL procedure successfully completed.

  • DBMS_OUTPUT.put_line  buffer overflow

    Hi all
    I am taking some values into a cursor and updating a table with those values, and catching the exception in the exception block
    EXCEPTION
    WHEN OTHERS
    THEN
    sqlm := SUBSTR (SQLERRM, 1, 100);
    sqlc := SQLCODE;
    DBMS_OUTPUT.put_line ( 'Error Code : '
    || sqlc
    || ' Error Message : '
    || sqlm
    || ' : aaa:: '
    || aaa_rec.recid
    Here the problem is the data which i am updating its huge(5 million records), i am getting the error for the exception block as Buffer overflow( After I set it to the buffer value to maximum i.e 1000000), how can i avoid this problem, i am not supposed to use utl file package, Can u be a little brief in ur answers
    Thnks in advance

    1000000 is not the maximum size:
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_output.htm#CIHEGBBF
    There used to be a maximum setting of 1000000 (in practice nearer 600K) in earlier versions of Oracle. Perhaps you are using one of those and forgot to mention it?
    In any case, why are you using a debugging tool for error handling?

  • Using DBMS_OUTPUT.PUT_LINE() to create a white space

    I had a script that I run on SQL*Plus to create a spool file output. How do I create a white space or skip a new line using the DBMS_OUTPUT.PUT_LINE()?
    e.g.
    DBMS_OUTPUT.PUT_LINE('+--------------------+');
    DBMS_OUTPUT.PUT_LINE('First Line..........');
    DMBS_OUTPUT.PUT_LINE('Second Line......');
    DBMS_OUTPUT.PUT_LINE(' ');
    DBMS_OUTPUT.PUT_LINE('Fourth Line........');
    DBMS_OUTPUT.PUT_LINE('+--------------------+');
    output on spool file should be like this:
    First Line..........
    Second Line......
    Fourth Line........
    but the output on spool file when run the script
    First Line..........
    Second Line......
    Fourth Line........
    --------------------

    hi
    it get a blank line u can simply use CHR function with argument 10
    like this
    declare
    begin
    dbms_output.put_line('ashish');
    dbms_output.put_line('+--------------------+');
    dbms_output.put_line('First Line..........');
    dbms_output.put_line('Second Line......');
    dbms_output.new_line();
    dbms_output.put_line('Fourth Line........');
    dbms_output.put_line(chr(10));
    dbms_output.put_line('ashish');
    end;
    regds

  • Spooling via DBMS_OUTPUT.PUT_LINE without new lines

    Is there a way to spool output to a file using DBMS_OUTPUT.PUT_LINE so that each line is placed on a same line? ie spool all output to one line?
    I guess this probably goes against design of PUT_LINE as it is mean to put a line.
    What I am trying to do is build a DOS command via a SQL script that spools to a file all on one line. this is so that when the spool file is run (either as a .bat or .sh file) the command can execute correctly since it is all on one line.
    Any ideas?
    Leigh.

    You can try below code.
    create or replace procedure p1(P_AMU varchar2) as
    cursor cu_get_workbooks is
    select '/workbook "'||doc_created_by||'.'||doc_name||'"' workbook
    from (
    SELECT EUL4_DOCUMENTS.DOC_NAME,
    DOC_CREATED_BY
    FROM EUL4_DOCUMENTS EUL4_DOCUMENTS
    WHERE DOC_CREATED_BY=P_AMU;
    str varchar2(4000);
    begin
    for cu_rec in cu_get_workbooks loop
    str := cu_rec.workbook;
    end loop;
    insert into temp values (str);
    end;
    And then you can write a sql script:
    exec p1(&&AMU);
    select * from temp;
    Regards,
    Vidyadhar Singh.

  • DBMS_OUTPUT.PUT_LINE multi records from PL/SQL procedure to Java web page.

    Hello
    I will explain the scenario:
    In our java web page, we are using three text boxes to enter "Part number,Description and Aircraft type". Every time the user no need to enter all these data. The person can enter any combination of data or only one text box. Actually the output data corresponding to this input entries is from five Oracle table. If we are using a single query to take data from all the five tables, the database will hang. So I written a procedure "SEARCH1",this will accept any combination of values (for empty values we need to pass NULL to this procedure) and output data from all the five tables. When I executing this procedure in SQL editor, the execution is very fast and giving exact result. I used "dbms_output.put_line" clause for outputing multiple records in my procedure. The output variables are "Serial No, part Number, Description, Aircraft type,Part No1,Part No2,Part No3,Part No4". I want to use the same procedure "SEARCH1" for outputing data in java web page.The passing argument I can take from the text box provided in java web page. I am using jdbc thin driver to connect our java web page to Oracle 9i database.
    Note1 : If any combination of search item not available, in procedure itself I am outputing a message like "Part Number not found". Here I am using four words ("Part" is the first word,"Number" is the second,"Not" s the third, and "found" is the fourth) for outputing this message.Is it necessary to equalise number of words I am using here to the record outputing eight variable?
    Our current development work is stopped because of this issue. So any one familier in this field,plese help me to solve our issue by giving the sample code for the same scenario.
    My Email-id is : [email protected]
    I will expect yor early mail.
    With thanks
    Pramod kumar.

    Hello Avi,
    I am trying to solve this issue by using objects. But the following part of code also throwing some warning like "PLS-00302: component must be declared". Plese cross check my code and help me to solve this issue.
    drop type rectab;
    create or replace type rectype as object(PartNo varchar2(30),Description varchar2(150),AIrcraft_type varchar2(15),status_IPC varchar2(30),status_ELOG varchar2(30),status_SUPCAT varchar2(30),status_AIRODWH varchar2(30));
    create or replace type rectab as table of rectype;
    create or replace package ioStructArray as
    procedure testsch2(pno in varchar2,pdes in varchar2,air in varchar2,orec in out rectab);
    end ioStructArray;
    create or replace package body ioStructArray as
    procedure testsch2(pno in varchar2,pdes in varchar2,air in varchar2,orec in out rectab) is
    mdescription varchar2(150);
    mpartnum varchar2(30);
    mpno varchar2(30);
    mdes varchar2(150);
    mair varchar2(15);
    mstat varchar2(1);
    cursor c1 is select partnum,description,aircraft_type from master_catalog where partnum=mpno and aircraft_type=mair and description like ltrim(rtrim(mdes))||'%';
    cursor c2 is select partnum from ipc_master where partnum=mpartnum;
    cursor c3 is select partnum from fedlog_data where partnum=mpartnum;
    cursor c4 is select partnum from superparts where partnum=mpartnum;
    cursor c5 is select part_no from supplier_catalog where part_no=mpartnum;
    mpno1 varchar2(30);
    mpno2 varchar2(30);
    mpno3 varchar2(30);
    mpno4 varchar2(30);
    mpno5 varchar2(30);
    maircraft_type varchar2(15);
    mstat1 varchar2(30);
    mstat2 varchar2(30);
    mstat3 varchar2(30);
    mstat4 varchar2(30);
    begin
    mstat:='N';
    mpno:=pno;
    mdes:=pdes;
    mair:=air;
    if mpno is not null and mdes is not null and mair is not null then
    begin
    mstat:='N';
    mpno:=pno;
    mdes:=pdes;
    mair:=air;
    for i in c1 loop
    mstat:='N';
    mstat1:='N';
    mstat2:='N';
    mstat3:='N';
    mstat4:='N';
    mpno1:=i.partnum;
    mpartnum:=i.partnum;
    mdescription:=i.description;
    maircraft_type:=i.aircraft_type;
    for j in c2 loop
    mpno2:=j.partnum;
    end loop;
    for k in c3 loop
    mpno3:=k.partnum;
    end loop;
    for l in c4 loop
    mpno4:=l.partnum;
    end loop;
    for m in c5 loop
    mpno5:=m.part_no;
    end loop;
    if mpno2=mpartnum then
    mstat1:=mpno2;
    end if;
    if mpno3=mpartnum then
    mstat2:=mpno3;
    end if;
    if mpno4=mpartnum then
    mstat3:=mpno4;
    end if;
    if mpno5=mpartnum then
    mstat4:=mpno5;
    end if;
    if mpno1=mpartnum then
    mstat:='Y';
    orec.PartNo:=mpno1;
    orec.Description:=mdescription;
    orec.AIrcraft_type:=maircraft_type;
    orec.status_IPC:=mstat1;
    orec.status_ELOG:=mstat2;
    orec.status_SUPCAT:=mstat3;
    orec.STATUS_AIRODWH:=status_AIRODWH;
    end if;
    end loop;
    end;
    end if;
    end testsch2;
    end ioStructArray;
    Expecting your early reply.
    With thanks
    Pramod kumar.

  • Dbms_output.put_line not printing in inner for loop using a parameter

    I cannot get the inner loop to print output. I can run both loops independent (hardcoding a value for the inner loop) Any help is apprecicated... Listed is the code
    set serveroutput on
    DECLARE
    cursor ACCNO_CUR is
    select accession_number from didb_studies where insert_time > to_date('02-JUN-12');
    cursor PATH_CUR (p1_accno VARCHAR2) is
    select distinct l.FILE_SYSTEM || '/' ||
    substr(LPAD(s.PATIENT_DB_UID, 12, '0'),1,3) || '/' ||
    substr(LPAD(s.PATIENT_DB_UID, 12, '0'),4,3) || '/' ||
    substr(LPAD(s.PATIENT_DB_UID, 12, '0'),7,3) || '/' ||
    substr(LPAD(s.PATIENT_DB_UID, 12, '0'),10,3) || '/' ||
    s.STUDY_DB_UID || '/' || i.SERIES_DB_UID || '/'||
    i.RAW_IMAGE_DB_UID || '.img' as FULLY_QUALIFIED_IMAGE_NAME
    , l.image_size
    , i.image_need_backup
    , i.sop_class_uid
    from medistore.didb_studies s
    , medistore.didb_raw_images_table i
    , medistore.didb_image_locations l
    where s.accession_number = 'p1_accno'
    and s.study_db_uid = i.study_db_uid
    and i.raw_image_db_uid = l.raw_image_db_uid
    and l.file_system is not null and INSTR(l.file_system, '.img') = 0
    UNION
    select distinct(l.FILE_SYSTEM) as FULLY_QUALIFIED_IMAGE_NAME
    , l.image_size
    , i.image_need_backup
    , i.sop_class_uid
    from medistore.didb_studies s, medistore.didb_raw_images_table i,
    medistore.didb_image_locations l
    where s.accession_number = 'p1_accno'
    and s.study_db_uid = i.study_db_uid
    and i.raw_image_db_uid = l.raw_image_db_uid
    and l.file_system is not null and INSTR(l.file_system, '.img') > 0
    order by 1;
    BEGIN
    FOR accno_rec in accno_cur LOOP
    DBMS_OUTPUT.put_line('ACCESSION_NUMBER is: '|| accno_rec.accession_number);
    FOR path_rec in path_cur(accno_rec.accession_number) LOOP
    DBMS_OUTPUT.put_line('Inner loop accession_number is :'||accno_rec.accession_number);
    DBMS_OUTPUT.put_line('Full path is : ' || path_rec.FULLY_QUALIFIED_IMAGE_NAME);
    END LOOP;
    END LOOP;
    END;

    Maybe
    DECLARE
      cursor ACCNO_CUR is
        select accession_number
          from didb_studies
         where insert_time > to_date('02-JUN-12');
      cursor PATH_CUR (p1_accno VARCHAR2) is
        select distinct
               l.FILE_SYSTEM || '/' ||
               substr(LPAD(s.PATIENT_DB_UID, 12, '0'),1,3) || '/' ||
               substr(LPAD(s.PATIENT_DB_UID, 12, '0'),4,3) || '/' ||
               substr(LPAD(s.PATIENT_DB_UID, 12, '0'),7,3) || '/' ||
               substr(LPAD(s.PATIENT_DB_UID, 12, '0'),10,3) || '/' ||
               s.STUDY_DB_UID || '/' || i.SERIES_DB_UID || '/'||
               i.RAW_IMAGE_DB_UID || '.img' as FULLY_QUALIFIED_IMAGE_NAME,
               l.image_size,
               i.image_need_backup,
               i.sop_class_uid
          from medistore.didb_studies s,
               medistore.didb_raw_images_table i,
               medistore.didb_image_locations l
         where s.accession_number = to_number(p1_accno) /* to_char(s.accession_number) = p1_accno */
           and s.study_db_uid = i.study_db_uid
           and i.raw_image_db_uid = l.raw_image_db_uid
           and l.file_system is not null
           and INSTR(l.file_system, '.img') = 0
        UNION
        select distinct
               l.FILE_SYSTEM as FULLY_QUALIFIED_IMAGE_NAME,
               l.image_size,
               i.image_need_backup,
               i.sop_class_uid
          from medistore.didb_studies s,
               medistore.didb_raw_images_table i,
               medistore.didb_image_locations l
         where s.accession_number = to_number(p1_accno) /* to_char(s.accession_number) = p1_accno */
           and s.study_db_uid = i.study_db_uid
           and i.raw_image_db_uid = l.raw_image_db_uid
           and l.file_system is not null and INSTR(l.file_system, '.img') > 0
         order by 1;
    BEGIN
      FOR accno_rec in accno_cur
      LOOP
        DBMS_OUTPUT.put_line('ACCESSION_NUMBER is: '|| accno_rec.accession_number);
        FOR path_rec in path_cur(accno_rec.accession_number)
        LOOP
          DBMS_OUTPUT.put_line('Inner loop accession_number is :'||accno_rec.accession_number);
          DBMS_OUTPUT.put_line('Full path is : ' || path_rec.FULLY_QUALIFIED_IMAGE_NAME);
        END LOOP;
      END LOOP;
    END;Regards
    Etbin

  • How to Populate a table with DBMS_OUTPUT.put_line

    Hey Guys, it's Xev.
    Please only pleasant people reply to this.
    I have a PL/SQL Program that searches for strings and then at the end of it it prints out to DBMS_OUTPUT.put_line.
    I have the owner, the table_name, the column name and the count, then it goes to DBMS_OUTPUT.put_line
    What i want to do, is take the results of DBMS_OUTPUT.put_line and insert it into a table.
    Here is the script I am talking about, as you can see it's simple, yet for me it works.  I want to take the results of this and insert it into a table. How can i do  that??
    set serveroutput on size unlimited
    execute DBMS_OUTPUT.ENABLE (buffer_size => NULL);
    DECLARE
       FND_GOVIDS       INTEGER;
       BEGIN
    FOR t  IN (SELECT owner, table_name, column_name
                FROM all_tab_columns
                WHERE owner = upper('&SCHEMA_NAME'))
    LOOP
      BEGIN
        EXECUTE IMMEDIATE 'with a as ( select  case when REGEXP_LIKE(' || t.column_name ||
    --This searches for 8 Alpha Digits
    ',''^([[:alpha:]]{2}|[[:alpha:]]{4})?[ ]?[0-9]{8}[ ]?([[:alpha:]]{2}|[[:alpha:]]{4})?$'')
    then ''Match Found''
    else ''No Match Found'' end as output from ' || t.owner || '.' || t.table_name || ')
    select count(*) from a where a.output=''Match Found'' '
          INTO FND_GOVIDS ;
    IF FND_GOVIDS > 0         THEN
    DBMS_OUTPUT.put_line (
    t.owner
    || '.'
    || t.table_name
    || ' '
    || t.column_name
    || ' '
    || FND_GOVIDS);
      END IF;
      EXCEPTION
        WHEN OTHERS
          THEN
          DBMS_OUTPUT.put_line (
          'Generic Error '
          || t.column_name
          || ' from '
          || t.owner
          || '.'
          || t.table_name);      
          END;
       END LOOP;
    END;

    Nope, the table is empty....
    But it ran without error??!?! Wait a minute, I think i have to commit right? Since it's not straight sql, ok, that's what I am going to try..
    set serveroutput on size unlimited
    execute DBMS_OUTPUT.ENABLE (buffer_size => NULL);
    DECLARE
       FND_GOVIDS       INTEGER;
       BEGIN
    FOR t  IN (SELECT owner, table_name, column_name
                FROM all_tab_columns
                WHERE owner = upper('&SCHEMA_NAME'))
    LOOP
      BEGIN
        EXECUTE IMMEDIATE 'with a as ( select  case when REGEXP_LIKE(' || t.column_name ||
    --This searches for 6 Alpha Digits
    ',''^([[:alpha:]]|[[:alpha:]]{3})[0-9]{6}$'')
    then ''Match Found''
    else ''No Match Found'' end as output from ' || t.owner || '.' || t.table_name || ')
    select count(*) from a where a.output=''Match Found'' '
          INTO FND_GOVIDS ;
    /*Table insert for resulting */
    IF FND_GOVIDS > 0 THEN
    INSERT INTO "SMEG"."DYNAMIC_COUNTS" (T_OWNER, T_TABLE_NAME, T_COLUMN_NAME, FND_GOVIDS) VALUES
    ('t.owner','t.table_name','t.column_name','FND_GOVIDS');
      END IF;
    /* dbms_output */
    IF FND_GOVIDS > 0 THEN
    DBMS_OUTPUT.put_line (t.owner || '.' || t.table_name || ' ' || t.column_name || ' ' || FND_GOVIDS);
      END IF;
    /* Exception Handeling */
      EXCEPTION
        WHEN OTHERS
          THEN
          DBMS_OUTPUT.put_line (
          'Generic Error '
          || t.column_name
          || ' from '
          || t.owner
          || '.'
          || t.table_name);     
          END;
       END LOOP;
    END;

Maybe you are looking for