ajit kumar nayak


{ City } bangalore
< Country > india
* Profession * software engineer
User No # 103755
Total Questions Posted # 7
Total Answers Posted # 19

Total Answers Posted for My Questions # 7
Total Views for My Questions # 20452

Users Marked my Answers as Correct # 17
Users Marked my Answers as Wrong # 0
Answers / { ajit kumar nayak }

Question { CTS, 4218 }

hi friends,
I have a table A
col as
status|NUM
and value as
open |1
open |2
close |3
close |3
the O/P should be
open|close
1 |3
2 |4


Answer

select decode ( status, 'open', num ) open,
decode ( status, 'close', num ) close
from A;

Is This Answer Correct ?    6 Yes 0 No

Question { 5152 }

I m giving Source, Destination and Age. Write a procedure or
function, it will give to u this source to destination
tickets are available or not, if available then check this
person is senior citizen or not,if this person is senior
citizen then give some discount.
PLZ give this answer......
Thanks advance.....


Answer

Hi Aritra, Kavitha,
Ur logic is correct, but it's not complete all point, where ur program is identify tickets are available or not then u program should calculate fare and all details.

Is This Answer Correct ?    0 Yes 0 No


Question { JPMorgan Chase, 10324 }

source destination distance
chennai bangalore 500
bangalore chennai 500
hyd delhi 1000
delhi hyd 1000
bangalore hyd 800

Here chennai to bangalore and bangalore to chennai is same distance. and hyd and delhi also same criteria.
Based on the distance i want to display only one row using sql query?


Answer

select distinct source,destination,distance from dist_tab where source > destination
minus
select distinct source,destination,distance from dist_tab where source < destination

Is This Answer Correct ?    0 Yes 0 No

Question { 2683 }

Hi Guys,

I have a situation where I need to access the column values from rowtype variable. However, the column names are dynamic.

below is sample code:
declare

Cursor c1 is select * from emp;
Cursor c2 is select column_name from xyztable;
v_c2 c2%rowtype;
v_str varchar2
v_value varchar2(200);

begin

for rec in c1
loop
open c2;---this cursor has column names like EMPLOYEE_ID, FIRST_NAME, LAST_NAME etc.
loop
fetch c2 into v_c2;
exit when c2%notfound;

/* now lets say i want to access value of LAST_NAME from cursor c1, so I am writing below code, however it does not work as expected */

v_str:= 'rec.'|| v_c2.column_name; -- this will give me string like "rec.EMPLOYEE_ID"

v_value:=v_str;



end loop;

end loop;



end;
/

Plz help ASAP.Thanks.


Answer

DECLARE
CURSOR C1 IS SELECT *
FROM DEPT;

CURSOR C2 IS SELECT *
FROM EMP;

v_c2 C2%ROWTYPE;
v_str VARCHAR2(30);
v_res VARCHAR2(35);

BEGIN
OPEN C2;

FOR REC IN C1
LOOP
FETCH C2 INTO v_c2;
EXIT WHEN C2%NOTFOUND;
v_str := 'REC'||v_c2.ENAME;
v_res := V_STR;
DBMS_OUTPUT.PUT_LINE('NAME'||v_c2.ENAME);
END LOOP;
CLOSE C2;
END;

Is This Answer Correct ?    1 Yes 0 No

Prev    1    [2]