Step through a view function

Hello all, I need to create a function that displays a view and that exports the data in a file with fixed field format. I think I need to step through the view and for each record, extract of each field, rpad at a given length and concatenate the new fields, together in a new record, perhaps dumping each new record in a temporary table and once that is done, export the table to a file. Please let me know if this reasoning seems logical, or is the best approach. Thank you.

If you want something a little more generic to any question (be it a regular table or view), something along these lines will do...

As user sys:

CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
/
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/

As myuser:

CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                     ,p_dir IN VARCHAR2
                                     ,p_header_file IN VARCHAR2
                                     ,p_data_file IN VARCHAR2 := NULL) IS
  v_finaltxt  VARCHAR2(4000);
  v_v_val     VARCHAR2(4000);
  v_n_val     NUMBER;
  v_d_val     DATE;
  v_ret       NUMBER;
  c           NUMBER;
  d           NUMBER;
  col_cnt     INTEGER;
  f           BOOLEAN;
  rec_tab     DBMS_SQL.DESC_TAB;
  col_num     NUMBER;
  v_fh        UTL_FILE.FILE_TYPE;
  v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
  c := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
  d := DBMS_SQL.EXECUTE(c);
  DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
  FOR j in 1..col_cnt
  LOOP
    CASE rec_tab(j).col_type
      WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
      WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
      WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
    ELSE
      DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
    END CASE;
  END LOOP;
  -- This part outputs the HEADER
  v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
  FOR j in 1..col_cnt
  LOOP
    v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
  END LOOP;
  --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
  UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
  IF NOT v_samefile THEN
    UTL_FILE.FCLOSE(v_fh);
  END IF;
  --
  -- This part outputs the DATA
  IF NOT v_samefile THEN
    v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
  END IF;
  LOOP
    v_ret := DBMS_SQL.FETCH_ROWS(c);
    EXIT WHEN v_ret = 0;
    v_finaltxt := NULL;
    FOR j in 1..col_cnt
    LOOP
      CASE rec_tab(j).col_type
        WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                    v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
        WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                    v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
        WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                    v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
      ELSE
        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
      END CASE;
    END LOOP;
  --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
    UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
  END LOOP;
  UTL_FILE.FCLOSE(v_fh);
  DBMS_SQL.CLOSE_CURSOR(c);
END;

This allows the header line and the data to write into files separate if necessary.

for example

SQL> exec run_query('select * from emp','TEST_DIR','output.txt');

PL/SQL procedure successfully completed.

Output.txt file contains:

empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10

The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

Adapt to the exit of styles and different types of data are needed.

Tags: Database

Similar Questions

  • I have published my muse built Business Catalyst site and all from the 'Site in the web browser view' function in the program of the Muse does not work. Screen comes up with a message that it cannot locate the page and suggests I check the ip address.

    I recently published my muse built the Business Catalyst site for preview and all from the 'Site in the web browser view' function in the program of the Muse does not work. Screen comes up with a message that it cannot locate the page and suggests I check the ip address.

    Hello Jimw93000314,

    Are you preview site in the edge browser? When you preview the page in the browser Muse create a local server to give you the preview in the browser. With the edge browser, there was a reported issue to access the local server.

    Please click the link below that shows the steps to enable the browser to edge.

    http://StackOverflow.com/questions/30334289/cant-open-localhost-in-Microsoft-edge-project-spartiate-dans-Windows-10-APER cu

    I'm sure this will help.

    Kind regards

    Vivek

  • My adobe will open and say "install updates" but it stops at 5% and told to try to connect to the server. It won't go past that. I tried to update through the view, but it still does the same thing.

    My adobe will open and say "install updates" but it stops at 5% and told to try to connect to the server. It won't go past that. I tried to update through the view, but it still does the same thing. I tried to reinstall, but it usually because of my other apps I have. How can I fix it?

    Hi crystal,

    Please see the following link for assistance on this issue;

    https://helpx.Adobe.com/creative-cloud/kb/download-update-errors.html

    Concerning

    Harsha

  • Step by step through a list of variables

    Hello

    How can step through a list of variables without a long list of "If"? Each var gets a string that consists of one or more paragraphs that are used to populate a text box. The var is selected in a hierarchical list box.

    Example:

    If (selectedValue == 1) {var TTHCov = dialogObject.TTHCov1;}

    } ElseIf (selectedValue == 2) {var TTHCov = dialogObject.TTHCov2;}

    } ElseIf (selectedValue == 3) {var TTHCov = dialogObject.TTHCov3;}

    } ElseIf (selectedValue == 4) {var TTHCov = dialogObject.TTHCov4;}

    } ElseIf (selectedValue == 5) {var TTHCov = dialogObject.TTHCov5;}

    } ElseIf (selectedValue == 6) {var TTHCov = dialogObject.TTHCov6;}

    } ElseIf (selectedValue == 7) {var TTHCov = dialogObject.TTHCov7;}

    } ElseIf (selectedValue == 8) {var TTHCov = dialogObject.TTHCov8;}

    } ElseIf (selectedValue == 9) {var TTHCov = dialogObject.TTHCov9;}

    } ElseIf (selectedValue == 10) {var TTHCov = dialogObject.TTHCov10;}

    } ElseIf (selectedValue == 11) {var TTHCov = dialogObject.TTHCov11;}

    } ElseIf (selectedValue == 12) {var TTHCov = dialogObject.TTHCov12;}

    } ElseIf (selectedValue == 13) {var TTHCov = dialogObject.TTHCov13;}

    } ElseIf (selectedValue == 14) {var TTHCov = dialogObject.TTHCov14;}

    } ElseIf (selectedValue == 15) {var TTHCov = dialogObject.TTHCov15;}

    } ElseIf (selectedValue == 16) {var TTHCov = dialogObject.TTHCov16;}

    } ElseIf (selectedValue == 17) {var TTHCov = dialogObject.TTHCov17;}

    } ElseIf (selectedValue == 18) {var TTHCov = dialogObject.TTHCov18;}

    } ElseIf (selectedValue == 19) {var TTHCov = dialogObject.TTHCov19;}

    } ElseIf (selectedValue == 20) {var TTHCov = dialogObject.TTHCov20;}

    } ElseIf (selectedValue == 21) {var TTHCov = dialogObject.TTHCov21;}

    } ElseIf (selectedValue == 22) {var TTHCov = dialogObject.TTHCov22;}

    } ElseIf (selectedValue == 23) {var TTHCov = dialogObject.TTHCov23;}

    } ElseIf (selectedValue == 24) {var TTHCov = dialogObject.TTHCov24;}

    } ElseIf (selectedValue == 25) {var TTHCov = dialogObject.TTHCov25;}

    } ElseIf (selectedValue == 26) {var TTHCov = dialogObject.TTHCov26;}

    } ElseIf (selectedValue == 27) {var TTHCov = dialogObject.TTHCov27;}

    } ElseIf (selectedValue == 28) {var TTHCov = dialogObject.TTHCov28;}

    } ElseIf (selectedValue == 29) {var TTHCov = dialogObject.TTHCov29;}

    } ElseIf (selectedValue == 30) {var TTHCov = dialogObject.TTHCov30;}

    } ElseIf (selectedValue == 31) {var TTHCov = dialogObject.TTHCov31;}

    } ElseIf (selectedValue == 32) {var TTHCov = dialogObject.TTHCov32;}

    } ElseIf (selectedValue == 33) {var TTHCov = dialogObject.TTHCov33;}

    } ElseIf (selectedValue == 34) {var TTHCov = dialogObject.TTHCov34;}

    } ElseIf (selectedValue == 35) {var TTHCov = dialogObject.TTHCov35;}

    } ElseIf (selectedValue == 36) {var TTHCov = dialogObject.TTHCov36;}

    } ElseIf (selectedValue == 37) {var TTHCov = dialogObject.TTHCov37;}

    } ElseIf (selectedValue == 38) {var TTHCov = dialogObject.TTHCov38;}

    } ElseIf (selectedValue == 39) {var TTHCov = dialogObject.TTHCov39;}

    } ElseIf (selectedValue == 40) {var TTHCov = dialogObject.TTHCov40;}

    }

    Hi there, your list values are stored in an object type, right?

    So, for example if you have your data listed as follows:

    var TTH = {"TTHCov1": "Value1"}

    "TTHCov2": "Value2",.

    ....}

    By using a loop with the declaration, you can browse the entire object

    for (var obj in TTH) {}

    If (selectedValue is {TTH [obj])}

    It's the value selected within the data object

    }

    }

    I hope this helps!

  • I'm unable to use the Live View function when working with JavaScript in Dreamweaver.

    I'm currently trying to set up my own Web site with dreamweaver and am very familiar with the languages Java and JavaScript. However, whenever I try to use the Live View function it never let me. In addition, I can't get a preview of my work in a browser, as to do so is greyed out.

    However, I noticed that when using html in a project, all these functions are available. Any ideas how I can be able to use these features?

    Or perhaps you mean a .jsp file that is a Java Server Page.

    Modern web pages are almost entirely HTML code with CSS for styles and JavaScript for functionality added as games & slideshows or interactive menus.  It does not seem possible for me that you have been creating web pages entirely with JavaScript.

    Nancy O.

  • Discoverer Viewer function

    Hello

    I added the discoverer Viewer function on my menu. It's just the seeded function, I want to return to the list of workbooks, and not a specific workbook.

    I get a problem when he clicked on the following error message is returned: search: OracleBI Discoverer Viewer was unable to find the data needed for the display of the results of this event. If please correct the errors and try again.
    When I click on go, all workbooks are returned and I can run reports as usual.

    My profile option: ICX: Discoverer Viewer Launcher is on: http://myserver.internal:7778/discoverer Viewer? Connect = [APPS_SECURE] which must be correct

    Anyone have any ideas on how to solve this problem?

    Thank you
    Dan

    Hello

    It's just the seeded function

    How it is defined. You should have the empty parameters property when the function is defined.

    Rod West

  • Step through the code line by line in Eclipse

    Hello.

    Simple question.

    How you make one through the code line by line using the Eclipse debugger? Is there a shortcut key for this?

    Thank you.

    I haven't opened it right in front of me, but I think that there

    F11-> start debugging

    F6-> step

    F7-> step into

    F8-> CV

  • Unable to connect to the outside through Horizon View Client

    http://www.VMware.com/files/PDF/view/VMware-view-evaluators-Guide.PDF

    I'm in the middle of evaluation of VMware Horizon View Suite. I set it up according to the information provided in the link above

    I am able to connect to my desktop PC internally through the Horizon View Client and HTML.

    I am also able to connect to the outside through HTML - BUT NOT - through the Horizon View Client from an external location.

    My first thought is that I have all the correct ports open on my firewall to network, that's what I opened, did I miss something?

    TCP / 80

    TCP / 443

    TCP / 4001

    TCP / 4172

    TCP / 8009

    TCP / 8443

    UDP / 4172

    Any help is appreciated with this!

    Exercise 3: connection to a Horizon of a customer of Mobile display view desktop

    "Launch the Horizon View Client you iOS mobile device...". "You will be asked to enter the host name or IP address of the view composer Server"

    See Server of composer? When I enter this IP address, it does not work immediately, it's a typo?

    Any help is greatly appreciated

    http://KB.VMware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalID=1036208

    My problem was solved by following the information provided in the above document (video), but the following two documents where it is also very useful

    http://KB.VMware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalID=1028332

    0 224598712 http://KB.VMware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1039021&sliceId=2&docTypeID=DT_KB_1_1&dialogID=224578928&StateID=0

  • Search through multiple sheets functionality

    Is it possible to create a search function that will work in any of several sheets in a custom shell app?

    Hi cedric,

    This type of research is a normal part of the Portico of MEI. Through the use of the portal, you can create search by keyword for folios and even create links to different articles or pages based on a search for the text in the page/post. This is in addition to another storefront/home page and direct payment capabilities that we allow through our integration with the Adobe business API.

    If you would like more information, feel free to contact me.

    Best,

    Brett

    [email protected]

  • Sharing a folio through a viewer brand

    Hello

    I understand how I can share via Ad - Hoc or In-House-Distribution with a spectator of brand and the appropriate licenses. If I have a business license or a business can I share a folio test through my brand spectator, in the same way that I share slips through the Adobe Content Viewer, brand with others who have connections Acrobat.com?

    Tony

    An app developer will expire after about 3 months.

    The only way to ensure an application brand without putting them on iTunes... As far as I KNOW... is a business account.

    Bob

  • Add limits to the parameters step through API TestStand of LabVIEW

    Dear LabVIEW and TestStand community!

    I am trying to add FileGlobal Variables that limits TestStand step NumericLimit programmatically, via LabVIEW via the TS API. I attach a screenshot of the code, which I use (part of it - the module that defines only values up to a limit high and low of the step), and also I agree, what I managed to get.

    In TS, when I open the file in sequence, after the execution of the code, I see in the description of the test line, he accepted limits, I put the LV - you can see on the screenshot, it is marked yellow. But in the "Limits" tab, there are even numeric values by default, not FileGlobal Variables.

    Could someone explain, what it means and how to configure correctly?

    Thank you very much in advance!

    I think that the search string to set the value Boolean true is inaccurate. Try to use "Limits.UseLowExpr" and "limits. UseHighExpr ".

    -Shashidhar

  • Print photos through photo viewer which lie in a Zip file

    Our users regularly receive ZIP files, email, containing several images they need to print. When they open the ZIP file, they can see the images listed; When they open a single image opens the photo viewer and displays the image, but the option is grayed out.

    If the user saves the content of the ZIP in their folder of photos (or other) and opens to them they can print them without any problem.

    Why Photo Viewer cannot print directly from ZIP files?

    I don't know if changing the following setting is
    the fix, but it may be worth trying: I think maybe
    It will allow the printer to access the zipped files.

    Reach... Folder options...
    Button start / Control Panel / appearance and
    Customization / Folder Options / Search tab

    See the next picture, the checkbox 'include '.
    Compressed files (ZIP. CAB...) "/ Apply / OK

    WIndows 7 - folders and Search Options
    http://content.screencast.com/users/Deadeye1864/folders/Jing/media/c05ff398-579d-4529-B2E5-f195c51a19cf/folder%20Options%20Search.PNG

    Let me know if it works for you.

  • step by step guide to disable function keys F1 etc Windows 7 ultimate so that I can work with the FTW Transcriber to transcribe software. Thank you

    I want to disable the function keys of windows 7 because I want to work with hotkeys TRANSCRIBER, FTW software. You can guide me please. Thank you very much for your quick response.

    Hi Kripananda,

    What is the brand and model of the computer?

    The function keys are controlled by the manufacturer of the system. The changes must be made in the BIOS (Basic Input Output System). I suggest you to contact the manufacturer of the system to better support.

    Note: changes to the BIOS/complementary metal oxide semiconductor (CMOS) settings can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the configuration of the BIOS/CMOS settings can be solved. Changes to settings are at your own risk.

  • How can I view a file of dps through the viewer of content on the iPhone?

    I have indesign CC 2015 and I want to get an overview of my work via the application viewer content on the iPhone.

    You use InDesign CC 2014. InDesign CC 2015 is supported only for the Solution of digital publishing, Digital Publishing Suite No.

    For more details, see DPS and InDesign CC 2015 .

    Neil

  • SEO step through Flex component Flex made in Flash

    Hello. I'm developing a component Flex in Flash CS4, called Navigator. The browser is just a slider (I'll use the slider to zoom in on something). It consists of a MovieClip with a child MovieClip named "magnifying glass" that is the cursor handle. Here's the class browser:


    package {
    import flash.display.MovieClip ;
    I have
    mport flash.events.Event
    import flash.events.MouseEvent
    import flash.geom.Rectangle
    Import mx.flash.
    UIMovieClip;

    public class Navigator extends {UIMovieClip}
    private var _dragging: Boolean ;
    private var _zoom: numberof;
    public var _bounds: Rectangle ;

    public void {Navigator()}
    _dragging = false;
    _bounds = new Rectangle(68,22.5,100,0);
    _zoom = 0;
    this.magnifier. buttonMode = true;
    this.magnifier. addEventListener (MouseEvent.MOUSE_DOWN, startDragging);
    stage. addEventListener (MouseEvent.MOUSE_UP, stopDragging);
    }

    private function startDragging (event: Event):void {}
    this.magnifier. startDrag (false, _bounds);
    _dragging = true;
    }

    private Function stopDragging (event: Event):void {}
    if (_dragging is true) {
    this.magnifier. stopDrag ();
    _dragging = false;
    _zoom = ((loupe. x-68) * 100) /(168-68);
    dispatchEvent (new event("zoomChanged"));
    }
    }

    public function get zoom(): {number }
    Return _zoom;
    }
    }
    }

    This code works on Flash, but in Flex I get this error "TypeError: Error #1009: cannot access a property or method of an object. null reference '-on the red line. Probably because it refers to the Flex and not Flash. It's my MXML Flex component:

    <? XML version = "1.0" encoding = "utf-8"? >
    < mx:Canvas "" xmlns:mx = "http://www.adobe.com/2006/mxml" width ="220" height = "64"creationComplete = "init ()" >
    < mx:Script >

    <! [CDATA]
    Import flash.display.MovieClip;
    Import mx.core.UIComponent;

    privé var UI:UIComponent = new UIComponent();
    privé var : browser = new Navigator();

    public f anointing init():void {}
    navigator.addEventListener ("zoomChanged", onZoom);
    ui.addChild (navigator);
    this.addChild (IU);
    }

    public function onZoom(event:Event):void {}
    trace (navigator.zoom);
    }
    []] >
    < / mx:Script >
    < / mx:Canvas >

    The purpose of the internship is the same for Flash and Flex.  It is not available in

    Flex after APPLICATION_COMPLETE or ADDED_TO_STAGE.  And in general, it

    better not to add listeners as MOUSE_UP until needed.

Maybe you are looking for

  • How to assign a macro key to type the email address?

    How can I assign a macro key to type my email address?A lot of sites that use under the user name email address required. 24 characters is a lot of typing.My OS is Windows 7 Home Premium.

  • Flash has disappeared on my iPad

    Tried to take a night photo with my iPad, but the flash has suddenly disappeared. My flashlight does not appear in the control center. I checked through all the settings and not found for light. Any suggestions on what could happen and how to solve t

  • Create a backup recovery

    Is this possible on a drive hard laptop usb or should it be a flash drive? I thought to partition my drive hard portable 1 TB and dedicate it to the backup recovery. Thank you

  • Venue Pro 8 Apps won't start not

    Whenever I try to start an application (such as email, IE, Sports, weather) on my site Pro 8, the tile to turn around and then return to the start page.  I tried to restart, but no luck.  I can go to the desktop and open IE from there, but I would us

  • BlackBerry Smartphones Appworld is not available in your country?

    Hi I'm new to the scene having just had my playbook yesterday. I downloaded a few free apps in appworld yesterday, but today I tried to download overdrive but after error (003-001) code a few times he says now appworld is not available in your countr