Duel with Dual
Dual is a default table that comes with all Oracle db installations. It is tiny table with just one column and has just one row. See desc below.
desc dual;
DUMMY
select * from dual;
DUMMY
X
It's owner is SYS but all users have access to it. This table always returns one row. So that's something that comes in handy.
Usages:
1. mostly to select pseudo columns from tables or views
2. test any of the Oracle functions
e.g.
select to_date(sysdate) as system_date from dual;
SYSTEM_DATE
6/25/2009
select 'ruchi' as name, 'crazy' as fame from dual;
NAME FAME
ruchi crazy
select upper('ruchi') as ucase from dual;
UCASE
RUCHI
Thursday, June 25, 2009
Wednesday, June 24, 2009
Oracle functions INSTR, SUBSTR, LENGTH, UPPER, LOWER
Usage:
length('snake')
= 5
upper('body')
= BODY
lower('roLLeR')
=roller
subset of a string is substr
substr('thisplace', 5)
= place
substr('thisplace',2,3)
= his
find in a string is instr
instr('thisplace','his')
=2
instr gives this starting position of the searched string in source string.
Usage:
length('snake')
= 5
upper('body')
= BODY
lower('roLLeR')
=roller
subset of a string is substr
substr('thisplace', 5)
= place
substr('thisplace',2,3)
= his
find in a string is instr
instr('thisplace','his')
=2
instr gives this starting position of the searched string in source string.
Tuesday, June 23, 2009
Toad Shortcuts
F2 - Hide data grid and show full screen editor
F4 - Run desc on the object under the cursor
F6 - Switch between editor and data grid
F7 - Clean editor
F8 - Show SQL statement history
Alt + downArrow - Display last executed SQL statement
Alt + upArrow - Brings previous recalled SQL statement
Ctrl + T or Ctrl + . - to expand Table names
F2 - Hide data grid and show full screen editor
F4 - Run desc on the object under the cursor
F6 - Switch between editor and data grid
F7 - Clean editor
F8 - Show SQL statement history
Alt + downArrow - Display last executed SQL statement
Alt + upArrow - Brings previous recalled SQL statement
Thursday, June 11, 2009
Database User Access information
To look up what role/access you have in an Oracle database we can use this query -
select * from dba_role_privs where grantee = 'userid';
Table structure of dba_role_privs:
If there's no entry for the user-id in this table that means user doesn't have access to the database.
select * from dba_role_privs where grantee = 'userid';
Table structure of dba_role_privs:
Column Name ID Data Type
GRANTEE 1 VARCHAR2 (30 Byte)
GRANTED_ROLE 2 VARCHAR2 (30 Byte) -- Roles defined specifically for the db
ADMIN_OPTION 3 VARCHAR2 (3 Byte)
DEFAULT_ROLE 4 VARCHAR2 (3 Byte)
If there's no entry for the user-id in this table that means user doesn't have access to the database.
Friday, June 5, 2009
Thursday, June 4, 2009
I use CVS at work for version control. It's very easy to learn and setup. There are few stumbling blocks though for a new user.
Removing a file permananently from CVS:
rm badfile
cvs remove badfile
* if you decide not to remove the file, just do : cvs update filename cvs commit badfile
Committing without opening editor
cvs commit -m 'interesting msg' filename
The above message format can be used with other cvs commands as well that require a modification message.
e.g
cvs import -m
This tutorial is very helpful and amusing.
An excerpt
1. Two developers, A and B, check out working copies of a project at the same time. The project is at its starting point - no changes have been committed by anyone yet, so all the files are in their original, pristine state.
2. Developer A gets right to work and soon commits her first batch of changes.
3. Meanwhile, developer B watches television.
4. Developer A, hacking away like there's no tomorrow, commits her second batch of changes. Now, the repository's history contains the original files, followed by A's first batch of changes, followed by this set of changes.
5. Meanwhile, developer B plays video games.
6. Suddenly, developer C joins the project and checks out a working copy from the repository. Developer C's copy reflects A's first two sets of changes, because they were already in the repository when C checked out her copy.
7. Developer A, continuing to code as one possessed by spirits, completes and commits her third batch of changes.
8. Finally, blissfully unaware of the recent frenzy of activity, developer B decides it's time to start work. He doesn't bother to update his copy; he just commences editing files, some of which may be files that A has worked in. Shortly thereafter, developer B commits his first changes.
Removing a file permananently from CVS:
rm badfile
cvs remove badfile
* if you decide not to remove the file, just do : cvs update filename cvs commit badfile
Committing without opening editor
cvs commit -m 'interesting msg' filename
The above message format can be used with other cvs commands as well that require a modification message.
e.g
cvs import -m
This tutorial is very helpful and amusing.
An excerpt
1. Two developers, A and B, check out working copies of a project at the same time. The project is at its starting point - no changes have been committed by anyone yet, so all the files are in their original, pristine state.
2. Developer A gets right to work and soon commits her first batch of changes.
3. Meanwhile, developer B watches television.
4. Developer A, hacking away like there's no tomorrow, commits her second batch of changes. Now, the repository's history contains the original files, followed by A's first batch of changes, followed by this set of changes.
5. Meanwhile, developer B plays video games.
6. Suddenly, developer C joins the project and checks out a working copy from the repository. Developer C's copy reflects A's first two sets of changes, because they were already in the repository when C checked out her copy.
7. Developer A, continuing to code as one possessed by spirits, completes and commits her third batch of changes.
8. Finally, blissfully unaware of the recent frenzy of activity, developer B decides it's time to start work. He doesn't bother to update his copy; he just commences editing files, some of which may be files that A has worked in. Shortly thereafter, developer B commits his first changes.
Subscribe to:
Posts (Atom)