Automating repetitive queries

Hi,
I'm quite new to Oracle PL/SQL and I'm using Oracle SQL Developer to write some queries. I am often asked to run a query for a list of values and output each set of results individually. For example:
Select Count(*) from ORDERS where ZIPCODE='XXXXXX';
Where XXXXXX might be a list of 100 postal codes in a text file. Obviously, running this individually for each postal code is very tedious and I'm sure there is an easy way to do it. I think the best way would be to use an associative array and a for loop, but I'm not sure how to get it to output the results of each iteration in the loop to a new row in a csv file. Can SPOOL be used to do this?
If anyone has done similar tasks before and has an easy way of doing it, please let me know.
Many Thanks.
Craig.

Hi,
First off, you are in the wrong forum, this one is about sqldeveloper the tool you need the SQL and PL/SQL forum.
Anyway as to your problem, there are many ways to tackle this.
depending on the amount of zipcodes the simpelest would probably be
using some search and replace magic on your text file to get the zipcodes in a comma seperated list enclosed in quotes and then issue
select zipcode,count(*) from orders where zipcode in ( <PASTE YOUR ZIPCODES HERE>) group by zipcode;
For large amounts of zipcodes you would first need to get those into Oracle, for this you could look into external tables.
hope this helps.
Neil
Edited by: barsema on Dec 8, 2009 4:20 AM

Similar Messages

  • Any Ideas for Automating Repetitive Tasks in AA3?

    I could really use some help if anyone has an idea.
    Many of the jobs I do monthly involve slicing up one or more audio files and saving the slices to their own folder with unique file names. There are SSOOOO many little things that have to be done to EVERY file (hundreds sometimes). Here's an example:
    I have a 20-minute audio file of a voice-over actor saying certain words or phrases. The finished product will consist of, say, 15 separate small files, each with a different file name. The VO actor provides multiple "takes" for each word/phrase. I pick the best versions of each take and create a file for it.
    *Current Process*:
    1. Listen to the original file, marking "keeper" regions as I go.
    2. Open the Marker List window
    3. Label each of the 15 phrase regions with their appropriate file names.
    4. Select all the markers and batch-save them, using the label as the file name.
    I have shortened the process a little by Auto-Marking the entire file first, then auditioning each marker, deleting those not needed as I go. But the process of clicking on each marker region and typing a name in the label box takes forever...especially when I'm dealing with hundreds of finished files.
    On the jobs where the "output" files are the same for every project, is there not some way to automate, macro, or otherwise reduce the total amount of busy (non-value-added) work involved in something like this?
    Any ideas would help.
    Thanks!
    Happy New Year!!
    Ken

    John,
    Thank you, thank you, thank you! In learning how to use the REN and batch processes in XP, I also discovered some more stuff I could do in AA's Marker window and the batch process button at the bottom of it. I feel kinda dumb that I didn't know about it all along. Oh well. Since I was going to need the final sound clips to be in a certain sequence, I just unchecked the "use label as filename" box, and all the marker phrases were saved in the order they appeared in the file. Nice! Now my 116 final marked phrases appeared as: "001.wav, 002.wav-->116.wav." Then all I had to do was make a batch script to create the list of file names, and paste those into a column in Excel. Then in the next column over I entered the name of all the final file names. Those will always be the same. Then with a 3rd column of "REN" next to the other 2, I just copy, paste into Notepad, save as ".bat," and double-click the file! All that saved about 4 hours off of about a 6-hour job!
    Runaway, to answer your question...I never see a "Save As" dialog box! Once I Auto-Mark the big file, I don't really spend much time even looking at the Edit window. I just go down the list in the Marker window, audition each marked phrase, delete until I'm left with the 116 I want, then use the "batch process" button at the bottom to do what I mentioned above.
    Wicked!
    Thanks a lot guys. This has been an amazing help.
    Now if I could just figure out why AA makes it so hard to sequentially listen to phrases one-by-one. You have to double-click each one before you can hear it. Then if you delete one, inexplicably the cursor jumps way up the list so you have to scroll back down to where you were. Once I had all the files saved into a folder, I QC'd them in Reaper and MAN what a difference! All I had to do was use the "down" arrow to advance to the next file AND have it play. I literally took me 5 minutes to check all 116 files that way. If AA could add that kind of functionality I would REALLY be happy.
    Oh well. ONe thing at a time, I guess. I may post about that last thing on its own.
    Thanks again! Hapy New Year!
    Ken

  • Automating tasks in Flash CS4

    I have a question regarding the possibility of automating repetitive tasks in Adoble Flash CS4.
    My wife is pregnant and we are taking a picture of her every day so that at the end, we will have a flash movie of her belly growing throughout her pregnany. This is basically what I am doing:
    1) Take the picture
    2) The picture's native resolution is too big for flash CS4, so i resize the image in Photoshop (I can automate this and do these in large batches)
    3) I import the resized photos into flash
    4) I create the keyframes etc (3 frames per photo)
    5) The canvas is the exact size of the photo, so the photo fits perfectly (drag and drop)
    6) Save the file once im done with the batch
    Basically, I was wondering if i can do in flash what i am doing in photoshop. Automate the app to select a folder, have Flash import the photo, create the keyframes and place each photo in the frame...repeat until all photos are done.
    Is this possible?
    Thanks in advance,
    Don

    if you name your photos suggestively (whatever1.jpg, whatever2.jpg etc) and if you import one, flash will detect that you might want to load the entire sequence and distribute one per keyframe and give you that option.
    while flash can resize for you, if this is going to be a web-based app, you would still benefit from resizing before importing.

  • TimesTen and Memcached

    Hi,
    Memcached (http://www.danga.com/memcached/) is a product being used by highly transactional websites to cache data structures in memory.
    I beleive it is similar to what TimesTen does. I was trying to find comparison between TimesTen and Memcached at OTN, but no luck.
    Appreciate if someone can provide the comparison for these alongwith pros and cons of both technologies.
    Regards.

    memcached is a distributed memory object cache, it is commonly used to cache SQL resultsets, targeted at repetitive queries found in read intensive database web applications. The user application is responsible for managing and populating the cache, memcached does not provide data synchronization with the Oracle database.
    For example this is the logic the application developer needs to implement:
    * Wherever you go to do a database query, first check the memcache. If the memcache returns an undefined object, then go to the database, get what you're looking for, and put it in the memcache
    * To ensure the application does not see stale data, the application must update both the memcache and the database at the same time
    memcached does not understand SQL. If a memcached node dies, all data are lost and it is up to the application to reload the data from the source.
    TimesTen is a memory optimized SQL relational database, that can run standalone or as a cache in front of an Oracle database. Developers use standard JDBC, ODBC or SQL to access TimesTen. TimesTen provides real-time, updatable caching for Oracle database, the data synchronization between Oracle and TimesTen is automatically handled.
    The TimesTen database is persistent and supports full ACID transactions with recovery. TimesTen also offers real-time transactional replication between TimesTen databases for high availability and load sharing.
    Simon

  • Why can't I use AS to change Keyboard prefpane settings?

    Hey y'all, I got a question for you.
    I have a windows keyboard that I plug into my iBook at home. A very common arrangement, I'm sure.
    When I plug the keyboard in, I go into the Keyboard prefpane and use the controls there to swap the <COMMAND> and <OPTION> Keys, so the keys are more mac-like.
    What I want to do is pretty simple: Create an applescript to do that for me, so I don't have to, everytime, go Apple -> System Preference -> Keyboard & Mouse -> Keyboard -> Modifier Keys etc.
    As a total AS newbie, here are my questions:
    1. Can AS do this?
    2. If not, why not? This is a serious question: What good is AppleScript if it won't actually do the things -- especially an extremely simple thing like change a system preference -- that I want it to?
    3. Is there a better way to do this?
    Thanks for whatever guidance you can offer!
    Alaska Jack
    iBook G4   Mac OS X (10.4.6)  

    Hi Jack and welcome to Apple Discussions!
    To answer your questions:
    1) Apparently so. See this thread in the Automator forum.
    2) AppleScript is very good at automating repetitive tasks and inter-application communication - provided developers incorporate scriptability into their applications. In the case of System Preferences, Apple themselves haven't put in the "hooks" that allow preferences to be changed without resorting to UI scripting, as in the solution linked above.
    3) It might be possible to parse the preference files themselves.
    Hope this helps,
    H

  • EEM CLI Script with parameters

    Hi all,
    I have a requirement to write an eem cli script that can be triggered using a pattern match and take parameters.
    Basically the user has to do many repetitive tasks reconfiguring interfaces regularly. So instead of having to go into each interface individually and run the config that they can write a one word command and give it params which would be for example a comma separated list of interface names and then within my script i could parse the interface names and iterate over them performing the config operation on them.
    so i'm just playing around with the cli policy.
    ::cisco::eem::event_register_cli occurs 1 pattern "nacdrop*" sync yes enter
    # Import Namespaces
    namespace import ::cisco::eem::*
    namespace import ::cisco::lib::*
    array set arr_einfo [event_reqinfo]
    set full_command $arr_einfo(msg)
    puts $full_command
    You can see here i want the command nacdrop to trigger this policy but when i try and run the command with arguments i get an error on the command line as its not a valid command and the policy doesnt trigger.
    Ideal scenario run command
    Router#nacdrop fastEthernet0/0,fastEthernet0/1,fastEthernet0/2
    the script would then perform a set of config tasks on each of the 3 interfaces.
    I thought the "enter" parameter to event_register_cli would do it as that is supposed to trigger the policy before the command is executed therefore before it determines it to be an invalid command. I do not have the latest version of eem however and suspect that the "enter" argument isn't being used as it isn't showing up as an option when i type ? to see what options are available although i don't get an error when registering the policy.
    So my question is what version off eem was this "enter" argument introduced and will it allow me to run the policy and get around the invalid command problem.
    Once i can run this policy and access the parameters to the cli command it opens up a lot for me in terms of automating repetitive tasks.
    Hope someone can help.
    Cheers,
    Joe.

    Cheer Joe. That's great. I've attached the first draft of a script i've written, maybe someone else can find it useful too.
    Basically it's for if you would like to perform the same operation on many interfaces you can use an alias and give it parameters
    E.G
    Router#vlanmove FastEthernet0/1-8,10,13-16
    Notice the params use '-' and ',' When you use dash it will perform the operation on all the interfaces in a range and then comma is just for an individual interface and as you can see above you can mix ranges with individual ones.
    The above example will give the output:
    Configuring Interface: FastEthernet0/1
    Configuring Interface: FastEthernet0/2
    Configuring Interface: FastEthernet0/3
    Configuring Interface: FastEthernet0/4
    Configuring Interface: FastEthernet0/5
    Configuring Interface: FastEthernet0/6
    Configuring Interface: FastEthernet0/7
    Configuring Interface: FastEthernet0/8
    Configuring Interface: FastEthernet0/10
    Configuring Interface: FastEthernet0/13
    Configuring Interface: FastEthernet0/14
    Configuring Interface: FastEthernet0/15
    Configuring Interface: FastEthernet0/16
    in the attached script just replace "puts "Configuring Interface: $interfaceName"
    with your configuration
    e.g.
    conf t
    interface $interfaceName
    switchport access vlan 2
    and it will perform that operation on all intefaces in a range. I might update the script later to take config commands as env variables too. That would make the script more generic. But at the moment this script is useful for us as we have to regularly reconfigure interfaces.
    Cheers,
    Joe.

  • Running a single action, separately, over multiple folders

    Hello all,
    First time for me using this forum, therefore i apologise if this is listed incorrectly. I am trying to speed up my work flow by automating repetitive tasks. Now that I am getting more work to do, I’m trying to tie up some loose ends in my actions that I haven’t previously been able to figure out.
    I shoot a lot of school photography and i use Photoshop to automate the process of adding each student’s image to a proof card which is printed and dispatched to the school. Now this process is really easy when it’s just a single shot per proof card. But for nurseries there are four different images per proof card. The action i currently use (proof card template would be open in Photoshop) asks me to open the four images, which then copies each of the images and pastes them into the designated area of the proof card, then asks me to save it, then removes the four images so that the proof card template is ready to accept another four images when the action is run again.
    The issue i have is that I have to manually select the four images every time i run the action. It’s become a tedious, time consuming process as some of these schools have up to 200 proof cards to be made.
    I’m looking for tips as to someway i can create an action that selects the first four images in a designated folder automatically, plays the action above, saves it automatically as basic file name (even "Proof1" would do!) Then automatically selects the next four images in the folder, runs the action, and automatically saves as 'proof2' and carries on going until its completed every image in the folder.
    I’m not sure if this would be possible to divide each student’s four images into subfolders and use the batch tool run the action?
    Any help would be appreciated.

    I have a similar problem. Wish I had an answer but am struggling with a similar problem. My situation is this: I have a Imac and a Macbook Pro. I have the same 4 accounts on both and I sync them through '.mac'. It works fairly well. My goal is to get one Itunes library accessible from the 2 computers and the 4 accounts per computer. I am also using Time Capsule/Machine as well. I currently keep the Itunes library on an external drive (not TCapsule). So, my problem is this:
    1. How to update from multiple accounts accross the two machines?
    2. How to access Itunes store from all of the accounts on machine 2?
    I am now trying to set up individual Itunes libraries for each account on machine 1 and share to machine 2.
    In any case, this is not pretty and needs to be reachitected to support a multiple user environmet.

  • [SOLVED] building mysql-workbench with lib32-libpng12

    i installed the mysql-workbench package because i want a gui interface for making query tables (from large database and non-repetitive queries):
    $ pacman -Ss mysql-workbench
    community/mysql-workbench 5.1.18-1
    MySQL Workbench is a cross-platform, visual database design tool developed
    by MySQL.
    however, running the app gives the following error:
    $ mysql-workbench
    /usr/bin/mysql-workbench-bin: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory
    looking for a solution gives:
    $ pacman -Ss libpng
    extra/libpng 1.4.0-2
    A collection of routines used to create PNG format graphics files
    community/lib32-libpng 1.4.0-2 (lib32)
    A collection of routines used to create PNG format graphics files
    i cant use libpng12 because i am running x86_64.  as far as i can tell lib32-libpng12 should satisfy the dependency.  however i still run into the error after installing this package and re-installing mysql-workbench.  is there a configuration file somewhere that i can edit to tell the app that it needs lib32-libpng12 not libpng12?  also, what is the reason that libpng (already installed) cannot be used instead of libpng12?  is it possible that libpng12 is inaccessible due to the presence of libpng?
    Last edited by poopship21 (2010-02-08 01:14:27)

    you don't need any libpn12 or lib32-libpng12.
    mysql-workbench doesn't even link it to libpng and other dependency is linking to it.
    mysql-workbench is linking to /usr/lib/libgtk-x11-2.0.so.0 (gtk2) who link to cairo, who needs libpng.
    you have other cairo package installed? pacman -Qs cairo. if so, is your job to rebuild any unsupported packages
    Last edited by wonder (2010-02-07 22:59:45)

  • How do I publish twelve movies at once?

    I am using iMovie to create 12 projects, one for each member of my extended family. So far the results are great. The problem is when I make changes to these files I want to publish them all at once, but iMovie makes me sit here and click on Share/MediaBrowser/Publish for each project, and I have to sit and wait 3-5 minutes for each project. So basically I have to sit and babysit this program for 30 minutes while it does its work of publishing. I can't find a way for iMovie to do its work autonomously (without me clicking 36 times over 30 minutes). Is this just something that Apple forgot, or am I doing something wrong? Oh, the same problem exists for the phase when I send the movies to MobileMe. That adds another 30 minutes to my life, wasted. Computers are supposed to excel at automating repetitive tasks.

    Same as everywhere in the OS.
    Click to select.
    Hold the command key and click (command-click) to add items to a seletion.
    To select a series of contiguous items: click on the first, then hold the shift key and click on the last. All the items in between will be selected.

  • Google Problem "computer or network may be sending automated queries", what to do?

    Hi,
    yesterday google told me this message "...computer or network may be sending automated queries...." now I Installed OSX Lion, deleted Firefox, reinstalled it, but now I get this message again. By now Google's Chrome and Safari work fine and no message appears in google. What can I do? I'd like to use Firefox...
    Thanks for your help
    Max

    I had never heard of such a message before, but a search turns up:
    http://support.google.com/websearch/bin/answer.py?hl=en&answer=86640
    It's unlikely that your Mac has malware that is causing this.  It's possible that a Windows computer on your local network is infected with something.  It's also possible that, if you're using a wireless network with no password that you have a "squatter" (a nearby neighbor) using your network, whose computer is infected.  Lock down the network with WPA2 encryption using a good, strong password.  If that's not it, note that the IP addresses used by most home networks are allocated from a pool of addresses, and may change at any time.  So it's possible that someone who was infected with malware drew the attention of Google's algorithms, and then the IP addresses were reallocated and now you're using that IP address.  You can try rebooting your cable or DSL modem, as that can give you a new IP address, if it's given a different one from the pool.

  • Automating some repetitive tasks

    Hello, I'm looking for an Acrobat plug-in or script that will allow me automate _some_ of the repetitive tasks that I do.
    For multi-sheet document, I need to:
    1) extract each page as separate file with each open in its own window
    2) crop image
    3) close window
    4) dialog will prompt me to enter filename for it (Note: default filename will usually start with the text "Pages from ... ")
    5) repeat until end.
    I'd like to automate step 1, 3 (maybe?), and 5, while I manually specify the crop boundary (2) and type in its filename (4).
    Thanks,
    Devin

    Yep, I'll be testing this thoroughly!
    But if it passes all my rigorous tests :D then that's one big issue taken care of and I believe a good enhancement to anyone's Apex skills.
    I'll report back with my findings!
    Edit: the export looks fine to my untrained eye, so maybe I'll try it out with my application (so far I only tested on my laptop test Apex installation)
    Haven't tested the text messages script yet, just the application items, but I figure it should be no different.
    Edited by: Baguette on 11-Aug-2009 23:41

  • Queries about automation

    hi all
    i am trying to automate an application using windows services
    i have written a small code in .net which compares
    the max timestamp with the source and brings the data from the remote switch
    in short appending the data
    now the application works fine
    but as it is a critical application
    and i new to the programming world i don want to take any risk
    can any one just point out some points of failure
    now the possible problem according to me might be
    the link going down at the time of transfer
    for that i used the timestamp so that at the next execution records are fetched after the last timestamp and no records are missed
    also i have some doubts over cursor if i am using cursors
    and records are getting inserted into the database from the records selected by the cursors does the records get inserted sequentially ie as per the timestamp
    or i have to use order by

    hey
    thanks for the reply even i felt so
    i don have much idea about how to do the automation
    using oracle
    can you just guide me with some links or material
    so that i can understand how it can be done
    or even the topics name would be fine because i have no clue where to start from
    also one more logical question i might sound silly but need to ask
    suppose i have billions of record with timestamp as one field
    now the records that i select for processing are selected by comparing the timestamp so i guess if all the records are compared with every record in the source than it will slow the process
    is there any way wherein if the processing is for suppose for
    march than the records are not compared with the previous months data
    will partitioning help
    if yes can i know where can i learn more about partitioning

  • Automated HR Ad hoc queries

    We are creating background job for running the report in background...but i want the output(report) to send an email in Excel format after the job run successfully...
    The only problem is the attachemnt in the email we are getting it as HTML  (filename.htm). So is there any way we can get this as Excel or CSV attachment?
    I tried configuring this in SQ01 with spreadsheet as well as in the query under setting.
    Is there any solution to get this corrected so that the end user get a excel, XML or a .csv file.

    We are creating background job for running the report in background...but i want the output(report) to send an email in Excel format after the job run successfully...
    The only problem is the attachemnt in the email we are getting it as HTML  (filename.htm). So is there any way we can get this as Excel or CSV attachment?
    I tried configuring this in SQ01 with spreadsheet as well as in the query under setting.
    Is there any solution to get this corrected so that the end user get a excel, XML or a .csv file.

  • What do I do when my google stops working because my computer is sending automated queries?

    Some sites are working and some are not, How do I solve this problem?

    I use iPod Music Liberator to transfer song files from iPod to computer.
    http://www.zeleksoftware.com/
    There are other utilities, including some that are free. Do a Google search to find them.

  • Photoshop CC 2014   Bridge CC: automated tasks missing

    I Have downloaded the new Photoshop CC 2014 and updated to Bridge CC. I am no longer able to run automated tasks from Bridge in Photoshop because the "photoshop" submenu is no longer available under tools… unistalling en reinstalling brings no avail. I'm now back to Photoshop CS6 and Bridge CS6… I just would like to know: Am I doing something wrong or is this a bug that hopefully will soon get fixed?

    Please post queries regarding Adobe Bridge over at
    Bridge General Discussion

Maybe you are looking for