Tuesday, November 17, 2009

How to disable and reenable constraints in Oracle

Disable
1. Run this script in your sql editor and output the results

select 'ALTER TABLE '||substr(c.table_name,1,35)||
' DISABLE CONSTRAINT '||constraint_name||' CASCADE;'
from user_constraints c, user_tables u
where c.table_name = u.table_name;

2. Copy paste the results and run them in your SQL editor again


Enable
1. Run this script in your sql editor and output the results

select 'ALTER TABLE '||substr(c.table_name,1,35)||
' ENABLE CONSTRAINT '||constraint_name||' ;'
from user_constraints c, user_tables u
where c.table_name = u.table_name;

2. Copy paste the results and run them in your SQL editor again

Saturday, October 3, 2009

Delete all rows in Oracle database

1. Run this:
select 'delete from ', table_name, '; ' from user_tables;

2. run and script the output into a file.

3. copy paste the commands from the file into your SQL editor.

done

Wednesday, September 23, 2009

Oracle: Drop all tables in the present schema

1. Login as the desired user
2. Issue this SQL
select 'drop table ', table_name, 'cascade constraints ;' from user_tables;

3. You will then get a list of drop table commands.
4. Just copy/paste into an SQL editor of your choice and run the whole batch of scripts

Thursday, July 16, 2009

Uninstall Oracle....the easy way

Try this...quick and painless

run this> $ORACLE_HOME/oui/bin/runInstaller

Select "Installed Products"

Select and click "Remove"

Voila

Friday, April 10, 2009

Reg Ex to validate comma delimited fields

Here's something that I cooked up that perhaps someone could find useful.

[\\w\\d]*(,[\\w\\d]*)*

e.g input asdf123,asdf234,asdf2134



no spaces between commas so that saves you from having to trim later.

Monday, February 2, 2009

Look for text in files recursively in Ubuntu

grep -r "text to search" /directoryToSearch

Saturday, January 10, 2009

Maven plugin ClassNotFoundException

Maven plugins use their own class loader which does not include the current projects class loader. To get the plugin to reference the class loader,
  • include the outputDirectory of the current project into a new URLClassLoader which has the present threads context loader as its parent
  • include all references to classes loaded at the current project to include this new classloader
  • do this at the execute() method of the Mojo.

try {

File classesFolder = new File(this.outputDirectory,"classes");

URL[] urls = new URL[]{classesFolder.toURI().toURL()};
URLClassLoader classLoader = new URLClassLoader(urls, (URLClassLoader)Thread
.currentThread().getContextClassLoader());

Thread.currentThread().setContextClassLoader(classLoader);


} catch (MalformedURLException e1) {
System.out.println("[Fatal Error] Unable to create custom classloader for project");
e1.printStackTrace();
System.exit(0);
}

where outputDirectory is
/**
* Location of the file.
* @parameter expression="${project.build.directory}"
* @required
*/
public static File outputDirectory;

and classes within the plugin that that attempts to load classes within the current project should so something like the following

something like this:
theClass = Class.forName(className,true,Thread.currentThread().getContextClassLoader());