Oracle: read the entries from alert log

Sometimes it’s necessary to read the information from the alert log together with the timestamp of the error.

The very simple Unix-shell script helps to do this:


echo
echo 'Enter # of lines:'
read NUM
tail -$NUM alert_${ORACLE_SID}.log | awk '
BEGIN {prev="" ; ret=1 }
/^(...-|Error)/ { if ( prev !~ /^(...-|Error)/ ) { print "" ; print prev;} print $0;ret=0}
{prev=$0}
END { exit ret } '

This code could be assigned to some hotkey in Your favorite telnet application, so You just need to press something like “Alt+A” to see the quick review of the recent Oracle errors.

Example:

Enter # of lines:
1000

Sep 01 19:42:03 2009
Errors in fileARC0: Archiving not possible: error count exceeded

Sep 01 19:42:06 2009
Errors in file testsrv_arc0_23486.trc:
ORA-16038: log 1 sequence# 112 cannot be archived
ORA-19502: write error on file “”, blockno (blocksize=)
ORA-00312: online log 1 thread 1: ‘redo_g1_m1.log’

Oracle: export as sysdba

The following trick could be used, if You want to start Oracle export as sysdba: use double quotes around the single quotes.

Warning! Dump consistency could not be guaranteed, if the export is done under sys user!


exp userid=" '/ as sysdba' " parfile=exp.par

Possible parameter file:

file=mydump.dmp
compress=n
log=mydump.log
direct=y
full=n
owner=SCOTT
consistent=y
feedback=10000

WHICH command for DOS

If You need the analog of Unix ‘which’ command and do not have Resource Kit, the following batch file will help.
The code was found on www.ss64.com
Published with the permission of the author, Clay Calvert.


@echo off
SETLOCAL
(set WF=)

:: Look for file in the current directory

for %%a in ("" %PATHEXT:;= %) do (
if not defined WF if exist "%~1%%~a" set WF=%CD%\%~1%%~a)

:: Look for file in the PATH

for %%a in ("" %PATHEXT:;= %) do (
if not defined WF for %%g in ("%~1%%~a") do (
if exist "%%~$PATH:g" set WF=%%~$PATH:g))

:: Store the Help Error message

if NOT "%~x1"=="" goto:END
for /f "delims=." %%a in ('help.exe *') do set HlpErr=%%a

:: If command missing from Help, goto end

help.exe "%~1" |find "%HlpErr%">nul && goto:END

:: Listed in help so find file in System32

for %%a in (exe com) do (
if /i "%WF%"=="%windir%\system32\%~1.%%a" goto:END)

:: File not in System32, so must be an internal command

set WF="%~1" is an internal command

:END
if defined WF (echo.%WF%) else (
echo The file: "%~1" was not found)

:: Credits:
:: Clay Calvert
:: alt.msdos.batch.nt

Oracle: grant permissions to the whole schema

Technically saying, this is granting permissions to all tables in the schema


set verify off
set feedback off
set pagesize 10000
set linesize 120ACCEPT main_owner CHAR PROMPT 'MAIN OWNER: '
ACCEPT grant_to CHAR PROMPT 'GRANT TO: '
ACCEPT permissions CHAR PROMPT 'PERMISSIONS (i.e. SELECT,UPDATE): '

spool grant_from_&&main_owner._to_&&grant_to..sql

select 'grant &&permissions on "&&main_owner"."'
||table_name
||'" to "&&grant_to";' "---"
from dba_tables
where owner=upper('&&main_owner');

spool off

undefine permissions
undefine main_owner
undefine grant_to

Template for proxy auto-config file

Proxy autoconfig file could be used in browser (Opera,FireFox,IE) to change the proxy dynamically.


var ALLOWED = "DIRECT";
var DISALLOWED = "PROXY 0.0.0.0:1234";

function FindProxyForURL(url, host)
{
if (shExpMatch(url,"*.badsite.com/*")) {return DISALLOWED;}
var currentTime = new Date();// convert the current time to minutes
var now = 60*currentTime.getHours() + currentTime.getMinutes();

// Do not allow the access before 18:00
if (now < 18 * 60 ) { return DISALLOWED ; } else { return ALLOWED ; } } // end of function

Additional examples

JavaScript: build table dynamically


<script type="text/javascript">
function buildTable(n_rows,n_columns) {

var the_body = document.getElementsByTagName("body")[0];

var new_table = document.createElement("table");
var new_tbody = document.createElement("tbody");

var new_row, new_col, new_text ;

for(row=1;row<=n_rows;row++) {
new_row = document.createElement("tr");
new_row.className = "tr"+row ;
for(col=1;col<=n_columns;col++) {
new_col = document.createElement("td");
new_col.className = "td"+col ;
new_text = document.createTextNode("text:" + row + ":" + col );

new_col.appendChild(new_text);
new_row.appendChild(new_col);
}
new_tbody.appendChild(new_row);
}

new_table.appendChild(new_tbody);
new_table.setAttribute("border", "2");

the_body.appendChild(new_table);

return new_table ;

}
</script>
<body>
Example:
<script type="text/javascript">
buildTable(4,3)
</script>
</body>

There is also interesting article on oreillynet.com, discussing performance improvement for such operations.