Custom Search

Wednesday 30 November 2011

Write a trigger that check the student_id must be start with ‘M’. PL/SQL trigger that check the student_id must be start with ‘M’


Write a trigger that check the student_id must be start with ‘M’. PL/SQL trigger that check the student_id must be start with ‘M’

create table student_id(sno varchar2(10));

insert into student_id values(‘&sno’)

SQL> select * from student_id;


SNO

---------

1

2

3

4

set serveroutput on

create or replace trigger tri30 before insert on student_id for each row

declare

tsno student_id.sno%type;

begin

tsno:=:new.sno;

dbms_output.put_line(tsno);

if tsno not like 'M%' then

raise_application_error(-20005,'Invalid Number');

end if;

end;

Write a trigger that check the mark is not zero or negative, PL/SQL trigger that check the mark is not zero or negative


Write a trigger that check the mark is not zero or negative, PL/SQL trigger that check the mark is not zero or negative


create table astd(mark number(3));


insert into astd values(&mark);

SQL> select * from astd;


MARK

---------

23

0

800

0

0


set serveroutput on

create or replace trigger tri29 before insert on astd for each row

declare

tmark astd.mark%type;

begin

tmark:=:new.mark;

if tmark>700 or tmark<0 then

raise_application_error(-20003,'Invalid Mark');

end if;

end;

Write a Trigger to ckeck the Pincode is exactly six degit or not., Write a PL/SQL Trigger to ckeck the Pincode is exactly six degit or not


Write a Trigger to ckeck the Pincode is exactly six degit or not.,  Write a PL/SQL Trigger to ckeck the Pincode is exactly six degit or not

create table citypin(

pin number(10));


insert into citypin values(&pin);


SQL> select * from citypin;


PIN

---------

2434355

3435465

122

123235467


set serveroutput on

create or replace trigger tri28 before insert on citypin for each row

declare

tpin citypin.pin%type;

begin

tpin:=:new.pin;

if length(to_char(tpin))!=6 then

raise_application_error(-20002,'Your Pincode is Invalid');

end if;

end;

Write a PL/SQL function to find the sum of digits of accepted nos.


Write a PL/SQL function to find the sum of digits of accepted nos.

set serveroutput on

create or replace function sm(no in number)return number as

i number(4);

sm number(4);

rem number(4);

num number(4);

begin

num:=no;

sm:=0;

i:=0;

while i<=num+1

loop

rem:=mod(num,10);

dbms_output.put_line(rem);

sm:=sm+rem;

num:=num/10;

i:=i+1;

end loop;

return sm;

end;
------------

set serveroutput on

declare

nos number(10);

ans number(3);

begin

nos:=&nos;

ans:=sm(nos);

dbms_output.put_line('Sum of Digit is '||ans);

end;

Write a function in PL/SQL to check whether the given number is prime or not.


Write a function in PL/SQL to check whether the given number is prime or not.

set serveroutput on

create or replace function prime(n in number) return varchar2 is

i number(10);

pr number(10);

res varchar2(10);

begin

pr:=1;

for i in 2..n/2 loop

if mod(n,i)=0 then

pr:=0;

end if;

end loop;


if pr=1 then

res:='prime';

else

res:='Not Prime';

end if;

return res;

end;

To run:= select prime(5) from dual;

Write a PL/SQL block to raise the salary by 20% of given employee on following table.., PL/SQL Program to raise the salary by 20% of given employee on following table


Write a PL/SQL block to raise the salary by 20% of given employee on following table.., PL/SQL Program to raise the salary by 20% of given employee on following table

Emp_Salary (eno, ename, city, salary)

Table Creation…

eno number primary key,

ename char(15),

city char(15),

sal number(10,2));

insert into empsal values(1,'Hiral','Mehsana',20000);

insert into empsal values(2,'Pinkey','Mehsana',15000);

insert into empsal values(3,'Dhruvi','Mehsana',10000);


Program…

declare

n number;

s number(10,2);

begin

n:=&n;

--select sal into s from empsal where eno=n;

update empsal set sal=sal+(sal*0.20) where eno=n;

end;

Write a PL/SQL block to display the Information of given student on following table Stud (sno, sname, address, city)., PL/SQL Program to display the Information of given student on following table Stud (sno, sname, address, city)


Write a PL/SQL block to display the Information of given student on following table Stud (sno, sname, address, city)., PL/SQL Program to display the Information of given student on following table Stud (sno, sname, address, city)


Table Creation…
create table stud(

sno number primary key,

sname char(15),

addr varchar(30),

city char(15));

insert into stud values(1,'hiral','2,krishna society','Mehsana.');

insert into stud values(2,'pinky','4,Kalyaneshwer society','Mehsana.');

insert into stud values(3,'Dhruvi','24,Pushpavati society','Mehsana');


Program…


declare

no number;

n number;

name char(15);

add varchar(50);

c char(15);

begin

n:=&n;

select sno,sname,addr,city into no,name,add,c from stud where sno=n;

dbms_output.put_line('The Sno is ' || no);

dbms_output.put_line('The Sname is ' || name);

dbms_output.put_line('The address is ' || add);

dbms_output.put_line('The city is ' || c);

end;

Write a PL/SQL block to find the sum of first 100 odd nos. and even nos). PL/SQL Program to find the sum of first 100 odd nos. and even nos


Write a PL/SQL block to find the sum of first 100 odd nos. and even nos). PL/SQL Program to find the sum of first 100 odd nos. and even nos

declare

odd number:=0;

even number:=0;

i number;

begin

for i in 1..100

loop

if(i mod 2 = 0) then

even:=even+i;

else

odd:=odd+i;

end if;

end loop;

dbms_output.put_line('The Sum of 100 even nos is ' || even);

dbms_output.put_line('The Sum of 100 odd nos is ' || odd);

end;

Write a PL/SQL block to find the maximum number from given three numbers, PL/SQL Program to find the maximum number from given three numbers


Write a PL/SQL block to find the maximum number from given three numbers, PL/SQL Program to find the maximum number from given three numbers

declare

a number;

b number;

c number;

begin

a:=&a;

b:=&b;

c:=&c;


if (a>b and a>c) then

dbms_output.put_line('a is maximum ' || a);

elsif (b>a and b>c) then

dbms_output.put_line('b is maximum ' || b);

else

dbms_output.put_line('c is maximum ' || c);

end if;

end;

Monday 21 November 2011

C /C++ Program to enter elements of integer array & display the sum, C or C++ Program to display numbers with the help of array.


C /C++ Program to enter elements of integer array & display the sum, C or C++ Program to display numbers with the help of array.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[5],sum=0;
clrscr();
printf("Enter the 5 numbers:\n");
for(i=0;i<5;i++)
 {
  scanf("%d", &a[i]);
  sum=sum+a[i];
 }
  printf("\n");
for(i=0;i<5;i++)
 {
  printf("a[%d]=%d\n",i+1,a[i]);
 }
 printf("\nsum=%d\n",sum);
 getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output


C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output

Program:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("Enter the values of a,b,c:\n");
scanf("%f %f %f", &a, &b, &c);
d= b*b - 4*a*c;
printf("discriminant is:%f", d);
if(d<0)
{
printf("\nRoots are Imaginary");
}
else
{
r1= (-b+ sqrt(d))/(2*a);
r2=( -b- sqrt(d))/(2*a);
printf("\n%f %f",r1,r2);
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the result

C/C++ Program to print star pattern, Program to print star pattern in pyramid form, Program to print star pattern in decreasing form.


C/C++ Program to print star pattern, Program to print star pattern in pyramid form, Program to print star pattern in decreasing form.

Program:-

#include<stdio.h>
#include<conio.h>
void main()
{ int i,j;
clrscr();
for(i=1;i<6;i++)
{ printf("\n");
for(j=1;j<=i;j++)
{ printf("*");
}}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/C++ Program that will scan a character string passed as an argument & convert all lowercase characters into uppercase characters.


C/C++ Program that will scan a character string passed as an argument & convert all lowercase characters into uppercase characters. 


Program

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void convupper (char s[10]);
void main()
{
char str[10];
clrscr();
printf("Enter the string:");
scanf("%s",str);
convupper(str);
getch();
}
 void convupper(char s[10])
 {
 int i;
 for(i=0;i<10;i++)
 if(islower (s[i]))
 {
 s[i]=toupper(s[i]);
 }
 printf("%s",s);
 getch();
 }


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

C/C++ Program to write a function that will interchange the value of two variable, Program to interchange values of 2 variables


C/C++ Program to write a function that will interchange the value of two variable, Program to interchange values of  2 variables

Program
#include<stdio.h>
#include<conio.h>
void interchange(int, int);
void main()
{
int x,y;
clrscr();
printf("Enter two Numbers:\n");
scanf("%d %d", &x, &y);
printf("\nOriginal value is:%d %d", x,y);
interchange(x,y);
getch();
}
void interchange(int m,int n)
{
int temp;
temp=m;
m=n;
n=temp;
printf("\nThe value after interchange is: %d %d",m,n);
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

Wednesday 9 November 2011

Header File Definition, Various Header File use in C, Use of Header File, Name Description of Various Header Files, Use of , , , C Library Header File, various header files in c language with ites use

Header File Definition, Various Header File use in C, Use of Header File, Name  Description of Various Header Files, Use of <float.h>, <ctype.h>, <stdio.h>, C Library Header File, various header files in c language with ites use

Header File Definition
Header files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required. This is to keep the interface in the header separate from the implementation. The C standard library and C++ standard library traditionally declare their standard functions in header files.

Use of Header Files

Header files are included into a program source file by the ‘#include’ preprocessor directive. The C language supports two forms of this directive; the first,

#include "header"
is typically used to include a header file header that you write yourself; this would contain definitions and declarations describing the interfaces between the different parts of your particular application. By contrast,

 #include <file.h>
is typically used to include a header file file.h that contains definitions and declarations for a standard library. This file would normally be installed in a standard place by your system administrator. You should use this second form for the C library header files.


Name--Description

  • <assert.h>--Contains the assert macro, used to assist with detecting logical errors and other types of bug in debugging versions of a program.
  • <complex.h>--A set of functions for manipulating complex numbers.
  • <ctype.h>--Contains functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known).
  • <errno.h> --For testing error codes reported by library functions.
  • <fenv.h>--For controlling floating-point environment.
  • <float.h>--Contains defined constants specifying the implementation-specific properties of the floating-point library, such as the minimum difference between two different floating-point numbers (_EPSILON), the maximum number of digits of accuracy (_DIG) and the range of numbers which can be represented (_MIN, _MAX).
  • <inttypes.h>--For precise conversion between integer types.
  • <iso646.h>--For programming in ISO 646 variant character sets.
  • <limits.h>--Contains defined constants specifying the implementation-specific properties of the integer types, such as the range of numbers which can be represented (_MIN, _MAX).
  • <locale.h>--For setlocale and related constants. This is used to choose an appropriate locale.
  • <math.h>--For computing common mathematical functions.
  • <setjmp.h>--Declares the macros setjmp and longjmp, which are used for non-local exits.
  • <signal.h> --For controlling various exceptional conditions.
  • <stdarg.h>--For accessing a varying number of arguments passed to functions.
  • <stdbool.h>--For a boolean data type.
  • <stdint.h>--For defining various integer types.
  • <stddef.h>--For defining several useful types and macros.
  • <stdio.h>--Provides the core input and output capabilities of the C language. This file includes the venerable printf function.
  • <stdlib.h>--For performing a variety of operations, including conversion, pseudo-random numbers, memory allocation, process control, environment, signalling, searching, and sorting.
  • <string.h>--For manipulating several kinds of strings.
  • <tgmath.h>--For type-generic mathematical functions.
  • <time.h>--For converting between various time and date formats.
  • <wchar.h>--For manipulating wide streams and several kinds of strings using wide characters - key to supporting a range of languages.
  • <wctype.h>


Laptops