$ dbca
$ sqlplus
$ sqlldr
* To make Oracle 10g happy: set shmsys:shminfo_shmmax=4294967295 set shmsys:shminfo_shmmin=1 set shmsys:shminfo_shmmni=100 set shmsys:shminfo_shmseg=10 set semsys:seminfo_semmns=2000 set semsys:seminfo_semmsl=1000 set semsys:seminfo_semmni=100 set semsys:seminfo_semopm=100 set semsys:seminfo_semvmx=32767 set noexec_user_stack=1And reboot...
# /usr/sbin/shutdown -y -g0 -i6
$ORACLE_HOME/rdbms/lib$ make -f ins_rdbms.mk install
SQL> SELECT 2 * 2 FROM dual; 2*2 ---------- 4 SQL>
ora$ bin/sqlplus /nolog conn system/manager as sysdba or connect /as sysdba startup ora$ lsnrctl start ora$ emctl start dbconsole
#!/bin/sh
#
# /etc/init.d/oracle
# Oracle startup script
#
# For Debugging:
#set -x
ORACLE_SID=mysid
ORAHOME=/opt/ora
ORACLE_HOME=$ORAHOME
export ORACLE_SID ORAHOME ORACLE_HOME
PATH=$ORAHOME/bin:/usr/bin
case "$1" in
start)
echo "Starting Oracle..."
sqlplus /nolog <<EOF
connect sys/kent as SYSDBA
startup
EOF
lsnrctl start
isqlplusctl start
emctl start dbconsole
onsctl start
;;
stop)
echo "Stopping Oracle..."
onsctl stop
emctl stop dbconsole
isqlplusctl stop
lsnrctl stop
sqlplus /nolog <<EOF
connect sys/kent as SYSDBA
shutdown abort
quit
EOF
;;
*)
echo "oracle [start | stop]"
;;
esac
SQL> CREATE tablespace mydata datafile '/opt/oracle/oradata/mydata/mydata.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local; --or, a more detailed example-- SQL> CREATE TABLESPACE ts_something logging datafile '/dbf1/ts_sth.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local;
SQL> SELECT name,ctime,ptime from sys.user$;
SQL> CREATE USER bob IDENTIFIED BY toughpassword -- Assign password DEFAULT TABLESACE mydata -- Assign space for table and index segments TEMPORARY TABLESPACE temp; -- Assign sort space -- After creating a new user, assign the required privileges: SQL> GRANT CONNECT, RESOURCE TO bob; SQL> GRANT DBA TO bob; -- Make user a DB Administrator -- Remember to give the user some space quota on its tablespaces: SQL> ALTER USER bob QUOTA UNLIMITED ON tools;
SQL> ALTER USER bob ACCOUNT LOCK; -- lock a user account SQL> ALTER USER bob ACCOUNT UNLOCK; -- unlocks a locked users account
SQL> DROP USER bob CASCADE; -- Remove user
SQL> SELECT table_name FROM user_tables;To show all of the tables that the current user has access to, use:
SQL> SELECT table_name FROM all_tables;--or--
SQL> SELECT tablespace_name,table_name,num_rows from all_tables;Handy commands to get a list of tables:
SQL> SELECT table_name FROM user_tables; --or-- SQL> SELECT table_name,TABLESPACE_NAME,PCT_USED FROM user_tables;
SQL> SELECT table_name,num_rows,blocks FROM user_tables;
SQL> SELECT table_name,num_rows,blocks FROM user_tables ORDER BY num_rows;
SQL> DESCRIBE table
-or, for more detail-
SQL> SELECT dbms_metadata.get_ddl('TABLE','JUST_A_TABLE') from dual;
SQL> SELECT table_name,tablespace_name,num_rows from all_tables where tablespace_name = 'DATA' and table_name like '%people%';
SQL> SELECT dbms_metadata.get_ddl('TABLESPACE', 'DATA') FROM dual;
SQL> SELECT view_name,text FROM all_views;
SQL> CREATE OR REPLACE PROCEDURE myproc
IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/
SQL> SELECT object_name,status,owner FROM all_objects WHERE object_type='PROCEDURE' AND status='INVALID';
SQL> EXECUTE myproc;
Enlarge the SQL*Plus buffer size and enable server message output: SQL> SET ARRAYSIZE 1 SQL> SET MAXDATA 60000 SQL> SET SERVEROUTPUT ON
SQL> SHOW ERRORS PROCEDURE myproc
SQL> show errors procedure myproc; Errors for PROCEDURE myproc: 19/8 PLS-00341: declaration of cursor 'mything' is incomplete or malformed SQL> SELECT text FROM user_source WHERE name='myproc' and line=19;
SQL> ALTER PROCEDURE myproc COMPILE;
SQL> SET HEADING OFF
SQL> SELECT text from user_source where name='myproc' ORDER BY line;
--or, generate the DDL code with--
SQL> SELECT dbms_metadata.get_ddl('PROCEDURE','myproc') FROM dual;
Loop through all the rows in a query with a cursor:
DECLARE
CURSOR dept_cur IS
SELECT deptno
FROM dept
ORDER BY deptno;
-- Employee cursor all employees for a dept number
CURSOR emp_cur (v_dept_no DEPT.DEPTNO%TYPE) IS
SELECT ename
FROM emp
WHERE deptno = v_dept_no;
BEGIN
FOR dept_rec IN dept_cur LOOP
dbms_output.put_line('Employees in Department '||TO_CHAR(dept_rec.deptno));
FOR emp_rec in emp_cur(dept_rec.deptno) LOOP
dbms_output.put_line('...Employee is '||emp_rec.ename);
END LOOP;
END LOOP;
END;
/
CREATE OR REPLACE FUNCTION whoami RETURN VARCHAR2 IS BEGIN RETURN user; END whoami;
SQL> SHOW parameters;
SQL> SHOW parameter open_cursors;
--or--
SQL> SELECT value from v$parameter where name = lower('open_cursors');
SQL> ALTER SYSTEM set open_cursors=1000;
SQL> ALTER SESSION set nls_date_format = 'dd.mm.yyyy hh24:mi:ss';
Activate for all SQL queries: SQL> SET AUTOTRACE ON | OFF;
-- View all connected ORACLE user sessions: SQL> SET LINE 200 SQL> SELECT machine,username,sid,serial# FROM v$session WHERE username IS NOT NULL; -- or, for more detail -- SQL> SELECT a.sid,a.serial#,b.spid,b.pid,a.username,a.osuser,a.machine FROM v$session a, v$process b WHERE a.username IS NOT NULL AND a.paddr=b.addr AND MACHINE='myserver.mycompany.com' ORDER BY sid,serial#; To see the SID and serial# of all Oracle sessions: SQL> SELECT a.sid, a.serial#, b.spid, b.pid, a.username, a.osuser, a.machine FROM v$session a, v$process b WHERE a.username IS NOT NULL AND a.paddr=b.addr; (SPID is the UNIX process pid)
Find an error or omission? Sorry about that! Please e-mail Eric at eric@ericshalov.com and let him know!
All of Eric's Tech Notes are provided on an as-is basis, and may contain
errors or omissions. No statement is made as to thier suitability for
any particular purpose, and no warranty is given. Use at your own risk!
All trademarks are the property of their respective owners.
No duplication of the above information is permitted without prior written
permission of the author(s).
©Copyright 2007 Eric Shalov. All Rights Reserved.