简体   繁体   中英

Schedule Oracle Reports and export to XML

I have a report that I need to run everyday @ 00:00 and export all the information from the table to a specific location with a specific name.

Example:

    select * from my_table 
where date between  SYSTIMESTAMP -2  and SYSTIMESTAMP -1 

and to export this to file date.xml.

Is this possible from Oracle SQL Developer or do I need other tools?

No Oracle version so I assume 10 or 11.

To schedule your process you just have to create a job and schedule it. The job has to run your script (which can be a function or a stored procedure). Here the documentation: http://docs.oracle.com/cd/B28359_01/server.111/b28310/scheduse.htm#i1033533

To write to a file you can use the spool command in SQL. Here you can find the documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12043.htm

It's really simple to use.

spool @path/nomefile
la tua query
spool off

Obviously the machine from which you run the script must have write permissions on the machine where you're going to write the file (I say this because I often forget to check out).

To create a XML it is slightly more complex and a little long to explain here but there is a nice post on the community of Oracle that explains it and makes a simple and practical example: https://community.oracle.com/thread/714758?start=0&tstart=0

If you do not want to use a job in Oracle you can write a .Sql file with the connection commands, the spool command and your query and schedule it on the server machine on which you intend to set as a simple command sqlplus.

---------- italian version ---------------

Non hai indicato la versione di Oracle che stai usando.

Per schedulare il processo devi semplicemente creare un job e schedularlo. Il job esegue il tuo script (che può essere una function o una intera stored procedure) Qui trovi la documentazione: http://docs.oracle.com/cd/B28359_01/server.111/b28310/scheduse.htm#i1033533

Per scrivere su un file puoi usare il comando spool di sql Qui trovi la documentazione: http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12043.htm

E' molto banale da usare.

spool @path/nomefile 
la tua query 
spool off

Ovviamente la macchina da cui esegui lo script deve avere i permessi di scrittura sulla macchina su cui andrai a scrivere il file (lo dico perché io spesso mi dimentico di controllare ^__^)

Per creare un xml la cosa è leggermente più complessa ed un poco lunga da spiegare qui però c'è un bel post sulla community di Oracle che lo spiega e fa un esempio semplice e funzionale: https://community.oracle.com/thread/714758?start=0&tstart=0

Se non vuoi usare un job dentro Oracle puoi scrivere un file .sql con i comnadi di connessione, lo spool e la tua query e schedularlo dalla macchina server su cui vuoi che parta come un semplice comando sqlplus. Se ti servono dettagli chiedi pure. ^__^

Spero sia sufficiente.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM