LevSelector.com |
Oracle
On This Page | Other Pages |
* intro * tools * books * hints |
* Oracle Bulk Operations |
Intro | home - top of the page - |
* technet.oracle.com
- Oracle Technology Network
* asktom.oracle.com - Thomas Kyte's site
* directory.google.com/Top/Computers/Software/Databases/Oracle
- Oracle on Google
* www.learningoracle.com
- book recomendations
* oracle.oreilly.com
- Oracle books on O'Reilly
* www.oramag.com
- Oracle Magazine
* oracle.ittoolbox.com -
* education.oracle.com
-Oracle courses and certification tests
* http://www.orafaq.com = http://www.orafaq.net - FAQ, Scripts, whole world
* http://www.orafaq.net/faqscrpt.htm - Oracle Scripts - very good
* www.oriolecorp.com/index1.html - Free Oracle SQL scripts and DBA tools
* www.revealnet.com
- RevealNet, Oracle information portal.
* www.dbasupport.com/cert/
- Oracle Certification training
* www.dbasupport.com/dbres/Technical_Docs/Tutorials/
- tutorials
* www.dbasupport.com/faq/ - Oracle FAQ.
* www.oraclenotes.com/
- Study Oracle Notes and Forums
* www.animatedlearning.com/ - animated tutorials
* www.sideris.com/curriculum.asp - training (for $$ - but has free contents)
* Google
search for video+training+oracle - find video training on Google
* www.oracle.com/oramag/code/
- Tips from Oracle
* www.revealnet.com/dbapipe/tips.htm
- tips on RevealNet
* www.osborne.com/oracle/dbafaq/dbafaq1.htm
- A good FAQ for administrators.
* www.theoracleresourcestop.com/
- discussions, scripts, info, links, white papers
* www.geocities.com/SiliconValley/Peaks/4535/oracle/
- Biju's Oracle DBA page - scripts, tips, tools, utilities, unix scripts,
gensql, hints, rdbms, oracle FAQ
* www.rchath.com
- Rakesh Chathli's Site on Oracle Financials' implementation issues -
Solutions to various Oracle Financials' implementation issues as posted
on OraApps List
Tools | home - top of the page - |
Tools For Oracle:
Oracle download page - here you can download the client and the database:
http://www.oracle.com/technology/software/products/database/
To play with Oracle on your PC you can download Oracle Express Edition:
http://www.oracle.com/technology/products/database/xe/
It comes with a client - so that all your tools will work.
Books | home - top of the page - |
Books:
Old books:
Hints | home - top of the page - |
Put SQL commands into a file (e.g. test.sql) and run it from unix prompt:
cat test.sql | sqlplus scott/tiger@starter
Note: remember to put a semicolon at the end of every SQL statement
login: oracle
password: (root password) ps -ef | grep smon export ORACLE_SID=starter sqlplus system/manager@starter // or from SQL> connect system/manager@starter // SQL clients: sqlplusw, SQL Navigator, TOAD select name from v$database select * from cat select * from dict !pwd spool datadict.txt ... spool off desc cat
create user myuser identified by //here is her password
select table_name from dict where table_name like '%PRIV%';
|
Here is how to get 10 rows of the result - and then next 10:
SELECT *
FROM ( SELECT * FROM my_table ORDER BY my_col ) WHERE ROWNUM <= 10; Next 10: just grab all of them out to the end, and only show the
last 10 (possibly adding
SELECT col1, col2, col3
|
How to update / delete depending on a join to another table:
update maintab m
set (m.fname,m.lname) = (select u.fname,u.lname from updates u where m.id=u.id) where exists (select u.fname,u.lname from updates u where m.id=u.id) Note: if you omit the "where exists" clause - then all rows in the maintab will be updated (those rows which don't belong to inner join will be updated by NULLs). update maintab m
delete from maintab m
Outer join - include all departments:
|
Working with Oracle from Perl:
Setting up DBD-Oracle:
untar the files as usual. procedure standard: perl Makefile.PL make make test make install but before running all this make sure that you've done 2 things: 1. add env. variables - here is part of .bash_profile : ORACLE_BASE=/usr/local/oracle/8i/u01/app/oracle ORACLE_HOME=$ORACLE_BASE/product/8.1.6 ORACLE_SID=starter CLASSPATH=.:~oracle/jre118_v1/lib/rt.jar PATH=.:$PATH:$HOME/bin:$ORACLE_HOME/bin ENV=$HOME/.bashrc USERNAME="root" PS1="\u@\h \w# " mesg n export USERNAME ENV PATH ORACLE_BASE ORACLE_HOME ORACLE_SID CLASSPATH ------------------------------------------------------- 2. put your $ORACLE_HOME/lib in your /etc/ld.so.conf (expand it to the explicit path) and then re-run /sbin/ldconfig. You may need to add database name into test.pl (or edit other env. accordingly)
Here is an example of simple Perl script using DBD-Oracle:
More examples on how to work with Oracle from Perl you can find in documentation for DBD::Oracle. For example, here is how to execute pieces of PL/SQL code: (from http://search.cpan.org/~pythian/DBD-Oracle-1.22/Oracle.pm#PL/SQL_Examples )
PL/SQL does not always give you details about errors in procedures. To get more info do this: show errors; -- shows the last errors. You can also abbriviate it as "SHO ERR". or something like this: show errors procedure myproc; |
------------------------------------------------------------------------------
"decode" function - if/else, if/else, ..., default - functionality decode( expression , search , result [, search , result]... [, default] ) SELECT |
"NVL" function - replace null value with some other value NVL( string1, string2 ) string1 is the string to test for a null value. |
Example: select '2'||to_char(sysdate, 'yyyymmdd')||rownum Sequence_Number, |
Detecting and removing duplicates select distinct ... select unique_id delete from mytab t1 delete from mytab where rowid NOT IN (select max(rowid) from mytab group by key1); delete from mytab a delete from
customer CREATE [UNIQUE] INDEX index_name
|
outer join - old and new syntax select a.name, nvl(b.title,'--') title select a.name, nvl(b.title,'--') title select a.name, nvl(b.title,'--') title |
VARCHAR2 - 1..4000 bytes
Example: the value 7,456,123.89 will display as follows INTERVAL YEAR[(p)] TO MONTH - stores a period of time represented as years and months. p is the number of digits in the YEAR datetime field (can be 0..9, default = 2). INTERVAL DAY[(p1)] TO SECOND[(p2)] - stores a period of time represented as days, hours, minutes and seconds with a fractional part. |
Output from the script First method using dbms_output.put_line('...'). For example: set serveroutput on; The problem - it is buffered - and will make output only at the very end. sqlplus -s / <<-EOF The best way - using autonomous transaction. An autonomous transaction can be committed even if the parent transaction that triggered it is rolled back, hence the term "autonomous". The autonomous transaction has no link to the calling transaction, so only commited data can be shared by both transactions. These are useful for auditing purposes, where even if an attempted parent transaction fails, a child autonomous transaction will still record the parent transaction, and mark it as failed, aborted, cancelled and so on. Example: procedure myprint (mes mylog.message%type) Note: the a.t. method is better than using dbms_output.put_line('...'), because put_line() is buffered until the enclosing transaction is ended. The following types of PL/SQL blocks can be defined as autonomous transactions: |
xxxx