Monday 26 May 2014

How to swap 2 numbers using pointers.

#iclude"stdio.h"
#include"conio.h"
void main()
{
int a=4,b=8;
void swap(int *,int *); // Prototype  for the function
clrscr();
printf("\nNumbers before swap : a = % d, b = %d",a,b); // print variable value before swap
swap(&a,&b);
printf("\nNumbers after swap : a = % d, b = %d",a,b); / print variable value after swap
getch();
 }
void swap(int *p,int *q)
{
int t; // Temporary variable to store the value before swapping
t=*p;
*p=*q;
*q=t;
}

How to copy string using pointer in C Programming

#include"stdio.h"
#include"conio.h"
void main(int argc,char *argv[])
{
void stringcopy(char *,char *);
char target[10];
clrscr();
fflush(stdout);
if(argc<2)
{
printf("\nWrong number of argument parameter");
exit(0);
}
stringcopy(target,argv[1]); // target, &target[0]
printf("\nSource string %s, Target String %s",argv[1],target);
getch();
}
void stringcopy(char *trg,char *source)
{
while(*trg++=*source++);
//Alternative way pretty adhoc process
/*while(*source)
{
*trg = *source;
trg++;
source++;
}
*trg=*source;*/
}

Monday 12 May 2014

How to create a view in Oracle

A view is a sql statement which can be stored in Oracle database as SQL statement. It never stored as data but as a sql statement.

Syntax to create a view

CREATE OR REPLACE VIEW VIEW_NAME AS
SELECT * FROM TABLE_NAME;

Syntax to see a view content

DESC VIEW_NAME

Syntax to delete a view

DROP VIEW VIEW_NAME

You can use a view as a table i.e. add where clause in view or use it in an inline view.

SELECT * FROM VIEW_NAME WHERE COLUMN_NAME = FIELD_VALUE

Example

Suppose you have a sql based on 2 table employee having 2 columns ecode, ename
and salary having 2 columns month_year, net_pay. Now the sql is to get ecode, ename,month_year
and sum of ney_pay. sql statement is given below.

select ee.ecode, ee.ename,sl.month_year, sum(sl.ney_pay) tot_net_pay
from employee ee,salary sl
where sl.emp_id = ee.emp_id
group by ee.ecode, ee.ename,sl.month_year,
order by 1,3

sl is the alias for table salary, ee is the alias for table employee, emp_id is primary key in employee
and reference key in salary. order by clause uses index of columns in select clause.

Now to create the view we write

CREATE OR REPLACE VIEW EMP_SAL_VIEW AS
select ee.ecode, ee.ename,sl.month_year, sum(sl.ney_pay) tot_net_pay
from employee ee,salary sl
where sl.emp_id = ee.emp_id
group by ee.ecode, ee.ename,sl.month_year,
order by 1,3

Now if you write a select query on this view it will be

SELECT ECODE,ENAME,MONTH_YEAR,NET_PAY FROM EMP_SAL_VIEW;

You can also use where clause in this view.

SELECT ECODE,ENAME,MONTH_YEAR,NET_PAY FROM EMP_SAL_VIEW
WHERE NET_PAY<=1000;

Sunday 11 May 2014

How to shutdown a Windows machine from command line.

Open command prompt.

1. To simply shutdown type
     shutdown -s

2.  To forcefully shutdown the machine (Close all application forcefully before shutdown)
     shutdown -f -s

3. To restart type
    shutdown -r

4. To forcefully restart the machine (Close all application forcefully before restart)
    shutdown -f -r

5.  To set countdown before shutting down your machine.
   
     shutdown -s -t 60  (60 is value in seconds if you want to shutdown after 1 hour value will be 3600)

6. To shutdown a machine remotely from another computer.

    shutdown -s -m \\computer name or ipaddress (Be sure the machine has permission to shutdown
    remotely.

Some useful shortcut key in Windows 7 and 8

1. To open, hide or show run dialog Press Windows key + R together.

2. To select any of the taksbar pinned program Press [Window + program position in taskbar] together.
    Say your Firefox is in 4th position from the left then press Window key + 4. If the program is running and
    in minimized state or not an active window then pressing this buttons will make it active window or
   maximized if it is minimized.

3. To open search window on a particular folder. Select the folder from the explorer and press
    Windows key + F.

4. To minimize all window press Window key + D.

5. I hope you know about the second screen window, it is used if you want to extend your monitor to a
    projector,  or make a duplicate screen to another monitor etc. To open the second screen window, press
    Window key + P.

6. To minimize all screen Press Window key + M.

7. To open the explorer window press Window key + E.

8. To open the start menu press Window key, or press Control key + Escape key.


How to add Quick Launch toolbar in Windows 8

Right click on empty space in task bar.

Go to Toolbar.
Select new toolbar from Toolbar submenu.
Set this path into select folder dialog

C:\Users\[You user folder]\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch
Click on Select Folder
You are all done.

Quick launch toolbar will be visible on right corner of the taskbar just left to the datatime.

How to start and stop Oracle database service in Linux.

You can do this task from both server and client.

1. If you do it from server then

  i. Make sure you are logged in as oracle user i.e. user which Oracle is installed and user who has all the
     rights.
 ii. Open terminal
iii. type sqlplus / as sysdba
iv. You will be logged in sql prompt. In the sql prompt just type startup. This will start your Oracle database
     service.
v.  type exit to exit from sql prompt.
vi. Now type service start lsnrctl. This will start your listener service.

You are all done.

2. If you are in  a client / remote machine then you need to have putty ssh client. Log in to oracle user
    through putty and do the same steps as mentioned above.

How to start and stop Oracle database service in Windows.

Suppose your instance name of Oracle is ORA.

You will be having 2 services which need to be started.

Step 1:
You can configure Windows service to start this service at startup, if it is not started.

  i. Press window key + R to open run dialog. type services.msc and press enter.
 ii. Search for service OracleServiceOra.
iii. Right click on it and click on properties from popup menu.
iv.From the startup type select Automatic if you want to start the service when windows start, or select
   manual if you want to start the service manually, this will save you windows loading time and save memory
  also.
v. Click on start button if you want to start the service now.
vi. Click on apply.
vii/ Search for Oracle[OracleHomeName]TNSListener (Oracle home name is your oracle installed path).
viii. Do the same process as you have done with OracleServiceORA.

Step 2.

If you have set your service as mentioned above to be started manually then you can use command prompt
to start your service.

  i.  Create a batch file named say StartOracleService.bat
 ii.  In the batch file add these following line.
      @echo off
       net start OracleServiceOra
       net start Oracle[OracleHomeName]TNSListener
       REM OracleHomeName is you Oracle installed path
       exit
iii.   To stop the service create a batch file named say StopOracleService.bat
       In the file add these following line.
      @echo off
       net stop OracleServiceOra
       net stop Oracle[OracleHomeName]TNSListener
       REM OracleHomeName is you Oracle installed path
       exit