June 2011

C - Question and Answers for Interview preparation

What is the output of the below programs?

1. #include

int main()
{
char *x="new";
char *y="dictonary";
char *t;
void swap (char * , char *);
swap (x,y);
printf("(%s, %s)",x,y);

t=x;
x=y;
y=t;
printf("-(%s, %s)",x,y);
}
void swap (char *x,char *y)
{
char *t;
y=x;
x=y;
y=t;
}

output: (new, dictonary)-(dictonary, new)

MySQL : How to get the process list or which threads are running currently?

To get the details on the threads running in the MySQL, use show processlist.

It will listout the threads which you have own. To see all the threads, use SUPER privileged login. mysqladmin processlist statement is equivalent of the show processlist.

Note: Each thread is an each connection. Each thread is associated with thread_id.

Linux / Unix - How to change the password?

You can change the password by issuing the passwd command, it will ask for old password, then new password two times to avoid typing mistake.

If you are a super user then can change password for other users. like passwd followed by user name.

DB2 Interview Questions - I

1. How do you eliminate duplicate values in SELECT?

Use SELECT DISTINCT

2. How would you find out total number of rows in a Table?

Use Select Count(*)

3. Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many time should i specify UNION to eliminate duplicate rows?

Once

C - Question Paper

What is the output the following program?

1)
main()
{
char *p1="name";
char *p2;
p2=(char*)malloc(20);
while(*p2++ = *p1++);
printf("%s\n",p2);
}

Ans:empty string.

Perl : Find and Replace in the multiple files using the Perl single line command

Do you know that we can use perl in command line to find some text/pattern in a single or multiple files and can replace it? If you doesn't know then just read this article to know more on it.

We can use single perl command line code to find and replace.

Example:

To find string "<--website-->" from files with extension html and replace it with itechp2pexchange.com.

Oracle: How to get the oracle version number?

To get the oracle version information, use the below query.

select * from v$version;

Which return oracle, PL/SQL version details.

Perl - How to check the syntax are correct without executing script?

You can check the perl script syntax errors without executing the script.

How?, Here is the way!

To test a scripts syntax without executing it, use -c option with perl.

perl -c testScript.pl

Oracle - TOAD - How to execute the precedure in the package?

1. Go to the schema browser -> package tab.
2. Right click on the package
3. select the package and expand it.
4. Right click, select the execute procedure.
5. Now Select the procedure which you want to execute.
6. Enter the input parameter and click ok to execute.

Linux / Unix : How to count the number of lines, words and characters in the file?

To count the number of lines, words and characters in the file, pipe cat with wc like below

$cat fruits_colors.txt | wc

10 30 150

first one is number of lines.
second one is number of words.
third one is number of characters.

Oracle: How to find the object (table, index, package, procedure,trigger, sequence) exists or not?

To find out the object exists or not , we can query the user_object table and get it.

Example 1: To check EMP_TABLE exists or not, if exists then it will return 1

select count(1) from user_objects where object_name='EMP_TABLE';

Example 2: To check index exists or not.

select count(1) from user_objects where object_name='EMP_NO_INDEX';

Vim: How to move to start and end of the file or particular line of the file?

Shortcut keys to move between lines in the vim.

G - to move to end of the file.
gg - to move to start of the file
Ctrl+g - display the current line number and total number of lines
:number - to move particular line.
Shift+$ - to move to the end of the line.
Shift+^ - to move to start of the line.

How to remove the event attached with the element using unbind ?

Do you binded the event with elements and after performing some operation, you don't want that event handler execute. How to do that?

jQuery has unbind to remove the event linked with particular element.

Oracle : How to execute sql file?

You can execute the sql command file in SQL prompt. To perform this, use @ followed by file name.

For example: You have sql commands in the file called a.sql then to execute this

SQL> @a.sql

How to assign css styles for form elements or remove from the css?

The elements have style sheet and you want to remove that how to do that?

To assign or remove the styles for the elements, you can use jQuery css. The property and value is passed to css function as comma seperated.

Linux / Unix : How to see our own uid, gid and other's?

We normally get the user and group details from /etc/passwd. Instead of open and see the details from /etc/passwd, we can use id command to get the details.

Mysql - How to execute the sql file in mysql prompt?

Having sql commands in the file and want to execute it in mysql prompt? To execute the sql file in sql prompt, you can use source or /. command.

For example you have staff.sql file and want to execute it.

mysql> source staff.sql
or

mysql> /. staff.sql

It will display the output of the commands.

Oracle: How to store the output of the SQL in the file?

Want to store the output of the commands in the file and to refer it future? You can do it in sql prompt.

To do this use SPOOL command.

For example, you want to store the output in the a.out file then

SQL> SPOOL a.out
SQL>@a.sql
SQL> Select * from company;
SQL> spool off

To stop write the output of the sql commands to file, use spool off command.

PHP - Difference between echo and print?

echo :
* Language constuct and behaves like statement. It won't return value.
* echo takes multiple parameter seperated by commas.
* Faster than print.

print:
* Language construct and behaves like function. It return true / false.
* print is part of precedence table.
* print take only one parameter.

DB2 Interview Questions - II

1. Why SELECT * is not preferred in embedded SQL programs?

1. If the table structure is changed, the program will have to be modified.

2. Program might retrieve the columns which it might not use, leading on I/O over head.

3. The chance of an Index scan only is lost.