Wednesday, December 28, 2011

some syntax to create user in Oracle Database


***********************************************************************************************************************
--To find the default tablespace in DB:
SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE';
-- this gives the output "USERS" in my case

--create user: here i am using user name "sdb" password "password"
CREATE USER sdb IDENTIFIED BY password
DEFAULT TABLESPACE USERS       
TEMPORARY TABLESPACE temp ;     

--Default object tablespace
-- Assign space for table and index segments
--If a user creates an object (such as a table or an index) without explicitely specifying the tablespace in which it goes, Oracle will place the object in the default object tablespace.
--Default temporary tablespace
-- Assign sort space
--If a user needs a temporary segment for an operation (such as a sort), Oracle will place the data in his default temporary tablespace.

--to give the user some space quota on its tablespaces:
ALTER USER sdb QUOTA UNLIMITED ON Users;

--grant CREATE SESSION privilege necessary to login, this is the right to connect to the database
GRANT CONNECT, RESOURCE TO sdb;
-- Make user a DB Administrator
GRANT DBA TO sdb;

-- lock a user account
ALTER USER sdb ACCOUNT LOCK   
-- unlocks a locked users account
ALTER USER sdb ACCOUNT UNLOCK;

-- Force user to choose a new password
ALTER USER sdb PASSWORD EXPIRE; 
-- choose new password
ALTER USER sdb IDENTIFIED BY password1

-- Remove user
DROP USER sdb CASCADE;

***********************************************************************************************************************

some concepts:
Users in Oracle                 
In Oracle terminology, a user is someone who can connect to a database (if granted enough privileges) and optionally (again, if granted the appropriate privileges) can own objects (such as tables) in the database.
The objects a user owns are collectively called >schema. A schema, on its part, is always bound to exactly one user. Because there is obviously a 1 to 1 relationship between a user and a schema, these two terms are often used interchangeable.
In order to find out what users are created on the database, one can use dba_users

A user's schema consists of all objects that belong to this user.

Oracle database objects                              
Oracle distinguishes between the following «object»:
    Tables
    Views
    Indexes
    Clusters
    Synonyms
    Sequences
    Procedures
    Functions
    Packages
    Triggers
    ...

All objects that belong to the same user are said to be this user's schema.

***********************************************************************************************************************

find commands in Linux


Find  a Word for a particular word in files present in multiple subdirectories
find . -type f -exec grep "dvc88601" {} \; -print

find ./ -type f -exec grep -i -H 'aaa' {} \;

if there is a escape character like “-” then use “\” for example for finding “–aaa”
find ./* -exec grep -i -H '\-aaa' {} \;

finding the occurrence in a particular format of a file: for example here we are finding it only in “.txt” files
find ./ -iname \*.txt\* -exec grep -i -H 'bbb' {} \;

Find and Replace:
this is meeting the requirement for me :
$ perl -e "s/pepsi/coke/g;" -pi $(find /home/oracle/vishal/test -type f)
syntax:
$ perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)

Ex:
findreplaceExurl.sh
perl -e "s/Vivek/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Pratheep/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Prateek/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Tom/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Jimmy/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Ramanujam/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Naveen/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Jophy/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Krishna/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)


Find and Replace:
find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

Find and Delete:
find ./* -type f -exec sed -i 's/index.html//g' {} \;

Find a file
========
The Linux 'find' command will list files and directories that match the arguments to the command and pass specified tests. For example, to find all 'txt' files in the home directory, the following command can be used:

find ~ -name *.txt

The '~' means start at the user's home directory and the -name is a test which means list only files with that particular name. Find has many tests but some of the most useful for finding files that have been updated recently are the -mtime and -mmin tests.


Find All Files Modified in the Last 90 Minutes
==================================

find . -mmin -90

It looks as if the 'find' command has listed files and directories. If we only want to see the files, add the -type test to the command to specify files only.

find . -type f -mmin -90

The sample output would then become

       
                /home/linux/dns/mysql-outfile/dnsx.txt
                /home/linux/dns/mysql-outfile/dnsx.doc
       
      
Adding Xargs to Find
=============================
Xargs' power lies in the fact that it can take the output of one command, in this case find, and use that output as arguments to another command. So, using the basic find command above, let us pass the output of find to xargs and get xargs to issue multiple 'ls -l' commands.

find ~ -type f -mmin -90 | xargs ls -l

The sample output would then become

       
                -rw-rw-r--    1 linux    lunux    10209032 Jun 30 13:28 /home/linux/dns/mysql-outfile/dnsx.doc
                -rw-rw-rw-    1 mysql    mysql    10209032 Jun 30 12:53 /home/linux/dns/mysql-outfile/dnsx.txt
       
      
Find All Files Modified More Than 5 Years Ago
=====================================
In this example of the find and xargs command, we will use a positive time and the mtime test. The operand value to mtime is the number of 24 hour periods. It is not the number of days and the reason why will become apparent if you read 'man find'. So, to see files over 5 years old will will use +1825 as the value for mtime. We have ignored leap years in calculating 5 years as 5*365 days. The command issued is

find ~ -type f -mtime +1825 |xargs ls -l

Tell xargs when to Quit
==================
One problem with the above approach is that a complete listing of the current directory will occur if the find command does not find any files! Xargs sees a list of zero files, but still issues the 'ls -l' command. To overcome this, simply use the xargs option '-r' which means "If the standard input does not contain any nonblanks, do not run the command." So, our command now becomes:

find ~ -type f -mtime +1825 |xargs -r ls -l

Note that the '-r' is an xargs option and therefore comes after the xargs command name but before the command to be issued - in this case 'ls -l'.