abc
#include <iostream.h>
class emp
{
private:
char ID[5];
char name[50];
emp *next;
emp *prev;
public:
friend class empnode;
void accept()
{
cout<<"Enter ID\n";
cin>>ID;
cin.ignore();
cout<<"Enter Name\n";
cin.getline(name,50);
}
void disp()
{
cout<<"ID\t"<<ID
<<"Name\t"<<name<<endl;
}
};
class empnode
{
emp *start;
public:
empnode()
{
start=NULL;
}
void addnode()
{
emp *fresh;
fresh=new emp();
fresh->accept();
fresh->next=start;
start=fresh;
}
void dispnode()
{
for(emp *t=start;t!=NULL;t=t->next)
t->disp();
}
};
void menu()
{
cout<<"\t\tMain Menu\n"
<<"\t1. Add Node\n"
<<"\t2. Display Node\n"<<endl;
cout<<"choice";
}
void main()
{
empnode o;
int ch;
for(;;){
menu();
cin>>ch;
if(ch==1)
o.addnode();
if(ch==2)
o.dispnode();
if(ch<1 || ch>2)
break;
}
}
#include <stdio.h>
struct emp
{
char name[10];
struct contactadd
{
char ph[10];
char email[10];
};
contactadd x;
};
emp var;
void accept()
{
printf("Enter Name of customer\n");
scanf("%s",var.name);
printf("Enter Phone number\n");
scanf("%s",var.x.ph);
printf("Enter Email\n");
scanf("%s",var.x.email);
}
void display()
{
printf("Name:\t%s",var.name);
printf("Phone:\t%s",var.x.ph);
printf("Email:\t%s",var.x.email);
}
void main()
{
accept();
display();
}
//1 static binding- function overloading
//2. dynamic binding- parent pointer to child class
// dynamic binding or dynamic polymorphism
#include <iostream.h>
class emp
{
char ID[10];
public:
virtual void accept() // virtual functions to make the parent silent
when called
{
cout<<"Enter ID";
cin>>ID;
}
virtual void display()
{
cout<<"ID:\t"<<ID<<endl;
}
};
class Grade1:public emp
{
char OFFICERID[10];
public:
void accept()
{
emp::accept();
cout<<"\nEnter Officer ID";
cin>>OFFICERID;
}
void display()
{
emp::display();
cout<<"OFFICERID:\t"<<OFFICERID<<endl;
}
};
void main()
{
emp *p; // base class pointer
Grade1 obj;
p=&obj; // parent pointer can hold childs address
p->accept(); // calling childs function
p->display();
}
#include <iostream.h>
class student
{
char roll[3];
char name[50];
public:
student();
virtual void accept();
virtual void display();
};
student::student()
{
roll[0]='\0';
name[0]='\0';
}
void student::accept()
{
cout<<"Enter ROll No\t"; cin>>roll; cin.ignore();
cout<<"Enter Name\t"; cin.getline(name,50);
}
void student::display()
{
cout<<"\nROLL\t\tName\t\tAddress\n";
cout<<"\n----\t\t------------\t\t-----------\n";
cout<<roll<<"\t\t"<<name<<"\t\t";
}
class res:public student
{
char Resadd[100];
public:
res();
void accept();
void display();
};
res::res()
{
Resadd[0]='\0';
}
void res::accept()
{
student::accept();
cout<<"\nEnter Residential Address\t";
cin.getline(Resadd,100);
}
void res::display()
{
student::display();
cout<<Resadd<<endl;
}
class nres:public student
{
char Hos[100];
public:
nres();
void accept();
void display();
};
nres::nres()
{
Hos[0]='\0';
}
void nres::accept()
{
student::accept();
cout<<"\nEnter Hostel Address\t";
cin.getline(Hos,100);
}
void nres::display()
{
student::display();
cout<<Hos<<endl;
}
void menu()
{
cout<<"\n\t\tMain Menu\n"
<<"\t1. Residential\n"
<<"\t2. Non Residential\n";
}
void submenu()
{
cout<<"\n\n\t\tSub Menu\n"
<<"\t1. Accept Details\n"
<<"\t2. Display Details\n";
}
void main()
{
char ch;
student *p;
do
{
menu();
cout<<"\n\t\t\t\tMain Choice:"; cin>>ch;
switch (ch)
{
case '1':
char ch1;
p=new res();
do
{
submenu();
cout<<"\n\t\t\t\tChoice:"; cin>>ch1;
switch (ch1)
{
case '1':
p->accept();
break;
case '2':
p->display();
break;
}
}while (ch1=='1' || ch1=='2');
break;
case '2':
char ch2;
p=new nres();
do
{
submenu();
cout<<"\n\t\t\t\tChoice:"; cin>>ch2;
switch (ch2)
{
case '1':
p->accept();
break;
case '2':
p->display();
break;
}
}while (ch2=='1' || ch2=='2');
break;
}
}while(ch == '1' || ch=='2');
}
#include <iostream.h>
// friend: private: nobody can access
// a private data can be shared
// friend class,friend function
class emp
{
int empage;
char name[10];
public:
void accept()
{
cin>>name>>empage;
}
void display()
{
cout<<name<<empage;
}
friend class elgiblity_for_prom;
};
class elgiblity_for_prom
{
int exp;
emp o;
public:
void accept()
{
o.accept();
exp=o.empage+10;
}
void display()
{
o.display();
if(exp>40)
cout<<"Eligible";
else
cerr<<"Not Eligible";
}
};
void main()
{
elgiblity_for_prom obj;
obj.accept();
obj.display();
}
#include <iostream.h>
class emp
{
int age;
public:
emp()
{
cout<<"Hi Me is Called";
age=21;
}
void disp() { cout<<age; }
};
void main()
{
emp obj;
emp obj1=obj;
obj1.disp();
}
// + - *
// emp o,o1,o2; o2=o+o1;
#include <iostream.h>
class sal
{
int basic;
public:
sal()
{
basic=0;
}
sal(int s)
{
basic=s;
}
sal operator +(sal x) // copy constructor
{
sal tmp;
tmp.basic=basic+x.basic;
return tmp;
}
sal operator -(sal x) // copy constructor
{
sal tmp;
tmp.basic=basic-x.basic;
return tmp;
}
void disp()
{
cout<<basic;
}
};
void main()
{
sal obj(300),obj1(100),obj4(2);
sal obj3=obj+obj1-obj4; //sal x=obj1
obj3.disp();
}
// Write a program to over load - operator
#include <iostream.h>
#include <string.h>
class string
{
char *x;
public:
string(char y[]='\0')
{
cout<<"constu";
if (y[0]=='\0')
x[0]='\0';
x=new char[strlen(y)+1];
strcpy(x,y);
}
};
void main()
{
string o;
}
// int x; x=9; cout<<x
// Files: variable ( dealing with memory)
// reading from (input ) and writing to(output) HD
// files are stored locations in permanent area
// how to create a file using c++
// how to store the data into files using c++ (output to HD)
// how to read the file from the HD (input from HD)
//
#include <fstream.h>
void main()
{
char name[100];
fstream cfout("bio.txt",ios::out|ios::app);
cout<<"Enter Full Name";
cin.getline(name,100);
cfout<<"\t\t\t\tRESUME\n\n";
cfout<<"NAME\t\t\t:"<<name<<endl;
cout<<"Enter Phone Number";
cin>>name;
cfout<<"PHONE\t\t\t:"<<name<<endl;
cout<<"Enter email address";
cin>>name;
cfout<<"EMAIL\t\t\t:"<<name<<endl;
cout<<"Enter date of birth";
cin>>name;
cin.ignore();
cfout<<"DATE OF BIRTH\t\t:"<<name<<endl;
cout<<"Enter your Qualification";
cin.getline(name,100);
cfout<<"QUALIFICATION\t\t:"<<name<<endl;
while(1){
cout<<"Enter your experience";
cin.getline(name,100);
cfout<<"\nEXPERIENCE\t\t\t:"<<name<<endl;
cout<<"Want to put one mor exp\n";
char ch;
cin>>ch;
cin.ignore();
if(ch!='y')
break;
}
cfout.close();
}
#include <fstream.h>
class emp
{
char name[10];
char qualification[10];
public:
void accept()
{
cout<<"Enter ur name:";
cin.getline(name,10);
cout<<"Enter ur qualification:";
cin.getline(qualification,10);
}
void display()
{
cout<<name;
cout<<qualification;
}
};
class empstore
{
emp obj;
public:
void accept()
{
fstream cfout("emp.txt",ios::out|ios::app);
obj.accept();
cfout.write((char*)&obj,sizeof(obj));
cfout.close();
}
void display()
{
fstream cfin("emp.txt",ios::in);
cfin.read((char*)&obj,sizeof(obj));
obj.display();
cfin.close();
}
};
void main()
{
empstore obj;
obj.accept();
obj.display();
}#include<fstream.h>
class student
{
char name[10];
short int age;
public:
void accept()
{
cout<<"Enter ur name:";
cin>>name;
cout<<"Enter ur age:";
cin>>age;
}
void display()
{
cout<<name<<age;
}
};
class studentstore
{
student obj;
public:
void accept()
{
ofstream cfout("student.txt",ios::out|ios::app);
obj.accept();
cfout.write((char*)&obj,sizeof(obj));
cfout.close();
}
void display()
{
int clt=0;
ifstream cfin("student.txt",ios::in);
cfin.read((char*)&obj,sizeof(obj));
while(!cfin.eof())
{
//..........................
obj.display();
cfin.read((char*)&obj,sizeof(obj));
cltclt+tot;
}
cfin.close();
}
};
void main()
{
studentstore obj;
obj.accept();
obj.display();
}
#include <iostream.h>
class emp
{
private:
char name[10];
char ph[10];
char email[10];
public:
void accept()
{
cout<<"Enter name\n";
cin>>name;
cout<<"Enter phone\n";
cin>>ph;
cout<<"Enter email\n";
cin>>email;
}
void display()
{
cout<<"\n\tName\t\tPhone\t\tEmail\n";
cout<<"\t"<<name<<"\t\t"<<ph<<"\t\t"<<email;
}
};
void main()
{
// pointer to object
emp x;
emp *ptr;
ptr=&x;
ptr->accept(); // -> arrow operator used to access members of a class
using pointer
ptr->display();
}
#include<fstream.h>
#include <string.h>
class reportcard
{
char name[20];
char sub[9][20];
int marks[9];
public:
friend class reportcardstore;
void accept()
{
cout<<"Enter student's name:";
cin.getline(name,20);
for(int i=0;i<9;i++)
{
cout<<"Enter subject name:";
cin>>sub[i];
cout<<"Enter ur marks in the subject:";
cin>>marks[i];
}
}
void change(int i)
{
int tmp;
cout<<"\nsubject Name\t"<<sub[i]
<<"marks\t"<<marks[i]<<endl;
cout<<"\nEnter New marks";
cin>>tmp;
marks[i]=tmp;
}
void display()
{
cout<<"Name\t"<<name<<endl;
for(int i=0;i<9;i++)
{
cout<<"subject name: "<<i+1<<"\t"<<sub[i];
cout<<"subject marks:"<<i+1<<"\t"<<marks[i]<<endl;
}
}
};
class reportcardstore
{
reportcard obj;
public:
void accept()
{
ofstream cfout("reportcard.txt",ios::out|ios::app);
obj.accept();
cfout.write((char*)&obj,sizeof(obj));
cfout.close();
}
void display()
{
int i,n=0;
int sum=0;
int avg;
int clt=0,cla;
ifstream cfin("reportcard.txt",ios::in);
cfin.read((char*)&obj,sizeof(obj));
while(cfin)
{
n++;
for(i=0;i<9;i++)
sum=sum+obj.marks[i];
avg=sum/i;
obj.display();
cout<<"\nTotal Marks: "<<sum
<<"\nAverage: "<<avg<<endl;
clt=clt+sum;
cfin.read((char*)&obj,sizeof(obj));
sum=0;
}
cla=clt/n;
cout<<"\nClass Total: "<<clt
<<"\nClass Average: "<<cla<<endl;
cfin.close();
}
void reportfind()
{
char tmp[20];
cout<<"Enter Name of student whose marks want to display\t";
cin.getline(tmp,20);
ifstream cfin("reportcard.txt",ios::in);
cfin.read((char*)&obj,sizeof(obj));
while(cfin)
{
if(strcmp(tmp,obj.name)==0)
{
obj.display();
}
cfin.read((char*)&obj,sizeof(obj));
}
cfin.close();
}
void modifymarks()
{
char tmp[20];
cout<<"Enter Name of student whose marks want to modify\t";
cin.getline(tmp,20);
fstream cfin("reportcard.txt",ios::out|ios::in);
cfin.read((char*)&obj,sizeof(obj));
while(!cfin.eof())
{
if(strcmp(tmp,obj.name)==0)
{
int subcode;
obj.display();
cout<<"\nEnter new marks for the subcode\n";
cin>>subcode;
obj.change(subcode-1);
int pos=cfin.tellg();
int size=sizeof(obj);
pos=pos-size;
cfin.seekp(pos,ios::beg);
cfin.write((char*)&obj,sizeof(obj));
}
cfin.read((char*)&obj,sizeof(obj));
}
cfin.close();
}
};
void menu()
{
cout<<"Main Menu\t"
<<"\n\t\t1. Add marks"
<<"\n\t\t2. Display marks"
<<"\n\t\t3. Find marks"
<<"\n\t\t4. Modify marks"<<endl;
cout<<"Enter Choice";
}
void main()
{
reportcardstore obj;
char ch;
do
{
menu();
cin>>ch;
cin.ignore();
if(ch=='1') obj.accept ();
if(ch=='2') obj.display ();
if(ch=='3') obj.reportfind();
if(ch=='4') obj.modifymarks();
}while(ch=='1' || ch=='2' || ch=='3' || ch=='4');
}
// exception handling
// Error and Exception
// try throw catch
// try is a block
// throw is a statement
// catch is a function
//
//ex:
#include <iostream.h>
void main()
{
try
{
int i,j;
cin>>i>>j;
if(j==0) throw "Error in denominator";
cout<<i/j;
}
catch(char *er)
{
cerr<<er;
}
}
// templates
// write a program in c++ to accept two variables x and y and sum them show
their average
#include<iostream.h>
class f3
{
int x,y,sum;
public:
void accept()
{
cout<<"Enter 2 nos.";
cin>>x;
cin>>y;
}
void display()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}
void s()
{
sum=x+y;
}
void average()
{
cout<<"the average is="<<sum/2;
}
};
void main()
{
f3 obj;
obj.accept(); // binding
obj.s();
obj.display();
obj.average();
}// write a program for an inn
// cost of AC room is 1500 per night
// cost of Delux is 1400 per night
// cost of Non AC is 900 per night
// you to accept the number of persons, name of one person, no of rooms required
and generate bill
#include <iostream.h>
class inn
{
int x; char name[10]; int y,bill,type,n;
public:
void accept()
{
cout<<"Enter the no. of persons:\t";
cin>>x;
cout<<"Enter the name of person:\t";
cin>>name;
cout<<"Enter the no. of rooms reqd:\t";
cin>>y;
cout<<"Enter the no. of days of stay:\t";
cin>>n;
cout<<"Enter the type of room reqd:\n1.ac room\n2.delux room\n3.non ac
room\n\t";
cin>>type;
}
void b()
{
if(type==1)
{
bill=y*n*1500;
}
if(type==2)
{
bill=y*n*1400;
}
if(type==3)
{
bill=y*n*900;
}}
void display()
{
cout<<"\n\n\n\t\t\tBILL";
cout<<"\nName of person:"<<name;
cout<<"\nNo. of rooms reqd.\t\tNo. of days to be spent\n";
cout<<"\n"<<y<<"\t\t\t\t"<<n<<"\n";
cout<<"total="<<bill<<endl;
}
};
void main()
{
inn obj;
obj.accept();
obj.b();
obj.display();
}
#include <iostream.h>
// inheritance:
class Inn
{
protected:
char name[50]; //raj malhotra
int no_of_per;
int no_of_days;
public:
void accept()
{
cout<<"\nEnter Name of person\t";
cin.getline(name,50);
cout<<"\nEnter Number of Persons\t";
cin>>no_of_per;
cout<<"\nEnter Number of Days\t";
cin>>no_of_days;
}
void display()
{
cout<<"Name of Person\t\tNo of Persons\t\tNo of Days\n";
cout<<name<<"\t\t\t"<<no_of_per<<"\t\t\t"<<no_of_days<<endl;
}
};
class ACInn:public Inn
{
int cost_of_room;
double TAX;
int rooms;
public:
void accept() // function overrrinding
{
Inn::accept(); // calling base class function from child
int ch;
cout<<"Enter number of beds required\n\t"
<<"1. 2 Bed Room\n\t2. 4 Bed Room\n\t3. Single Bed Room\n";
cin>>ch;
if(ch==1)
cost_of_room=1200;
if(ch==2)
cost_of_room=2400;
if(ch==3)
cost_of_room=600;
cout<<"Enter Number of Rooms Required\n";
cin>>rooms;
TAX=(no_of_days*rooms*cost_of_room)*.05;
}
int bill()
{
return cost_of_room*no_of_days*rooms;
}
void display()
{
Inn::display();
cout<<"\nRooms Demanded\t:"<<rooms<<endl;
cout<<"\n Room Opted:";
if(cost_of_room==1200)
cout<<"\n\t\t2 Bed Room AC Inn\t-\t"
<<cost_of_room;
if(cost_of_room==600)
cout<<"\n\t\tSingle Bed Room AC Inn\t-\t"
<<cost_of_room;
if(cost_of_room==2400)
cout<<"\n\t\t4 Bed Room AC Inn\t-\t"
<<cost_of_room;
cout<<"\nTotal Bill is \t\t\t\t:"<<bill()
<<"\nTAX\t\t\t\t\t:"<<TAX
<<"\nTotal\t\t\t\t\t:"<<bill()+TAX<<"\n\t\t\t\t\t"
<<"Thank You\n\t\t\t\t\tVisit Again\n";
}
};
void main()
{
ACInn obj;
obj.accept();
obj.display();
}
// virtual class is used to remove the ambiguity
// ambiguity means same variable from different parents
# include <iostream.h>
class base
{
protected:
int x;
};
class c1:virtual public base
{
protected:
int c1x;
};
class c2:virtual public base
{
protected:
int c2x;
};
class c3:public c1,c2
{
public:
int c3x;
public:
void display()
{
cout<<x;
}
};
void main()
{
c3 obj;
obj.display();
}
// problem is called ambiguity
// enhance the code given in f5 by including DeluxInn and NONACInn
// DeluXInn has 2 bed rooms ( 2000 ) with option AC included ( No Ac 600)
// Other Facilities opted by user ( Extra TV,DVD, Direct Meals etc) TAX .05
// NONAC has 2 bed,4 bed only with NO Tax.// overloading: same function name
with different signatures
// signature means parameters of the function with no of arguments,type of
arguments,arrangement of arguments
// void accept(int x)
// constructors
// destructors
#include <iostream.h>
class sample
{
int x,y;
public:
// constructor is a function with no return type,
//having the name as that of class name
// constructor is used for initialization or to show a initial message
// constructor can also be overloaded
sample() // default constructor
{
x=y=0;
}
sample(int x) // one argument constructor
{
this->x=x;
}
sample(int x,int y)
{
this->x=x;
this->y=y;
}
void accept()
{
cin>>x>>y;
}
// function with default arguments
void accept(int x=10,int y=10)
{
this->x=x;
this->y=y;
}
void disp()
{
cout<<x<<y;
}
};
void main()
{
sample obj; // constructor is called when object is created ( implictly
called)
int a;
cin>>a;
obj.accept(a);
obj.disp();
}
#include <iostream.h>
class sample
{
int x,y;
public:
sample(int x=10,int y=10)
{
this->x=x;
this->y=y;
cout<<x<<y<<"\nconstructor is called";
}
~sample()
{
x=y=0;
cout<<"\ndestructor is called";
}
};
void main()
{
sample obj;
cout<<"\nprogram working";
}
// what is destructor
// destructor is also same as that of constructor but preceded by ~ symbol
// destructos is used for deinitialization
// is called at the end of program
// is not possible to overload#include <iostream.h>
class gbase
{
public:
gbase()
{
cout<<"\ngbase";
}
~gbase()
{
cout<<"\nGBASE";
}
};
class base1:public gbase
{
public:
base1()
{
cout<<"\nbase1";
}
~base1()
{
cout<<"\nBASE1";
}
};
class base2
{
public:
base2()
{
cout<<"\nbase2";
}
~base2()
{
cout<<"\nBASE2";
}
};
class guest
{
public:
guest()
{
cout<<"\nguest";
}
~guest()
{
cout<<"\nGUEST";
}
};
class child:public base1, base2
{
guest o;
public:
child()
{
cout<<"\nchild";
}
~child()
{
cout<<"\nCHILD";
}
};
class grandchild:public child
{
public:
gandchild()
{
cout<<"\ngrandchild";
}
~grandchild()
{
cout<<"\nGRANDCHILD";
}
};
void main()
{
grandchild obj;
}// sequence of constructor
// first parent
//second guest object
//third own object
// destructor is fallowed reverse to constructor sequence
#include <iostream.h>
class base
{
public:
base()
{
cout<<"\nbase";
}
~base()
{
cout<<"\nBASE";
}
};
class base1
{
public:
base1()
{
cout<<"\nbase1";
}
~base1()
{
cout<<"\nBASE1";
}
};
class guest
{
public:
guest()
{
cout<<"\nguest";
}
~guest()
{
cout<<"\nGUEST";
}
};
class child:public base,base1
{
guest obj;
public:
child()
{
cout<<"\nchild";
}
~child()
{
cout<<"\nCHILD";
}
};
void main()
{
child obj;
}
// write a program to check the given tree using constructos ,destructors that
also with arguments
// simple single linked list program
#include <iostream.h>
class emp
{
private:
char ID[5];
char name[50];
emp *next;
public:
friend class empnode;
void accept()
{
cout<<"Enter ID\n";
cin>>ID;
cin.ignore();
cout<<"Enter Name\n";
cin.getline(name,50);
}
void disp()
{
cout<<"ID\t"<<ID
<<"Name\t"<<name<<endl;
}
};
class empnode
{
emp *start;
public:
empnode()
{
start=NULL;
}
void addnode()
{
emp *fresh;
fresh=new emp();
fresh->accept();
fresh->next=start;
start=fresh;
}
void dispnode()
{
for(emp *t=start;t!=NULL;t=t->next)
t->disp();
}
};
void menu()
{
cout<<"\t\tMain Menu\n"
<<"\t1. Add Node\n"
<<"\t2. Display Node\n"<<endl;
cout<<"choice";
}
void main()
{
empnode o;
int ch;
for(;;){
menu();
cin>>ch;
if(ch==1)
o.addnode();
if(ch==2)
o.dispnode();
if(ch<1 || ch>2)
break;
}
}
#include <iostream.h>
namespace IT
{
class emp
{
public:
char ID[4];
};
class soft
{
public:
char nam[10];
};
};
void main()
{
IT::emp obj;
cin>>obj.ID;
}
#include <iostream.h>
#include <stdlib.h>
struct Q
{
int arr[10];
int start;
int end;
};
Q obj;
void init()
{
obj.start=obj.end=0;
}
void push(int x)
{
if(obj.end==10)
{
cout<<"Q is full";
exit(0);
}
obj.arr[obj.end]=x;
obj.end++;
cout<<obj.end;
}
int pop()
{
if((obj.start==0 && obj.end==0 )|| (obj.start>=obj.end))
{
cout<<"Q is MT";
init();
return -1;
}
cout<<obj.start;
int temp= obj.arr[obj.start];
obj.start++;
return temp;
}
void menu()
{
cout<<"\n\t1. push"
<<"\n\t2. pop"
<<"choice ";
}
void main()
{
int ch;
init();
for(;;)
{
menu();
cin>>ch;
if(ch==1)
{
int val;
cout<<"Enter a value"; cin>>val;
push(val);
}
if(ch==2)
cout<<pop();
if(ch<1 || ch>2)
break;
}
}
#include <iostream.h>
void main()
{
int x[]={4,5,60,7,8};
int *p=x;
*(p+4)=*p**p;
cout<<*p; // 4
cout<<*(p+4); // 16
p+=2;
*p-=59;
cout<<*p; // 1
cout<<p; // address of 1
int *p1=p;
cout<<endl<<*p1; // 1
int sum=0;
for(p1=&x[0];p1<=&x[4];p1++)
*p1=*p1+*p1;
cout<<endl<<"the final value is "<<*p1; // error output
}#include <iostream.h>
#include <string.h>
class emp
{
public:
class beings
{
public:
char name[100];
};
char name[10];
emp *ptr;
emp(char *str)
{
strcpy(name,str);
}
void disp()
{
cout<<name;
}
};
emp obj("OM"),obj1("JESUS");
void main()
{
obj.ptr=&obj1;
obj1.ptr=&obj;
obj.disp();
obj.ptr->disp();
obj1.ptr->disp ();
}
/*
linked list with (desc ) sorted insertion
node with value 21 which is 1st node
so is added with start
a node with value is added after the first node so it is second node
there are two chances
1. value of thenode is > the already available nodes
2. value of the fresh node is < the already available nodes
if it is the first option then node goes to the begining
if it is the second option then node is again of two chances
1. somewhere in the middle
2. at the last
the total logic is divided into 3 parts
1. node at the beginging
2. node at the middle
3. node at the end
logic for begining node.
1. if the node is first one
2. node is greater than all the existing nodes
logic for middle nodes
1. the node is less than the first one but greater than the remaining one of
the list
logic for the last node
1. the node is smallest of all available in list
*/
#include <iostream.h>
class emp
{
public:
int age;
emp *next;
void accept()
{
cout<<"Enter age of the person\t"; cin>>age;
}
void disp()
{
cout<<"Age\t"<<age;
}
};
class empnode
{
emp *f;
public:
empnode()
{
f=NULL;
}
void addnode()
{
emp *fresh;
fresh=new emp();
fresh->accept();
//logic for beinging node
if(f==NULL || fresh->age>f->age)
{ fresh->next=f;
f=fresh;
}
else
{
for(emp *t=f,*p;t!=NULL && (t->age > fresh->age) ;p=t,t=t-
>next){}
if(t!=NULL)
{
fresh->next=p->next;
p->next=fresh;
}
else
{
fresh->next=NULL;
p->next=fresh;
}
}
}
void disp()
{
for(emp *t=f;t!=NULL;t=t->next)
t->disp();
}
};
void menu()
{
cout<<"\t\tMain Menu\n"
<<"\t1. Add Node\n"
<<"\t2. Display Node\n"<<endl;
cout<<"choice";
}
void main()
{
empnode o;
int ch;
for(;;){
menu();
cin>>ch;
if(ch==1)
o.addnode();
if(ch==2)
o.disp();
if(ch<1 || ch>2)
break;
}
}
// Data structures
#include <iostream.h>
#include <stdlib.h>
struct stack
{
int arr[10];
int top;
};
stack obj;
void init()
{
obj.top=0;
}
void push(int x)
{
if(obj.top==10)
{
cout<<"Stack is full";
exit(0);
}
obj.arr[obj.top]=x;
obj.top++;
}
int pop()
{
if(obj.top==0)
{
cout<<"Stack is MT";
return -1;
}
obj.top--;
return obj.arr[obj.top];
}
void menu()
{
cout<<"\n\t1. push"
<<"\n\t2. pop"
<<"choice ";
}
void main()
{
int ch;
init();
for(;;)
{
menu();
cin>>ch;
if(ch==1)
{
int val;
cout<<"Enter a value"; cin>>val;
push(val);
}
if(ch==2)
cout<<pop();
if(ch<1 || ch>2)
break;
}
}
__________________________Wish U best of Luck _________________________________
Remember we will concentrate mainly on practicals reading which if u practice, will be able to understand yourself how it works
Friday, October 22, 2010
Oracle Fundamentals - 2
SQL> select table_name from user_constraints a where r_constraint_name in (select constraint_name from user_constraints b where b.table_name='ITEMS');
TABLE_NAME
------------------------------
SALES
SQL> drop table sales;
Table dropped.
SQL> drop table items;
Table dropped.
SQL> create table items (itemid number(4) primary key, item_name varchar2(20) not null,cost number(4,2),qty number );
Table created.
SQL> create table customer (cid number(3) primary key,cust_name varchar2(20) not null, cust_addr varchar2(25));
Table created.
SQL> create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,qty number(4) constraint qty_chk (check qty>0),t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null);
create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,qty number(4) constraint qty_chk (check qty>0),t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
*
ERROR at line 1:
ORA-02253: constraint specification not allowed here
SQL> ed
Wrote file afiedt.buf
1 create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,
2 cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,
3 qty number(4) constraint qty_chk (check qty>0),
4* t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
SQL> /
qty number(4) constraint qty_chk (check qty>0),
*
ERROR at line 3:
ORA-02253: constraint specification not allowed here
SQL> ed
Wrote file afiedt.buf
1 create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,
2 cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,
3 qty number(4) constraint qty_chk check (qty>0),
4* t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
SQL> /
Table created.
SQL> desc sales;
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> desc user_indexes;
Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME NOT NULL VARCHAR2(30)
INDEX_TYPE VARCHAR2(27)
TABLE_OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
TABLE_TYPE VARCHAR2(11)
UNIQUENESS VARCHAR2(9)
COMPRESSION VARCHAR2(8)
PREFIX_LENGTH NUMBER
TABLESPACE_NAME VARCHAR2(30)
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
PCT_THRESHOLD NUMBER
INCLUDE_COLUMN NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
PCT_FREE NUMBER
LOGGING VARCHAR2(3)
BLEVEL NUMBER
LEAF_BLOCKS NUMBER
DISTINCT_KEYS NUMBER
AVG_LEAF_BLOCKS_PER_KEY NUMBER
AVG_DATA_BLOCKS_PER_KEY NUMBER
CLUSTERING_FACTOR NUMBER
STATUS VARCHAR2(8)
NUM_ROWS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
DEGREE VARCHAR2(40)
INSTANCES VARCHAR2(40)
PARTITIONED VARCHAR2(3)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
BUFFER_POOL VARCHAR2(7)
USER_STATS VARCHAR2(3)
DURATION VARCHAR2(15)
PCT_DIRECT_ACCESS NUMBER
ITYP_OWNER VARCHAR2(30)
ITYP_NAME VARCHAR2(30)
PARAMETERS VARCHAR2(1000)
GLOBAL_STATS VARCHAR2(3)
DOMIDX_STATUS VARCHAR2(12)
DOMIDX_OPSTATUS VARCHAR2(6)
FUNCIDX_STATUS VARCHAR2(8)
JOIN_INDEX VARCHAR2(3)
IOT_REDUNDANT_PKEY_ELIM VARCHAR2(3)
DROPPED VARCHAR2(3)
SQL> select index_name,index_type from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
SYS_C005457 NORMAL
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME
------------------------------
SYS_C005457 NORMAL
SQL> select index_name,index_type,degree from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
DEGREE
----------------------------------------
SYS_C005457 NORMAL
1
SQL> select index_name,index_type,degree,num_rows from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
DEGREE NUM_ROWS
---------------------------------------- ----------
SYS_C005457 NORMAL
1
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='CUSTOMER';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME
------------------------------
SYS_C005459 NORMAL
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SYS_C005457 NORMAL
UNIQUE
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> create index sales_itemidx on sales(Item_ID);
create index sales_itemidx on sales(Item_ID)
*
ERROR at line 1:
ORA-00904: "ITEM_ID": invalid identifier
SQL> create index sales_itemidx on sales(ItemID);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SALES_ITEMIDX NORMAL
NONUNIQUE
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> create unique index cust_nameidx on customer(cust_name);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='CUSTOMER';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SYS_C005459 NORMAL
UNIQUE
CUST_NAMEIDX NORMAL
UNIQUE
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> create index qty_costidx on (T_type,qty);
create index qty_costidx on (T_type,qty)
*
ERROR at line 1:
ORA-00903: invalid table name
SQL> create index qty_costidx on sales(T_type,qty);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SALES_ITEMIDX NORMAL
NONUNIQUE
QTY_COSTIDX NORMAL
NONUNIQUE
SQL> desc user_indx_cols
ERROR:
ORA-04043: object user_indx_cols does not exist
SQL> desc user_index_cols
ERROR:
ORA-04043: object user_index_cols does not exist
SQL> desc user_col_index
ERROR:
ORA-04043: object user_col_index does not exist
SQL> select tname from tab where tname like '%COLS%';
no rows selected
SQL> conn / as sysdba
Connected.
SQL> select tname from tab where tname like '%COLS%';
TNAME
------------------------------
ALL_NESTED_TABLE_COLS
ALL_SEC_RELEVANT_COLS
ALL_TAB_COLS
ALL_TRIGGER_COLS
ALL_XML_TAB_COLS
ALL_XML_VIEW_COLS
DBA_MVIEW_LOG_FILTER_COLS
DBA_NESTED_TABLE_COLS
DBA_SEC_RELEVANT_COLS
DBA_TAB_COLS
DBA_TRIGGER_COLS
TNAME
------------------------------
DBA_XML_TAB_COLS
DBA_XML_VIEW_COLS
EXU9TAB_UNUSED_COLS
KU$_FIND_SGC_COLS_VIEW
KU$_FIND_SGI_COLS_VIEW
LOGMNR_INTERESTING_COLS
STREAMS$_DEST_OBJ_COLS
USER_NESTED_TABLE_COLS
USER_SEC_RELEVANT_COLS
USER_TAB_COLS
USER_TRIGGER_COLS
TNAME
------------------------------
USER_XML_TAB_COLS
USER_XML_VIEW_COLS
24 rows selected.
SQL> select tname from tab where tname like '%ind%';
TNAME
------------------------------
_utl$_gnp_ind
_utl$_gp_ind_parts
_utl$_lc_ind_subs
_utl$_lnc_ind_parts
SQL> select tname from tab where tname like 'IND%';
TNAME
------------------------------
IND$
INDARRAYTYPE$
INDCOMPART$
INDCOMPARTV$
INDEX_HISTOGRAM
INDEX_STATS
INDOP$
INDPART$
INDPARTV$
INDPART_PARAM$
INDSUBPART$
TNAME
------------------------------
INDSUBPARTV$
INDTYPES$
IND_ONLINE$
IND_STATS$
15 rows selected.
SQL> select tname from tab where tname like '%IND%';
TNAME
------------------------------
ALL_INDEXES
ALL_INDEXTYPES
ALL_INDEXTYPE_ARRAYTYPES
ALL_INDEXTYPE_COMMENTS
ALL_INDEXTYPE_OPERATORS
ALL_IND_COLUMNS
ALL_IND_EXPRESSIONS
ALL_IND_PARTITIONS
ALL_IND_STATISTICS
ALL_IND_SUBPARTITIONS
ALL_JOIN_IND_COLUMNS
TNAME
------------------------------
ALL_OPBINDINGS
ALL_PART_INDEXES
ALL_SCHEDULER_WINDOWS
ALL_SCHEDULER_WINDOW_DETAILS
ALL_SCHEDULER_WINDOW_GROUPS
ALL_SCHEDULER_WINDOW_LOG
ALL_SQLSET_BINDS
ALL_XML_INDEXES
DBA_ADVISOR_FINDINGS
DBA_HIST_SQLBIND
DBA_HIST_SQL_BIND_METADATA
TNAME
------------------------------
DBA_INDEXES
DBA_INDEXTYPES
DBA_INDEXTYPE_ARRAYTYPES
DBA_INDEXTYPE_COMMENTS
DBA_INDEXTYPE_OPERATORS
DBA_IND_COLUMNS
DBA_IND_EXPRESSIONS
DBA_IND_PARTITIONS
DBA_IND_STATISTICS
DBA_IND_SUBPARTITIONS
DBA_JOIN_IND_COLUMNS
TNAME
------------------------------
DBA_OPBINDINGS
DBA_PART_INDEXES
DBA_SCHEDULER_WINDOWS
DBA_SCHEDULER_WINDOW_DETAILS
DBA_SCHEDULER_WINDOW_GROUPS
DBA_SCHEDULER_WINDOW_LOG
DBA_SQLSET_BINDS
DBA_SQLTUNE_BINDS
DBA_XML_INDEXES
EXU10IND_BASE
EXU81IND
TNAME
------------------------------
EXU81INDC
EXU81INDI
EXU81INDIC
EXU81IND_BASE
EXU8IND
EXU8INDC
EXU8INDI
EXU8INDIC
EXU8INDU
EXU9IND
EXU9INDC
TNAME
------------------------------
EXU9INDI
EXU9INDIC
EXU9IND_BASE
GV_$INDEXED_FIXED_COLUMN
GV_$SQL_BIND_CAPTURE
GV_$SQL_BIND_DATA
GV_$SQL_BIND_METADATA
IND$
INDARRAYTYPE$
INDCOMPART$
INDCOMPARTV$
TNAME
------------------------------
INDEX_HISTOGRAM
INDEX_STATS
INDOP$
INDPART$
INDPARTV$
INDPART_PARAM$
INDSUBPART$
INDSUBPARTV$
INDTYPES$
IND_ONLINE$
IND_STATS$
TNAME
------------------------------
KU$_10_1_IND_STATS_VIEW
KU$_10_1_PIND_STATS_VIEW
KU$_10_1_SPIND_STATS_VIEW
KU$_FIND_HIDDEN_CONS_VIEW
KU$_FIND_SGC_COLS_VIEW
KU$_FIND_SGC_VIEW
KU$_FIND_SGI_COLS_VIEW
KU$_INDARRAYTYPE_VIEW
KU$_INDEXOP_VIEW
KU$_INDEXTYPE_VIEW
KU$_INDEX_COL_VIEW
TNAME
------------------------------
KU$_INDEX_VIEW
KU$_IND_CACHE_STATS_VIEW
KU$_IND_COL_VIEW
KU$_IND_COMPART_VIEW
KU$_IND_PARTOBJ_VIEW
KU$_IND_PART_COL_VIEW
KU$_IND_PART_VIEW
KU$_IND_STATS_VIEW
KU$_IND_SUBPART_COL_VIEW
KU$_IND_SUBPART_VIEW
KU$_IND_TS_VIEW
TNAME
------------------------------
KU$_LOBFRAGINDEX_VIEW
KU$_LOBINDEX_VIEW
KU$_OIDINDEX_VIEW
KU$_OPBINDING_VIEW
KU$_PIND_STATS_VIEW
KU$_SPIND_STATS_VIEW
KU$_SUBLOBFRAGINDEX_VIEW
KU$_TTS_IND_VIEW
LOADER_SKIP_UNUSABLE_INDEXES
LOGMNRG_IND$
LOGMNRG_INDCOMPART$
TNAME
------------------------------
LOGMNRG_INDPART$
LOGMNRG_INDSUBPART$
LOGMNRT_IND$
LOGMNRT_INDCOMPART$
LOGMNRT_INDPART$
LOGMNRT_INDSUBPART$
OPBINDING$
SCHEDULER$_WINDOW
SCHEDULER$_WINDOW_DETAILS
SCHEDULER$_WINDOW_GROUP
USER_ADVISOR_FINDINGS
TNAME
------------------------------
USER_INDEXES
USER_INDEXTYPES
USER_INDEXTYPE_ARRAYTYPES
USER_INDEXTYPE_COMMENTS
USER_INDEXTYPE_OPERATORS
USER_IND_COLUMNS
USER_IND_EXPRESSIONS
USER_IND_PARTITIONS
USER_IND_STATISTICS
USER_IND_SUBPARTITIONS
USER_JOIN_IND_COLUMNS
TNAME
------------------------------
USER_OPBINDINGS
USER_PART_INDEXES
USER_SQLSET_BINDS
USER_SQLTUNE_BINDS
USER_XML_INDEXES
UTL_ALL_IND_COMPS
V_$INDEXED_FIXED_COLUMN
V_$SQL_BIND_CAPTURE
V_$SQL_BIND_DATA
V_$SQL_BIND_METADATA
WRH$_SQL_BIND_METADATA
TNAME
------------------------------
WRI$_ADV_FINDINGS
WRI$_ADV_SQLT_BINDS
WRI$_OPTSTAT_IND_HISTORY
WRI$_SQLSET_BINDS
147 rows selected.
SQL> conn scott/lion
Connected.
SQL> desc user_ind_columns
Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME VARCHAR2(30)
TABLE_NAME VARCHAR2(30)
COLUMN_NAME VARCHAR2(4000)
COLUMN_POSITION NUMBER
COLUMN_LENGTH NUMBER
CHAR_LENGTH NUMBER
DESCEND VARCHAR2(4)
SQL> select index_name,column_name,column_position from user_ind_columns;
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
PK_DEPT
DEPTNO
1
PK_EMP
EMPNO
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SYS_C005400
AID
1
T1PK
EID
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
1
SYS_C005454
ID
1
BIN$u/R7a2iFSquoTbC0j8wH9g==$0
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
ITEM_ID
1
SYS_C005457
ITEMID
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SYS_C005459
CID
1
SALES_ITEMIDX
ITEMID
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
CUST_NAMEIDX
CUST_NAME
1
QTY_COSTIDX
QTY
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
2
QTY_COSTIDX
T_TYPE
1
12 rows selected.
SQL> select index_name,column_name,column_position from user_ind_columns where table_name='SALES';
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SALES_ITEMIDX
ITEMID
1
QTY_COSTIDX
T_TYPE
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
QTY_COSTIDX
QTY
2
SQL> desc items;
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NOT NULL NUMBER(4)
ITEM_NAME NOT NULL VARCHAR2(20)
COST NUMBER(4,2)
QTY NUMBER
SQL> insert into items values(&id,&iname,&cost,&qty);
Enter value for id: 101
Enter value for iname: Lux
Enter value for cost: 15.50
Enter value for qty: 4
old 1: insert into items values(&id,&iname,&cost,&qty)
new 1: insert into items values(101,Lux,15.50,4)
insert into items values(101,Lux,15.50,4)
*
ERROR at line 1:
ORA-00984: column not allowed here
SQL> insert into items values(&id,&iname,&cost,&qty);
Enter value for id:
Enter value for iname:
Enter value for cost:
Enter value for qty:
old 1: insert into items values(&id,&iname,&cost,&qty)
new 1: insert into items values(,,,)
insert into items values(,,,)
*
ERROR at line 1:
ORA-00936: missing expression
SQL>
SQL> insert into items values(&id,'&iname',&cost,&qty);
Enter value for id: 101
Enter value for iname: Lux
Enter value for cost: 15.50
Enter value for qty: 33
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(101,'Lux',15.50,33)
1 row created.
SQL> /
Enter value for id: 102
Enter value for iname: Surf
Enter value for cost: 40.00
Enter value for qty: 20
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(102,'Surf',40.00,20)
1 row created.
SQL> /
Enter value for id: 106
Enter value for iname: Colgate
Enter value for cost: 16.50
Enter value for qty: 10
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(106,'Colgate',16.50,10)
1 row created.
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 106
Enter value for cid: 200
Enter value for qty: 1
Enter value for typ: P
Enter value for cost: 17.00
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(106,200,1,'P',17.00)
1 row created.
SQL> /
Enter value for id: 102
Enter value for cid: 10
Enter value for qty: 2
Enter value for typ: S
Enter value for cost: 18.00
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(102,10,2,'S',18.00)
1 row created.
SQL> /
Enter value for id: 101
Enter value for cid: 20
Enter value for qty: 2
Enter value for typ: S
Enter value for cost: 20.50
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,20,2,'S',20.50)
1 row created.
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> insert into customer values(&cid,'&cnam','&cadr')
2 ;
Enter value for cid: 200
Enter value for cnam: Raman
Enter value for cadr: Delhi
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(200,'Raman','Delhi')
1 row created.
SQL> /
Enter value for cid: 50
Enter value for cnam: Shyam
Enter value for cadr: Bombay
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(50,'Shyam','Bombay')
1 row created.
SQL> /
Enter value for cid: 20
Enter value for cnam: Manoj
Enter value for cadr: Bangalore
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(20,'Manoj','Bangalore')
1 row created.
SQL> select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
200 Raman Delhi
50 Shyam Bombay
20 Manoj Bangalore
SQL> select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
106 200 1 P 17
102 10 2 S 18
101 20 2 S 20.5
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 106
Enter value for cid: 50
Enter value for qty: 1
Enter value for typ: S
Enter value for cost: 25
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(106,50,1,'S',25)
1 row created.
SQL> /
Enter value for id: 102
Enter value for cid: 20
Enter value for qty: 1
Enter value for typ: P
Enter value for cost: 18
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(102,20,1,'P',18)
1 row created.
SQL> select * from items
2 ;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 15.5 33
102 Surf 40 20
106 Colgate 16.5 10
SQL> commit
2 ;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (SCOTT.FKCUST) violated - parent key not found
SQL> select * from sales;
no rows selected
SQL> select * from customer;
no rows selected
SQL> select * from items;
no rows selected
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 101
Enter value for cid: 10
Enter value for qty: 4
Enter value for typ: P
Enter value for cost: 10
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,10,4,'P',10)
1 row created.
SQL> /
Enter value for id: 50
Enter value for cid: 20
Enter value for qty: 5
Enter value for typ: S
Enter value for cost: 25
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(50,20,5,'S',25)
1 row created.
SQL> /
Enter value for id: 500
Enter value for cid: 30
Enter value for qty: 15
Enter value for typ: P
Enter value for cost: 10
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(500,30,15,'P',10)
1 row created.
SQL> /
Enter value for id: 101
Enter value for cid: 20
Enter value for qty: 5
Enter value for typ: S
Enter value for cost: 50
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,20,5,'S',50)
1 row created.
SQL> desc items
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NOT NULL NUMBER(4)
ITEM_NAME NOT NULL VARCHAR2(20)
COST NUMBER(4,2)
QTY NUMBER
SQL> insert into items values(&itmid,'&itmnam',&cst,&qty);
Enter value for itmid: 101
Enter value for itmnam: Lux
Enter value for cst: 13.50
Enter value for qty: 50
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(101,'Lux',13.50,50)
1 row created.
SQL> /
Enter value for itmid: 50
Enter value for itmnam: Surf
Enter value for cst: 40
Enter value for qty: 10
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(50,'Surf',40,10)
1 row created.
SQL> /
Enter value for itmid: 500
Enter value for itmnam: Colgate
Enter value for cst: 30
Enter value for qty: 5
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(500,'Colgate',30,5)
1 row created.
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> insert into customer values(&cid,'&cnam','&cadr');
Enter value for cid: 20
Enter value for cnam: Raman
Enter value for cadr: Delhi
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(20,'Raman','Delhi')
1 row created.
SQL> /
Enter value for cid: 10
Enter value for cnam: Shyam
Enter value for cadr: Mumbai
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(10,'Shyam','Mumbai')
1 row created.
SQL> /
Enter value for cid: 30
Enter value for cnam: Manoj
Enter value for cadr: Bangalore
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(30,'Manoj','Bangalore')
1 row created.
SQL> commit
2 ;
Commit complete.
SQL> select * from items;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 13.5 50
50 Surf 40 10
500 Colgate 30 5
SQL> select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
101 10 4 P 10
50 20 5 S 25
500 30 15 P 10
101 20 5 S 50
SQL> select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
20 Raman Delhi
10 Shyam Mumbai
30 Manoj Bangalore
SQL> insert into sales values(50,10,10,'P',25);
1 row created.
SQL> commit
2 ;
Commit complete.
SQL> host cls
SQL> select * from Items;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 13.5 50
50 Surf 40 10
500 Colgate 30 5
SQL> Select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
20 Raman Delhi
10 Shyam Mumbai
30 Manoj Bangalore
SQL> Select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
101 10 4 P 10
50 20 5 S 25
500 30 15 P 10
101 20 5 S 50
50 10 10 P 25
SQL> show plan
SP2-0158: unknown SHOW option "plan"
SQL> show
SQL> show all
appinfo is OFF and set to "SQL*Plus"
arraysize 15
autocommit OFF
autoprint OFF
autorecovery OFF
autotrace OFF
blockterminator "." (hex 2e)
btitle OFF and is the first few characters of the next SELECT statement
cmdsep OFF
colsep " "
compatibility version NATIVE
concat "." (hex 2e)
copycommit 0
COPYTYPECHECK is ON
define "&" (hex 26)
describe DEPTH 1 LINENUM OFF INDENT ON
echo OFF
editfile "afiedt.buf"
embedded OFF
escape OFF
FEEDBACK ON for 6 or more rows
flagger OFF
flush ON
heading ON
headsep "|" (hex 7c)
instance "local"
linesize 80
lno 9
loboffset 1
logsource ""
long 80
longchunksize 80
markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>SQL*Plus Report</title>" BODY "" TABLE "border='1' width='90%' align='center' summary='Script output'" SPOOL OFF ENTMAP ON PREFORMAT OFF
newpage 1
null ""
numformat ""
numwidth 10
pagesize 14
PAUSE is OFF
pno 1
recsep WRAP
recsepchar " " (hex 20)
release 1002000100
repfooter OFF and is NULL
repheader OFF and is NULL
serveroutput OFF
shiftinout INVISIBLE
showmode OFF
spool ON
sqlblanklines OFF
sqlcase MIXED
sqlcode 0
sqlcontinue "> "
sqlnumber ON
sqlpluscompatibility 10.2.0
sqlprefix "#" (hex 23)
sqlprompt "SQL> "
sqlterminator ";" (hex 3b)
suffix "sql"
tab ON
termout ON
timing OFF
trimout ON
trimspool OFF
ttitle OFF and is the first few characters of the next SELECT statement
underline "-" (hex 2d)
USER is "SCOTT"
verify ON
wrap : lines will be wrapped
SQL> set explain plan
SP2-0158: unknown SET option "explain"
SQL> set autotrace on explain
SQL> select count(*) from sales;
COUNT(*)
----------
5
Execution Plan
----------------------------------------------------------
Plan hash value: 1047182207
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| SALES | 5 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> select count(itemid) from sales;
COUNT(ITEMID)
-------------
5
Execution Plan
----------------------------------------------------------
Plan hash value: 417427692
--------------------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Tim
e |
--------------------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:
00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | |
|
| 2 | INDEX FAST FULL SCAN| SALES_ITEMIDX | 5 | 65 | 2 (0)| 00:
00:01 |
--------------------------------------------------------------------------------
-------
Note
-----
- dynamic sampling used for this statement
SQL> ed
Wrote file afiedt.buf
1 declare
2 x number ;
3 y number ;
4 z number ;
5 begin
6 select qty into x,cost into z from items where itemsid=&&itemid;
7 dbms_output.put_line('Qnty in Item Table'||x);
8 dbms_output.put_line('Cost of Item '||z);
9 update items set qty=qty-&salesqty where itemid=&&itemid;
10 savepoint s1;
11 select count(cid) into y from customer where cid=&cid;
12 if y=1
13 then
14 if x>0
15 then
16 insert into sales values (&&itemid,&&cid,&&salesqty,'S',&Cost);
17 commit;
18 else
19 rollback to savepoint s1;
20 end if;
21 else
22 dbms_output.put_line('Customer does not exist');
23 rollback to savepoint to s1;
24 end if;
25* end;
26 /
Enter value for itemid: 101
old 6: select qty into x,cost into z from items where itemsid=&&itemid;
new 6: select qty into x,cost into z from items where itemsid=101;
Enter value for salesqty:
User requested Interrupt or EOF detected.
SQL>
TABLE_NAME
------------------------------
SALES
SQL> drop table sales;
Table dropped.
SQL> drop table items;
Table dropped.
SQL> create table items (itemid number(4) primary key, item_name varchar2(20) not null,cost number(4,2),qty number );
Table created.
SQL> create table customer (cid number(3) primary key,cust_name varchar2(20) not null, cust_addr varchar2(25));
Table created.
SQL> create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,qty number(4) constraint qty_chk (check qty>0),t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null);
create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,qty number(4) constraint qty_chk (check qty>0),t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
*
ERROR at line 1:
ORA-02253: constraint specification not allowed here
SQL> ed
Wrote file afiedt.buf
1 create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,
2 cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,
3 qty number(4) constraint qty_chk (check qty>0),
4* t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
SQL> /
qty number(4) constraint qty_chk (check qty>0),
*
ERROR at line 3:
ORA-02253: constraint specification not allowed here
SQL> ed
Wrote file afiedt.buf
1 create table sales (itemid number(4) constraint fkitems references items(itemid) deferrable initially deferred,
2 cid number(3) constraint fkcust references customer(cid) deferrable initially deferred,
3 qty number(4) constraint qty_chk check (qty>0),
4* t_type char(1) constraint tp_chk check (t_type in ('P','S')),cost number(4,2) not null)
SQL> /
Table created.
SQL> desc sales;
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> desc user_indexes;
Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME NOT NULL VARCHAR2(30)
INDEX_TYPE VARCHAR2(27)
TABLE_OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
TABLE_TYPE VARCHAR2(11)
UNIQUENESS VARCHAR2(9)
COMPRESSION VARCHAR2(8)
PREFIX_LENGTH NUMBER
TABLESPACE_NAME VARCHAR2(30)
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
PCT_THRESHOLD NUMBER
INCLUDE_COLUMN NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
PCT_FREE NUMBER
LOGGING VARCHAR2(3)
BLEVEL NUMBER
LEAF_BLOCKS NUMBER
DISTINCT_KEYS NUMBER
AVG_LEAF_BLOCKS_PER_KEY NUMBER
AVG_DATA_BLOCKS_PER_KEY NUMBER
CLUSTERING_FACTOR NUMBER
STATUS VARCHAR2(8)
NUM_ROWS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
DEGREE VARCHAR2(40)
INSTANCES VARCHAR2(40)
PARTITIONED VARCHAR2(3)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
BUFFER_POOL VARCHAR2(7)
USER_STATS VARCHAR2(3)
DURATION VARCHAR2(15)
PCT_DIRECT_ACCESS NUMBER
ITYP_OWNER VARCHAR2(30)
ITYP_NAME VARCHAR2(30)
PARAMETERS VARCHAR2(1000)
GLOBAL_STATS VARCHAR2(3)
DOMIDX_STATUS VARCHAR2(12)
DOMIDX_OPSTATUS VARCHAR2(6)
FUNCIDX_STATUS VARCHAR2(8)
JOIN_INDEX VARCHAR2(3)
IOT_REDUNDANT_PKEY_ELIM VARCHAR2(3)
DROPPED VARCHAR2(3)
SQL> select index_name,index_type from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
SYS_C005457 NORMAL
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME
------------------------------
SYS_C005457 NORMAL
SQL> select index_name,index_type,degree from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
DEGREE
----------------------------------------
SYS_C005457 NORMAL
1
SQL> select index_name,index_type,degree,num_rows from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
DEGREE NUM_ROWS
---------------------------------------- ----------
SYS_C005457 NORMAL
1
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='CUSTOMER';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME
------------------------------
SYS_C005459 NORMAL
SQL> select index_name,index_type,ityp_name from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
no rows selected
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='ITEMS';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SYS_C005457 NORMAL
UNIQUE
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> create index sales_itemidx on sales(Item_ID);
create index sales_itemidx on sales(Item_ID)
*
ERROR at line 1:
ORA-00904: "ITEM_ID": invalid identifier
SQL> create index sales_itemidx on sales(ItemID);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SALES_ITEMIDX NORMAL
NONUNIQUE
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> create unique index cust_nameidx on customer(cust_name);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='CUSTOMER';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SYS_C005459 NORMAL
UNIQUE
CUST_NAMEIDX NORMAL
UNIQUE
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> create index qty_costidx on (T_type,qty);
create index qty_costidx on (T_type,qty)
*
ERROR at line 1:
ORA-00903: invalid table name
SQL> create index qty_costidx on sales(T_type,qty);
Index created.
SQL> select index_name,index_type,ityp_name,uniqueness from user_indexes where table_name='SALES';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
ITYP_NAME UNIQUENES
------------------------------ ---------
SALES_ITEMIDX NORMAL
NONUNIQUE
QTY_COSTIDX NORMAL
NONUNIQUE
SQL> desc user_indx_cols
ERROR:
ORA-04043: object user_indx_cols does not exist
SQL> desc user_index_cols
ERROR:
ORA-04043: object user_index_cols does not exist
SQL> desc user_col_index
ERROR:
ORA-04043: object user_col_index does not exist
SQL> select tname from tab where tname like '%COLS%';
no rows selected
SQL> conn / as sysdba
Connected.
SQL> select tname from tab where tname like '%COLS%';
TNAME
------------------------------
ALL_NESTED_TABLE_COLS
ALL_SEC_RELEVANT_COLS
ALL_TAB_COLS
ALL_TRIGGER_COLS
ALL_XML_TAB_COLS
ALL_XML_VIEW_COLS
DBA_MVIEW_LOG_FILTER_COLS
DBA_NESTED_TABLE_COLS
DBA_SEC_RELEVANT_COLS
DBA_TAB_COLS
DBA_TRIGGER_COLS
TNAME
------------------------------
DBA_XML_TAB_COLS
DBA_XML_VIEW_COLS
EXU9TAB_UNUSED_COLS
KU$_FIND_SGC_COLS_VIEW
KU$_FIND_SGI_COLS_VIEW
LOGMNR_INTERESTING_COLS
STREAMS$_DEST_OBJ_COLS
USER_NESTED_TABLE_COLS
USER_SEC_RELEVANT_COLS
USER_TAB_COLS
USER_TRIGGER_COLS
TNAME
------------------------------
USER_XML_TAB_COLS
USER_XML_VIEW_COLS
24 rows selected.
SQL> select tname from tab where tname like '%ind%';
TNAME
------------------------------
_utl$_gnp_ind
_utl$_gp_ind_parts
_utl$_lc_ind_subs
_utl$_lnc_ind_parts
SQL> select tname from tab where tname like 'IND%';
TNAME
------------------------------
IND$
INDARRAYTYPE$
INDCOMPART$
INDCOMPARTV$
INDEX_HISTOGRAM
INDEX_STATS
INDOP$
INDPART$
INDPARTV$
INDPART_PARAM$
INDSUBPART$
TNAME
------------------------------
INDSUBPARTV$
INDTYPES$
IND_ONLINE$
IND_STATS$
15 rows selected.
SQL> select tname from tab where tname like '%IND%';
TNAME
------------------------------
ALL_INDEXES
ALL_INDEXTYPES
ALL_INDEXTYPE_ARRAYTYPES
ALL_INDEXTYPE_COMMENTS
ALL_INDEXTYPE_OPERATORS
ALL_IND_COLUMNS
ALL_IND_EXPRESSIONS
ALL_IND_PARTITIONS
ALL_IND_STATISTICS
ALL_IND_SUBPARTITIONS
ALL_JOIN_IND_COLUMNS
TNAME
------------------------------
ALL_OPBINDINGS
ALL_PART_INDEXES
ALL_SCHEDULER_WINDOWS
ALL_SCHEDULER_WINDOW_DETAILS
ALL_SCHEDULER_WINDOW_GROUPS
ALL_SCHEDULER_WINDOW_LOG
ALL_SQLSET_BINDS
ALL_XML_INDEXES
DBA_ADVISOR_FINDINGS
DBA_HIST_SQLBIND
DBA_HIST_SQL_BIND_METADATA
TNAME
------------------------------
DBA_INDEXES
DBA_INDEXTYPES
DBA_INDEXTYPE_ARRAYTYPES
DBA_INDEXTYPE_COMMENTS
DBA_INDEXTYPE_OPERATORS
DBA_IND_COLUMNS
DBA_IND_EXPRESSIONS
DBA_IND_PARTITIONS
DBA_IND_STATISTICS
DBA_IND_SUBPARTITIONS
DBA_JOIN_IND_COLUMNS
TNAME
------------------------------
DBA_OPBINDINGS
DBA_PART_INDEXES
DBA_SCHEDULER_WINDOWS
DBA_SCHEDULER_WINDOW_DETAILS
DBA_SCHEDULER_WINDOW_GROUPS
DBA_SCHEDULER_WINDOW_LOG
DBA_SQLSET_BINDS
DBA_SQLTUNE_BINDS
DBA_XML_INDEXES
EXU10IND_BASE
EXU81IND
TNAME
------------------------------
EXU81INDC
EXU81INDI
EXU81INDIC
EXU81IND_BASE
EXU8IND
EXU8INDC
EXU8INDI
EXU8INDIC
EXU8INDU
EXU9IND
EXU9INDC
TNAME
------------------------------
EXU9INDI
EXU9INDIC
EXU9IND_BASE
GV_$INDEXED_FIXED_COLUMN
GV_$SQL_BIND_CAPTURE
GV_$SQL_BIND_DATA
GV_$SQL_BIND_METADATA
IND$
INDARRAYTYPE$
INDCOMPART$
INDCOMPARTV$
TNAME
------------------------------
INDEX_HISTOGRAM
INDEX_STATS
INDOP$
INDPART$
INDPARTV$
INDPART_PARAM$
INDSUBPART$
INDSUBPARTV$
INDTYPES$
IND_ONLINE$
IND_STATS$
TNAME
------------------------------
KU$_10_1_IND_STATS_VIEW
KU$_10_1_PIND_STATS_VIEW
KU$_10_1_SPIND_STATS_VIEW
KU$_FIND_HIDDEN_CONS_VIEW
KU$_FIND_SGC_COLS_VIEW
KU$_FIND_SGC_VIEW
KU$_FIND_SGI_COLS_VIEW
KU$_INDARRAYTYPE_VIEW
KU$_INDEXOP_VIEW
KU$_INDEXTYPE_VIEW
KU$_INDEX_COL_VIEW
TNAME
------------------------------
KU$_INDEX_VIEW
KU$_IND_CACHE_STATS_VIEW
KU$_IND_COL_VIEW
KU$_IND_COMPART_VIEW
KU$_IND_PARTOBJ_VIEW
KU$_IND_PART_COL_VIEW
KU$_IND_PART_VIEW
KU$_IND_STATS_VIEW
KU$_IND_SUBPART_COL_VIEW
KU$_IND_SUBPART_VIEW
KU$_IND_TS_VIEW
TNAME
------------------------------
KU$_LOBFRAGINDEX_VIEW
KU$_LOBINDEX_VIEW
KU$_OIDINDEX_VIEW
KU$_OPBINDING_VIEW
KU$_PIND_STATS_VIEW
KU$_SPIND_STATS_VIEW
KU$_SUBLOBFRAGINDEX_VIEW
KU$_TTS_IND_VIEW
LOADER_SKIP_UNUSABLE_INDEXES
LOGMNRG_IND$
LOGMNRG_INDCOMPART$
TNAME
------------------------------
LOGMNRG_INDPART$
LOGMNRG_INDSUBPART$
LOGMNRT_IND$
LOGMNRT_INDCOMPART$
LOGMNRT_INDPART$
LOGMNRT_INDSUBPART$
OPBINDING$
SCHEDULER$_WINDOW
SCHEDULER$_WINDOW_DETAILS
SCHEDULER$_WINDOW_GROUP
USER_ADVISOR_FINDINGS
TNAME
------------------------------
USER_INDEXES
USER_INDEXTYPES
USER_INDEXTYPE_ARRAYTYPES
USER_INDEXTYPE_COMMENTS
USER_INDEXTYPE_OPERATORS
USER_IND_COLUMNS
USER_IND_EXPRESSIONS
USER_IND_PARTITIONS
USER_IND_STATISTICS
USER_IND_SUBPARTITIONS
USER_JOIN_IND_COLUMNS
TNAME
------------------------------
USER_OPBINDINGS
USER_PART_INDEXES
USER_SQLSET_BINDS
USER_SQLTUNE_BINDS
USER_XML_INDEXES
UTL_ALL_IND_COMPS
V_$INDEXED_FIXED_COLUMN
V_$SQL_BIND_CAPTURE
V_$SQL_BIND_DATA
V_$SQL_BIND_METADATA
WRH$_SQL_BIND_METADATA
TNAME
------------------------------
WRI$_ADV_FINDINGS
WRI$_ADV_SQLT_BINDS
WRI$_OPTSTAT_IND_HISTORY
WRI$_SQLSET_BINDS
147 rows selected.
SQL> conn scott/lion
Connected.
SQL> desc user_ind_columns
Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME VARCHAR2(30)
TABLE_NAME VARCHAR2(30)
COLUMN_NAME VARCHAR2(4000)
COLUMN_POSITION NUMBER
COLUMN_LENGTH NUMBER
CHAR_LENGTH NUMBER
DESCEND VARCHAR2(4)
SQL> select index_name,column_name,column_position from user_ind_columns;
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
PK_DEPT
DEPTNO
1
PK_EMP
EMPNO
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SYS_C005400
AID
1
T1PK
EID
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
1
SYS_C005454
ID
1
BIN$u/R7a2iFSquoTbC0j8wH9g==$0
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
ITEM_ID
1
SYS_C005457
ITEMID
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SYS_C005459
CID
1
SALES_ITEMIDX
ITEMID
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
CUST_NAMEIDX
CUST_NAME
1
QTY_COSTIDX
QTY
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
2
QTY_COSTIDX
T_TYPE
1
12 rows selected.
SQL> select index_name,column_name,column_position from user_ind_columns where table_name='SALES';
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
SALES_ITEMIDX
ITEMID
1
QTY_COSTIDX
T_TYPE
1
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
COLUMN_POSITION
---------------
QTY_COSTIDX
QTY
2
SQL> desc items;
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NOT NULL NUMBER(4)
ITEM_NAME NOT NULL VARCHAR2(20)
COST NUMBER(4,2)
QTY NUMBER
SQL> insert into items values(&id,&iname,&cost,&qty);
Enter value for id: 101
Enter value for iname: Lux
Enter value for cost: 15.50
Enter value for qty: 4
old 1: insert into items values(&id,&iname,&cost,&qty)
new 1: insert into items values(101,Lux,15.50,4)
insert into items values(101,Lux,15.50,4)
*
ERROR at line 1:
ORA-00984: column not allowed here
SQL> insert into items values(&id,&iname,&cost,&qty);
Enter value for id:
Enter value for iname:
Enter value for cost:
Enter value for qty:
old 1: insert into items values(&id,&iname,&cost,&qty)
new 1: insert into items values(,,,)
insert into items values(,,,)
*
ERROR at line 1:
ORA-00936: missing expression
SQL>
SQL> insert into items values(&id,'&iname',&cost,&qty);
Enter value for id: 101
Enter value for iname: Lux
Enter value for cost: 15.50
Enter value for qty: 33
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(101,'Lux',15.50,33)
1 row created.
SQL> /
Enter value for id: 102
Enter value for iname: Surf
Enter value for cost: 40.00
Enter value for qty: 20
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(102,'Surf',40.00,20)
1 row created.
SQL> /
Enter value for id: 106
Enter value for iname: Colgate
Enter value for cost: 16.50
Enter value for qty: 10
old 1: insert into items values(&id,'&iname',&cost,&qty)
new 1: insert into items values(106,'Colgate',16.50,10)
1 row created.
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 106
Enter value for cid: 200
Enter value for qty: 1
Enter value for typ: P
Enter value for cost: 17.00
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(106,200,1,'P',17.00)
1 row created.
SQL> /
Enter value for id: 102
Enter value for cid: 10
Enter value for qty: 2
Enter value for typ: S
Enter value for cost: 18.00
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(102,10,2,'S',18.00)
1 row created.
SQL> /
Enter value for id: 101
Enter value for cid: 20
Enter value for qty: 2
Enter value for typ: S
Enter value for cost: 20.50
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,20,2,'S',20.50)
1 row created.
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> insert into customer values(&cid,'&cnam','&cadr')
2 ;
Enter value for cid: 200
Enter value for cnam: Raman
Enter value for cadr: Delhi
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(200,'Raman','Delhi')
1 row created.
SQL> /
Enter value for cid: 50
Enter value for cnam: Shyam
Enter value for cadr: Bombay
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(50,'Shyam','Bombay')
1 row created.
SQL> /
Enter value for cid: 20
Enter value for cnam: Manoj
Enter value for cadr: Bangalore
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(20,'Manoj','Bangalore')
1 row created.
SQL> select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
200 Raman Delhi
50 Shyam Bombay
20 Manoj Bangalore
SQL> select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
106 200 1 P 17
102 10 2 S 18
101 20 2 S 20.5
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 106
Enter value for cid: 50
Enter value for qty: 1
Enter value for typ: S
Enter value for cost: 25
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(106,50,1,'S',25)
1 row created.
SQL> /
Enter value for id: 102
Enter value for cid: 20
Enter value for qty: 1
Enter value for typ: P
Enter value for cost: 18
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(102,20,1,'P',18)
1 row created.
SQL> select * from items
2 ;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 15.5 33
102 Surf 40 20
106 Colgate 16.5 10
SQL> commit
2 ;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (SCOTT.FKCUST) violated - parent key not found
SQL> select * from sales;
no rows selected
SQL> select * from customer;
no rows selected
SQL> select * from items;
no rows selected
SQL> insert into sales values(&id,&cid,&qty,'&typ',&cost);
Enter value for id: 101
Enter value for cid: 10
Enter value for qty: 4
Enter value for typ: P
Enter value for cost: 10
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,10,4,'P',10)
1 row created.
SQL> /
Enter value for id: 50
Enter value for cid: 20
Enter value for qty: 5
Enter value for typ: S
Enter value for cost: 25
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(50,20,5,'S',25)
1 row created.
SQL> /
Enter value for id: 500
Enter value for cid: 30
Enter value for qty: 15
Enter value for typ: P
Enter value for cost: 10
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(500,30,15,'P',10)
1 row created.
SQL> /
Enter value for id: 101
Enter value for cid: 20
Enter value for qty: 5
Enter value for typ: S
Enter value for cost: 50
old 1: insert into sales values(&id,&cid,&qty,'&typ',&cost)
new 1: insert into sales values(101,20,5,'S',50)
1 row created.
SQL> desc items
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NOT NULL NUMBER(4)
ITEM_NAME NOT NULL VARCHAR2(20)
COST NUMBER(4,2)
QTY NUMBER
SQL> insert into items values(&itmid,'&itmnam',&cst,&qty);
Enter value for itmid: 101
Enter value for itmnam: Lux
Enter value for cst: 13.50
Enter value for qty: 50
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(101,'Lux',13.50,50)
1 row created.
SQL> /
Enter value for itmid: 50
Enter value for itmnam: Surf
Enter value for cst: 40
Enter value for qty: 10
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(50,'Surf',40,10)
1 row created.
SQL> /
Enter value for itmid: 500
Enter value for itmnam: Colgate
Enter value for cst: 30
Enter value for qty: 5
old 1: insert into items values(&itmid,'&itmnam',&cst,&qty)
new 1: insert into items values(500,'Colgate',30,5)
1 row created.
SQL> desc customer
Name Null? Type
----------------------------------------- -------- ----------------------------
CID NOT NULL NUMBER(3)
CUST_NAME NOT NULL VARCHAR2(20)
CUST_ADDR VARCHAR2(25)
SQL> insert into customer values(&cid,'&cnam','&cadr');
Enter value for cid: 20
Enter value for cnam: Raman
Enter value for cadr: Delhi
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(20,'Raman','Delhi')
1 row created.
SQL> /
Enter value for cid: 10
Enter value for cnam: Shyam
Enter value for cadr: Mumbai
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(10,'Shyam','Mumbai')
1 row created.
SQL> /
Enter value for cid: 30
Enter value for cnam: Manoj
Enter value for cadr: Bangalore
old 1: insert into customer values(&cid,'&cnam','&cadr')
new 1: insert into customer values(30,'Manoj','Bangalore')
1 row created.
SQL> commit
2 ;
Commit complete.
SQL> select * from items;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 13.5 50
50 Surf 40 10
500 Colgate 30 5
SQL> select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
101 10 4 P 10
50 20 5 S 25
500 30 15 P 10
101 20 5 S 50
SQL> select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
20 Raman Delhi
10 Shyam Mumbai
30 Manoj Bangalore
SQL> insert into sales values(50,10,10,'P',25);
1 row created.
SQL> commit
2 ;
Commit complete.
SQL> host cls
SQL> select * from Items;
ITEMID ITEM_NAME COST QTY
---------- -------------------- ---------- ----------
101 Lux 13.5 50
50 Surf 40 10
500 Colgate 30 5
SQL> Select * from customer;
CID CUST_NAME CUST_ADDR
---------- -------------------- -------------------------
20 Raman Delhi
10 Shyam Mumbai
30 Manoj Bangalore
SQL> Select * from sales;
ITEMID CID QTY T COST
---------- ---------- ---------- - ----------
101 10 4 P 10
50 20 5 S 25
500 30 15 P 10
101 20 5 S 50
50 10 10 P 25
SQL> show plan
SP2-0158: unknown SHOW option "plan"
SQL> show
SQL> show all
appinfo is OFF and set to "SQL*Plus"
arraysize 15
autocommit OFF
autoprint OFF
autorecovery OFF
autotrace OFF
blockterminator "." (hex 2e)
btitle OFF and is the first few characters of the next SELECT statement
cmdsep OFF
colsep " "
compatibility version NATIVE
concat "." (hex 2e)
copycommit 0
COPYTYPECHECK is ON
define "&" (hex 26)
describe DEPTH 1 LINENUM OFF INDENT ON
echo OFF
editfile "afiedt.buf"
embedded OFF
escape OFF
FEEDBACK ON for 6 or more rows
flagger OFF
flush ON
heading ON
headsep "|" (hex 7c)
instance "local"
linesize 80
lno 9
loboffset 1
logsource ""
long 80
longchunksize 80
markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>SQL*Plus Report</title>" BODY "" TABLE "border='1' width='90%' align='center' summary='Script output'" SPOOL OFF ENTMAP ON PREFORMAT OFF
newpage 1
null ""
numformat ""
numwidth 10
pagesize 14
PAUSE is OFF
pno 1
recsep WRAP
recsepchar " " (hex 20)
release 1002000100
repfooter OFF and is NULL
repheader OFF and is NULL
serveroutput OFF
shiftinout INVISIBLE
showmode OFF
spool ON
sqlblanklines OFF
sqlcase MIXED
sqlcode 0
sqlcontinue "> "
sqlnumber ON
sqlpluscompatibility 10.2.0
sqlprefix "#" (hex 23)
sqlprompt "SQL> "
sqlterminator ";" (hex 3b)
suffix "sql"
tab ON
termout ON
timing OFF
trimout ON
trimspool OFF
ttitle OFF and is the first few characters of the next SELECT statement
underline "-" (hex 2d)
USER is "SCOTT"
verify ON
wrap : lines will be wrapped
SQL> set explain plan
SP2-0158: unknown SET option "explain"
SQL> set autotrace on explain
SQL> select count(*) from sales;
COUNT(*)
----------
5
Execution Plan
----------------------------------------------------------
Plan hash value: 1047182207
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| SALES | 5 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
SQL> desc sales
Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMID NUMBER(4)
CID NUMBER(3)
QTY NUMBER(4)
T_TYPE CHAR(1)
COST NOT NULL NUMBER(4,2)
SQL> select count(itemid) from sales;
COUNT(ITEMID)
-------------
5
Execution Plan
----------------------------------------------------------
Plan hash value: 417427692
--------------------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Tim
e |
--------------------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:
00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | |
|
| 2 | INDEX FAST FULL SCAN| SALES_ITEMIDX | 5 | 65 | 2 (0)| 00:
00:01 |
--------------------------------------------------------------------------------
-------
Note
-----
- dynamic sampling used for this statement
SQL> ed
Wrote file afiedt.buf
1 declare
2 x number ;
3 y number ;
4 z number ;
5 begin
6 select qty into x,cost into z from items where itemsid=&&itemid;
7 dbms_output.put_line('Qnty in Item Table'||x);
8 dbms_output.put_line('Cost of Item '||z);
9 update items set qty=qty-&salesqty where itemid=&&itemid;
10 savepoint s1;
11 select count(cid) into y from customer where cid=&cid;
12 if y=1
13 then
14 if x>0
15 then
16 insert into sales values (&&itemid,&&cid,&&salesqty,'S',&Cost);
17 commit;
18 else
19 rollback to savepoint s1;
20 end if;
21 else
22 dbms_output.put_line('Customer does not exist');
23 rollback to savepoint to s1;
24 end if;
25* end;
26 /
Enter value for itemid: 101
old 6: select qty into x,cost into z from items where itemsid=&&itemid;
new 6: select qty into x,cost into z from items where itemsid=101;
Enter value for salesqty:
User requested Interrupt or EOF detected.
SQL>
Subscribe to:
Posts (Atom)