Showing posts with label oracle teacher sourav. Show all posts
Showing posts with label oracle teacher sourav. Show all posts

Thursday, April 19, 2018

Oracle 11g basics,part 1,Oracle Teacher Sourav,Kolkata 09748184075

set ORACLE_SID=sysdba

echo %ORACLE_SID%

set ORACLE_HOME=E:\app\sourav\product\11.2.0\dbhome_1

echo %ORACLE_HOME%

Now connect to oracle

start sqlplus

sqlplus /nolog

connect as sysdba

connect / as sysdba;

run a sample query and find the name of the databse you are connected to


select name from v$database;

to see the instance name which you are connected with

select * from global_name;


exit

Now we like to use the sql developer



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


shut down the database


log in as sysdba

shutdown immediate;

exit


start the database

log in as sysdba

startup;



***********************************************************
Data types supported by oracle

char
varchar2
number
date
timestamp
BLOB
CLOB
User Defined data types


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

Find the number of rows in a table

select count(*) from dba_tablespaces;

(dba_tablespaces give information about tablespaces,during the installation oracle create some tablespaces by default,those tablespaces hold all the data)
to find all the tablespaces currently existing in the database


select * from dba_tablespaces;


we can select particular columns using select such as

select TABLESPACE_NAME,STATUS from DBA_TABLESPACES;

we can also change the order by changing the name of columns







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


to know the structure of the table use describe

describe dba_tablespaces;

desc dba_tablespaces;


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


to find the total number of rows in a table

select count(*) from dba_tablespaces;


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


filtering data using where clause


select * from dba_roles where role='CONNECT';


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


To make your pc faster

go to services.msc

and change these services startup from automatic to manual as written below

(My oracle instance name is sysdba instead of orcl)

Oracledbconsolesysdba

oraclemtsrecoveryservice

oracleoradb11g_home1tnslistener

oracleservicesysdba


you have to start these services manually every time you want to use oracle



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

Find the user list for your oracle database;

select username from dba_users;

let's see if the user scott is enabled or disabled

SELECT username, account_status   from dba_users;

if you find the username scott is locked let's try to enable/unlock that user

alter user scott account unlock;

let's logout and try to use scott

exit


sqlplus /nolog

if you use this command to connect connect using scott and the password tiger it
will prompt you to change the password as it is expired


you could also change the user status and password in a same line such as

alter user hr identified by 123456 account unlock;

after loggin in you can verify it by using this sql command

select * from global_name

then go to sql developer and create another connect using hr and password 123456 and see the tables created for the hr schema




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

directly login as scott


sqlplus scott/tiger@orcl


show the date

SELECT SYSDATE FROM dual;


login as sysdba and run the storeschema.sql

To end SQL*Plus, you enter EXIT. To reconnect to the store schema
in SQL*Plus, you enter store as the user name with a password
of store_password.


connect using sqlplus like this

sqlplus store@sysdba

enter the password



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

creating the database user


CREATE USER sourav IDENTIFIED BY 123456;

If you want the user to be able to work in the database, the user must be granted the
necessary permissions to do that work. In the case of store, this user must be able to log onto
the database (which requires the connect permission) and create items like database tables
(which requires the resource permission). Permissions are granted by a privileged user (for
example, the system user) using the GRANT statement.



GRANT connect, resource TO sourav;


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


Oracle data types explanation


Format Number Supplied Number Stored
NUMBER 1234.567 1234.567
NUMBER(6, 2) 123.4567 123.46
NUMBER(6, 2) 12345.67 Number exceeds the specified precision and
is therefore rejected by the database.


CHAR(length) Stores strings of a fixed length. The length parameter specifies
the length of the string. If a string of a smaller length is stored, it
is padded with spaces at the end. For example, CHAR(2) may
be used to store a fixed-length string of two characters; if 'C' is
stored in a CHAR(2), then a single space is added at the end;
'CA' is stored as is, with no padding.


VARCHAR2(length) Stores strings of a variable length. The length parameter specifies
the maximum length of the string. For example, VARCHAR2(20)
may be used to store a string of up to 20 characters in length. No
padding is used at the end of a smaller string.


DATE Stores dates and times. The DATE type stores the century, all four
digits of a year, the month, the day, the hour (in 24-hour format),
the minute, and the second. The DATE type may be used to store
dates and times between January 1, 4712 B.C. and December 31,
4712 A.D.


INTEGER Stores integers. An integer doesn’t contain a floating point: it is a
whole number, such as 1, 10, and 115.


NUMBER(precision,scale)
Stores floating point numbers, but may also be used to store
integers. The precision is the maximum number of digits
(left and right of a decimal point, if used) that may be used for
the number. The maximum precision supported by the Oracle
database is 38. The scale is the maximum number of digits to
the right of a decimal point (if used). If neither precision nor
scale is specified, any number may be stored up to a precision
of 38 digits. Any attempt to store a number that exceeds the
precision is rejected by the database.


BINARY_FLOAT Introduced in Oracle Database 10g, stores a single precision
32-bit floating point number. You’ll learn more about BINARY_
FLOAT later in the section “The BINARY_FLOAT and BINARY_
DOUBLE Types.”


BINARY_DOUBLE Introduced in Oracle Database 10g, stores a double precision
64-bit floating point number.

using sql developer if you connect using store to enter the store schema you will see

The customers table holds the details of the customers. The
following items are held in this table:
First name
Last name
Date of birth (dob)
Phone number

to create a table like in this schema the sql command is this


CREATE TABLE customers (
customer_id INTEGER CONSTRAINT customers_pk PRIMARY KEY,
first_name VARCHAR2(10) NOT NULL,
last_name VARCHAR2(10) NOT NULL,
dob DATE,
phone VARCHAR2(12)
);



As you can see, the customers table contains five columns,

one for each item in the

previous list, and an extra column named customer_id. The columns are
customer_id Contains a unique integer for each row in the table. Each table should
have one or more columns that uniquely identifies each row; the column(s) are known as
the primary key. The CONSTRAINT clause indicates that the customer_id column is the
primary key. A CONSTRAINT clause restricts the values stored in a column, and, for the
customer_id column, the PRIMARY KEY keywords indicate that the customer_id
column must contain a unique value for each row. You can also attach an optional
name to a constraint, which must immediately follow the CONSTRAINT keyword—for
example, customers_pk. You should always name your primary key constraints, so
that when a constraint error occurs it is easy to spot where it happened.


first_name Contains the first name of the customer. You’ll notice the use of the NOT
NULL constraint for this column—this means that a value must be supplied for first_
name when adding or modifying a row. If a NOT NULL constraint is omitted, a user
doesn’t need to supply a value and the column can remain empty.

last_name Contains the last name of the customer. This column is NOT NULL, and
therefore a value must be supplied when adding or modifying a row.
dob Contains the date of birth for the customer. Notice that no NOT NULL constraint is
specified for this column; therefore, the default NULL is assumed, and a value is optional
when adding or modifying a row.

phone Contains the phone number of the customer. This is an optional value.


You can see the rows in the customers table for yourself by executing the following
SELECT statement using SQL*Plus:
SELECT * FROM customers;

The product_types table holds the names of the product
types sold by the store. This table is created by the store_schema.sql script using the
following CREATE TABLE statement:


CREATE TABLE product_types (
product_type_id INTEGER CONSTRAINT product_types_pk PRIMARY KEY,
name VARCHAR2(10) NOT NULL
);



The product_types table contains the following two columns:

product_type_id uniquely identifies each row in the table; the product_type_id
column is the primary key for this table. Each row in the product_types table must
have a unique integer value for the product_type_id column.

name contains the product type name. It is a NOT NULL column, and therefore a value
must be supplied when adding or modifying a row.

You can see the rows in the product_types table for yourself by executing the following
SELECT statement using SQL*Plus:

SELECT * FROM product_types;


The products Table The products table holds the products sold by the store. The
following pieces of information are held for each product:
Product type
Name
Description
Price

The sql for creating the product table


CREATE TABLE products (
product_id INTEGER CONSTRAINT products_pk PRIMARY KEY,
product_type_id INTEGER
CONSTRAINT products_fk_product_types
REFERENCES product_types(product_type_id),
name VARCHAR2(30) NOT NULL,
description VARCHAR2(50),
price NUMBER(5, 2)
);


The columns in this table are as follows:

product_id uniquely identifies each row in the table. This column is the primary key
of the table.

product_type_id associates each product with a product type. This column is a
reference to the product_type_id column in the product_types table; it is known
as a foreign key because it references a column in another table. The table containing
the foreign key (the products table) is known as the detail or child table, and the table
that is referenced (the product_types table) is known as the master or parent table.

This type of relationship is known as a master-detail or parent-child relationship. When
you add a new product, you associate that product with a type by supplying a matching
product_types.product_type_id value in the products.product_type_id
column .

name contains the product name, which must be specified, as the name column is
NOT NULL.

description contains an optional description of the product.

price contains an optional price for a product. This column is defined as NUMBER(5,
2)—the precision is 5, and therefore a maximum of 5 digits may be supplied for this
number. The scale is 2; therefore 2 of those maximum 5 digits may be to the right of the
decimal point.

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


Adding modifying and removing rows in a table

Adding a Row to a Table
You use the INSERT statement to add new rows to a table. You can specify the following
information in an INSERT statement:

The table into which the row is to be inserted
A list of columns for which you want to specify column values
A list of values to store in the specified columns
When inserting a row, you need to supply a value for the primary key and all other columns
that are defined as NOT NULL. You don’t have to specify values for the other columns if you don’t
want to; those columns will be automatically set to null if you omit values for them.
You can tell which columns are defined as NOT NULL using the SQL*Plus DESCRIBE
command. The following example DESCRIBEs the customers table:

SQL> DESCRIBE customers
Name Null? Type
----------------------------------------- -------- ------------
CUSTOMER_ID NOT NULL NUMBER(38)
FIRST_NAME NOT NULL VARCHAR2(10)
LAST_NAME NOT NULL VARCHAR2(10)
DOB DATE
PHONE VARCHAR2(12)

As you can see, the customer_id, first_name, and last_name columns are NOT NULL,
meaning that you must supply a value for these columns. The dob and phone columns don’t
require a value; you could omit the values if you wanted, and they would be automatically set to null.
Go ahead and run the following INSERT statement, which adds a row to the customers
table; notice that the order of values in the VALUES list matches the order in which the columns
are specified in the column list:

SQL> INSERT INTO customers (
 customer_id, first_name, last_name, dob, phone) VALUES ( 6, 'Fred', 'Brown', '01-JAN-1970', '800-555-1215' );


SELECT *
FROM customers;

will show the added row


Possible error when inserting


When a row is added to the customers table, a unique value for the customer_id column
must be given. The Oracle database will prevent you from adding a row with a primary key value
that already exists in the table; for example, the following INSERT statement causes an error
because a row with a customer_id of 1 already exists:
SQL> INSERT INTO customers (
2 customer_id, first_name, last_name, dob, phone
3 ) VALUES (
4 1, 'Lisa', 'Jones', '02-JAN-1971', '800-555-1225'
5 );
INSERT INTO customers (
*
ERROR at line 1:
ORA-00001: unique constraint (STORE.CUSTOMERS_PK) violated


Modifying an Existing Row in a Table


You use the UPDATE statement to change rows in a table. Normally, when you use the UPDATE
statement, you specify the following information:
The table containing the rows that are to be changed
A WHERE clause that specifies the rows that are to be changed
A list of column names, along with their new values, specified using the SET clause
You can change one or more rows using the same UPDATE statement. If more than one row is
specified, the same change will be made for all the rows. The following example updates customer
#2’s last_name to Orange:

UPDATE customers
SET last_name = 'Orange'
WHERE customer_id = 2;
1 row updated.
SQL*Plus confirms that one row was updated.


SELECT *
FROM customers
WHERE customer_id = 2;


Removing a Row from a Table

You use the DELETE statement to remove rows from a table. You typically use a WHERE clause to
limit the rows you wish to delete; if you don’t, all the rows will be deleted from the table.
The following DELETE statement removes customer #2:
DELETE FROM customers
WHERE customer_id = 2;
1 row deleted.
To undo the changes you’ve made to the rows, you use ROLLBACK:
ROLLBACK;


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

show all the tables in your schema

log in as store

conn store@sysdba;

enter password

select TABLE_NAME from user_tables



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


To see the post number and the instance name of your oracle database

open this file in notepad

E:\app\sourav\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora

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

Tuesday, May 16, 2017

Install oracle 11g on Scientific Linux 6,Oracle Teacher Sourav,Kolkata 09748184075

installing oracle 11g on scientific linux 6

as root

yum -y install openssh-server

service sshd start

chkconfig sshd on

yum -y install nano

nano /etc/group

make the line look like this

wheel:x:10:root,sourav

save and exit

nano /etc/pam.d/su

uncomment the following two lines to make sourav as powerful 

as root

# Uncomment the following line to implicitly trust users in 

the "wheel" group.

auth            sufficient      pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the 

"wheel" group.

auth            required        pam_wheel.so use_uid


save and exit


stop and disable iptables by

/etc/rc.d/init.d/iptables stop 

chkconfig iptables off 


stop and disable ip6tables by

/etc/rc.d/init.d/ip6tables stop 

chkconfig ip6tables off

disable selinux

by 

nano /etc/sysconfig/selinux

change the line 

SELINUX=enforcing to

SELINUX=disabled

save and exit

set the hostname to oracle.sourav by

nano /etc/hosts

127.0.0.1       oracle.sourav   sourav  localhost.localdomain 

localhost
::1             localhost6.localdomain6 localhost6

save and exit

nano /etc/sysconfig/network

make the file look like this

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=oracle.sourav


save and exit

i am using dhcp so my network card file should look like this

 nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

NM_CONTROLLED=no

PEERDNS=no

DNS1=8.8.8.8

DNS2=4.2.2.2


save and exit

to set the dns

  nano /etc/resolv.conf

# Generatedby NetworkManager
search google.com
nameserver 8.8.8.8
nameserver 4.2.2.2


save and exit

to stop the NetworkManager

 service NetworkMnager stop

to make sure NetworkManager won't start at the next reboot

 chkconfig NetworkManager off


to restart the network

/etc/rc.d/init.d/network restart 

 chkconfig network on 


let's reboot and let's see if everything going just fine

ok everything is fine

one more thing 

let us disable ipv6 as it is not needed here

 echo "install ipv6 /bin/true" > /etc/modprobe.d/disable-

ipv6.conf

ok everything is set 

now let's try to install oracle's dependencies 

yum -y install binutils compat-libstdc++-33 elfutils-libelf 

elfutils-libelf-devel glibc glibc-common glibc-devel gcc 

gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel 

make sysstat unixODBC unixODBC-devel 

after installing now let's set some kernel parameters

nano /etc/sysctl.conf 

comment out those three lines

#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0


and also comment out 

#kernel.shmmax = 4294967295


and



#kernel.shmall = 268435456


at the end add this section

net.ipv4.ip_local_port_range = 9000 65500
fs.file-max =65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=1048576 



save and exit

using the sysctl -p check out the output

it should be like

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576


ok now let's create an user for oracle

groupadd -g 200 oinstall 

groupadd -g 201 dba 

useradd -u 440 -g oinstall -G dba -d /usr/oracle oracle 

passwd oracle

set the password

nano /etc/pam.d/login


add this line

session   required   pam_limits.so

before the line

session    optional     pam_keyinit.so force revoke

save and exit

nano /etc/security/limits.conf 

add these lines at the end


before # End of file

oracle   soft   nproc   2047
oracle   hard   nproc   16384
oracle   soft   nofile   1024
oracle   hard   nofile   65536


save and exit

nano /etc/profile

at the end add these lines

if [ $USER = "oracle" ]; then
       if [ $SHELL = "/bin/ksh" ]; then
            ulimit -p 16384
            ulimit -n 65536
       else
            ulimit -u 16384 -n 65536
       fi
 fi


save and exit

now switch to the user oracle

su oracle

cd ~

chmod 755 /usr/oracle 


mkdir /usr/oracle/app 


chmod 775 /usr/oracle/app 

mkdir /usr/oracle/oradata 

chmod 775 /usr/oracle/oradata

nano ~/.bash_profile 

at the end add these lines

umask 022
export ORACLE_BASE=/usr/oracle/app

save and exit

mkdir tmp

using winscp copy the oracle 11g installation files in the 

target machine

ok before trying to install oracle as root you need

to execute the command xhost + in the target machine

 unzip linux_11gR2_database_1of2.zip

 unzip linux_11gR2_database_2of2.zip

Now to avoid pdksh error

go to

/usr/oracle/tmp/database/stage/cvu/cv/admin

Edit cvu_config and change the following line 

CV_ASSUME_DISTID=OEL4 to CV_ASSUME_DISTID=OEL6

save and exit

source://https://unix.stackexchange.com/questions/29554/pdksh

-missing-from-rhel-6-and-centos-6


now

./database/runInstaller  as oracle

you will be presented with an error 

environment does not meet minimum requirements error

probably a bug but i still tried installing java and some 

more

steps but the same error shows up,so i ignored it and

went on

abiding by the default settings 

now when asked 

run this script 
/usr/oracle/oraInventory/orainstRoot.sh 
as root

and 

 /usr/oracle/app/product/11.2.0/dbhome_1/root.sh 

as root

and press enter for defaults

after it's done press ok

the installation should complete successfully
nano ~/.bash_profile 

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
 export PATH=$PATH:$ORACLE_HOME/bin



source ~/.bash_profile 

rm -rf tmp 


source:https://www.server-world.info/en/note?os=Scientific_Linux_6&p=oracle11g&f=2