My Ramblings with Oracle-11g
27 Sep 2015 #sql #oracle11gIntro :
I have recently started using Oracle 11g
and boy, doesn’t it come with enough problems already!! However, it may be due to my undying allegiance to mysql
and sqlite
. But whatever be the case.
Here are some of the things which I found would be useful to a first time user of Oracle 11g
. I will try to update it when I find something useful.
If you haven’t already installed
Oracle 11g
. I wrote a small article on how to do so sometime back.
Creating a new user :
Now we can use the default users SYSTEM
or SYS
, but I prefer creating my own here.
To do that
Now connect to the new user lab
To Delete a User :
After dropping the user, you need to, for each related tablespace, take it offline and drop it. For example if you had a user named ‘SAMPLE’ and two tablespaces called ‘SAMPLE’ and ‘SAMPLE_INDEX’, then you’d need to do the following:
1
2
3
4
5
DROP USER SAMPLE CASCADE;
ALTER TABLESPACE SAMPLE OFFLINE;
DROP TABLESPACE SAMPLE INCLUDING CONTENTS;
ALTER TABLESPACE SAMPLE_INDEX OFFLINE;
DROP TABLESPACE SAMPLE_INDEX INCLUDING CONTENTS;
There is no such thing as IF EXISTS
:
I mean what! I find this really irritating in the part of Oracle
to not give support for this feature as any other major RDMS system implements this.
Lets try it out
So we don’t have any relations
right now. Lets try to drop tasdik
which does not exist the way we do in mysql
.
If you try to DROP
a relation which does not exist, the query will not stop executing in the middle, but will just give you an error like the above
Well, sqlite
has a limitation where we cannot alter
the attribute
in a relation
, like add
or delete
an attribute to a relation. So nobody is perfect here.
No support for cursor keys :
As you can see, whenever you press the cursor keys, there is garbage on the screen. Now I was not sure why this was happening. Turns out it doesn’t support the arrow keys in *nix
based systems. (Good news for those on windows
).
But well there is a workaround.
You can use a third party utility called rlwrap
.
rlwrap is a readline wrapper, a small utility that uses the GNU readline library to allow the editing of keyboard input for any other command. It maintains a separate input history for each command, and can TAB-expand words using all previously seen words and/or a user-specified file.So you will be able to use arrows and also get a command history as a bonus.
After you have installed the utility run sqlplus the following way:
And the arrow keys would work just fine
References:
- http://stackoverflow.com/questions/22386976/create-a-user-with-all-privileges-in-oracle
- http://stackoverflow.com/questions/205736/get-list-of-all-tables-in-oracle
- http://stackoverflow.com/questions/969245/how-to-delete-a-user-in-oracle-10-including-all-its-tablespace-and-datafiles
- http://stackoverflow.com/questions/9890636/arrow-keys-are-not-functional-in-sqlplus