Wednesday 29 January 2014

ORACLE - SQL Query - 3

Query to display first n records of the table

Structure and data of the table i used

 query to display first n records of the table. where &n is a substitution variable in oracle, whose values can be assigned at runtime, very much similar to scanf function in C language

rownum column i used here is a pseudo-column supplied from oracle with every table that you create. Be sure with the behaviour of rownum. check the below queries to understand the behaviour




Friday 13 December 2013

ORACLE - SQL Query - 2

Query to display 1st highest,2nd highest salary earners.

This is the table i am using here.

Query to display 1st highest earners

Query to display 2nd highest earners

Sunday 6 October 2013

custom strcpy function in c to copy a string

#include<stdio.h>
#include<conio.h>
void mystrcpy(char *dest,const char*src)
{
while(*src)
{
 *dest=*src;
 src++;
 dest++;
}
*dest='\0';
}
int main()
{
  char str1[10]="Welcome";
  char str2[10];
  clrscr();
  printf("\nEnter a string: ");
  gets(str2);
  puts(str1);
  puts(str2);
  //stcpy(str1,str2); -- way to call library function
  mystrcpy(str1,str2);
  puts(str1);
  puts(str2);
  return 0;
}

custom strcmp function in c to compare two strings

#include<stdio.h>
#include<string.h>
#include<conio.h>
int mystrcmp(const char*s1,const char*s2)
{
int r=0;
while(*s1!='\0'||*s2!='\0')
{
 if(*s1!=*s2)
 {
 r=(int)(*s1-*s2);
 return r;
 }
 s1++;
 s2++;
}
return r;
}

int main()
{
  char s1[10]="Hello";
  char s2[10]="HeLlo";
  int d;
  clrscr();
  puts(s1);
  puts(s2);
  //d=strcmp(s1,s2);
  d=mystrcmp(s1,s2);
  printf("\nDiff is:%d",d);
  getch();
  return 0;
}