Thursday, July 9, 2009

Solution for ORA-01157

Recently while dropping the database some of my other datafiles gone missing. Because of this when trying to open the database got an error "ORA-01157 - Cannot find lock for the file D:\oracle\Oradata\Oradesigner\Designer" and the database is not at all opening

Solution
1. Login to database as / as sysdba
sqlplus > connect / as sysdba
SQL*Plus: Release 9.2.0.8.0 - Production on Thu Feb 8 14:54:38 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to an idle instance.

sqlplus > startup mount;
ORACLE instance started.
Total System Global Area 236404368 bytes
Fixed Size 724624 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 798720 bytes
Database mounted.
sqlplus > alter database datafile 'D:\oracle\Oradata\Oradesigner\Designer' offline drop;
Database altered.
sqlplus> alter database open;
Database opened

Tuesday, April 21, 2009

Changing the Default Gateway using Command prompt

The command is:
to change IP and default gateway:
netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 192.168.0.254 1

to change DNS:
netsh int ip set dns "local area connection" static 192.168.0.254 primary

This is assuming 3 things.
1) The network adapter you're trying to change the IP for is "local area connection". It could also be "local area connection 2" or "wireless network connection". Look in your control panel for the correct name
2) The IP you want to set is 192.168.0.101, change this to whatever IP to want to use.
3) The default gateway and dns are the same IP. If you are using some kind of router they usually are. Change this to match your network config found with the command ipconfig /all

You will need to run both commands to change the IP.

Friday, May 23, 2008

Creating - Oracle DB Links

1. Log into the db from which the query will be executed.
2.create public database link using
ex Create Database link db1_link using db1_machine1
3. Database link is created

Common Problems
===============
1. When global_names parameter set to TRUE then default domain name 'REGRESS.RDBMS.DEV.US.ORACLE.COM' is appended at the end of the dblink name and will cause ORA-02805 error.


Changing global names
================
Alter system set Global_names =false;

Thursday, March 27, 2008

Date Queries in MS Access

Writting query in MS Access for Date column differes from other SQL formats. For eg Writing the sql in ORACLE you will follow this patterrn

Select First_Name, DOB from emp where dob='01/jul/2008'

whereas in Access it has to be written like this
Select First_Name, DOB from emp where dob=#01/jul/2008#

Access understands the literals enclosed within # as date.

Sunday, February 24, 2008

Java - XPath for parsing XML

XPATH
(XML Path Language) is a language for selecting nodes from an XML document. In addition, XPath may be used to compute values (strings, numbers, or boolean values) from the content of an XML document. The current version of the language is XPath 2.0, but because version 1.0 is still the more widely-used version, this article describes XPath 1.0.

The XPath language is based on a tree representation of the XML document, and provides the ability to navigate around the tree, selecting nodes by a variety of criteria. In popular use (though not in the official specification), an XPath expression is often referred to simply as an XPath.

Originally motivated by a desire to provide a common syntax and behavior model between XPointer and XSLT, XPath has rapidly been adopted by developers as a small query language, and subsets are used in other W3C specifications such as XML Schema and XForms.


Using XPath sample

1. Create the DOM XML document
String fileName = "D:/sample.xml"
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new File(fileName));

2. Create XPATH query string like "/parent/child/grandchild'[@attribute = value]'"
for eg
String XpathQueryContexts = "/root/module[@display='" + moduleKey +
"']/subjectArea[@name='" + subjAreaKey +
"']/tab[@targettable='" + tabKey + "']/" +
"filter-contexts";

root is the parent node
subjectArea is the child node for root
tab is the child node for subjectArea
targettable is a property defined in the tab node

3. Get the nodes as a ArrayList for the given query condition at step 2
List lstContexts = XPath.selectNodes(jDomDocument, XpathQueryContexts);


More information available in
http://en.wikipedia.org/wiki/XPath

Monday, November 26, 2007

Starting up 10g EM console

1. Start the command prompt

2. Set the ORACLE SID to the instance on which the EM console needs to be started using the command like
Set ORACLE_SID=ocp

3. execute the command
emctl start dbcconsole

Above command results in following status message
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://PURUSHOTHAMAN:5504/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ...The OracleDBConsoleocp service is starting....
The OracleDBConsoleocp service was started successfully.


4. using IE / firefox open the page http://PURUSHOTHAMAN:5504/em

Thursday, November 22, 2007

Changing column data type with data

Recently my friend came with a stragne requirement. He has data in one of the columns which is date value but the table is wrongly created as varchar2 column. He wants to change the datatype from varchar2 to date.

Here it goes

First created a table like this

create table a(id number, dt1 varchar2(20));

Inserted some values into the table using following queries

insert into a values (4,'04/jul/2007')
insert into a values (1,'01/jul/2007')
insert into a values (2,'02/jul/2007')


Now create another column in the same table like this
alter table a add dt2 date


Now update the newly created column with the existing value using the query

update a set dt2=to_date(dt1)


Drop the varchar2 column from the table using
alter table a drop column dt1

Rename the newly created column
alter table a rename column dt2 to dt1