ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Databases  >>  SQL PLSQL
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
How to get the 3rd column(i.e all the data along with the 
column name)in a table?
 Question Submitted By :: Dibya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to get the 3rd column(i.e all the data along with the column name)in a table?
Answer
# 1
This is the common solution for any table

Run the following Function and fire the follwoing query



CREATE OR REPLACE FUNCTION fnSpecificcol(p_tablename IN 
VARCHAR2,                                    
                                    p_columnid IN number,
                                    P_ROWID    IN Varchar2) 
RETURN VARCHAR2

AUTHID CURRENT_USER AS
  TYPE c_refcur IS REF CURSOR;

  lc_str     VARCHAR2(4000);
  out_char   varchar2(50);
  lc_colval  VARCHAR2(4000);
  tmp_strSQL varchar2(400);

  c_dummy c_refcur;

  l number;

BEGIN

  tmp_strSQL := 'select column_name from user_tab_cols a ' 
||
                'where upper(table_name)=' || '''' || 
p_tablename || '''' ||
                ' and column_id=' || p_columnid;
  OPEN c_dummy FOR tmp_strSQL;

  LOOP
  
    FETCH c_dummy
      INTO lc_colval;
  
    EXIT WHEN c_dummy%NOTFOUND;
  
    lc_str := lc_str || lc_colval;
  
  END LOOP;

  CLOSE c_dummy;

  tmp_strSQL := '';
  tmp_strSQL := 'select ' || lc_str || ' from ' || 
p_tablename ||
                ' A WHERE A.ROWID=' || '''' || P_ROWID 
|| '''';
  lc_str     := '';
  lc_colval  := '';
  OPEN c_dummy FOR tmp_strSQL;

  LOOP
  
    FETCH c_dummy
      INTO lc_colval;
  
    EXIT WHEN c_dummy%NOTFOUND;
  
    lc_str := lc_str || lc_colval || CHR(13);
  
  END LOOP;

  CLOSE c_dummy;

  RETURN SUBSTR(lc_str, 1);

EXCEPTION

  WHEN OTHERS THEN
  
    lc_str := SQLERRM;
  
    IF c_dummy%ISOPEN THEN
    
      CLOSE c_dummy;
    
    END IF;
  
    RETURN lc_str;
  
END;




SELECT fnSpecificcol('Tablename', ColumnNumber,A.ROWID) 
from Tablename A

eg
SELECT rowtocol('AA', 1,A.ROWID) from aa A
 
Is This Answer Correct ?    1 Yes 1 No
P.rajasekar
 

 
 
 
Other SQL PLSQL Interview Questions
 
  Question Asked @ Answers
 
what is Hash join?how it is different from inner join?what is the sign used for inner join?(eg: like the (+) sign used for outer join)? TCS1
hi this is nakka i have been looking for 1+ exp in oracle sql,plsql developer positions also have knoledge on d2k i am not getting proper walkins how to know it? where can i find it?  1
How to recompile a already made trigger?  2
why sql is used as interpreter frequently rather than a compile?  1
how will u find statistics of a database objects? iFlex1
what is the difference between the query and corelated query IBM6
Differentiate between %type and %rowtype attribute in Oracle PL/AQL programming ? PreVator4
SELECT flavor, SUM (ice_cream_sales) FROM sales_detail GROUP BY flavor ORDER BY 2 DESC If the "sales_detail" table contains ten records with different values in the flavor column (two "vanilla," three "chocolate," four "strawberry," and one NULL), how many rows are returned by the sample code above? 1. 0 rows 2. 1 row 3. 3 rows 4. 4 rows 5. 10 rows Sonata7
State the difference between implict and explict cursor's?  6
Given two tables Student(SID, Name, Course) and Level(SID, level) write the SQL statement to get the name and SID of the student who are taking course = 3 and at freshman level. Oracle6
What is the fastest way of accessing a row in a table? TCS2
What is a self join ? BirlaSoft5
How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". It consists of multiple columns. Then if we insert rows into this table with duplicate records then how can we retrieve only duplicate records from that table? Wipro16
SELECT category, type, AVG(price) FROM products GROUP BY category, type ORDER BY 1, 2 If there are three distinct categories in the "products" table, and each one has five different types, how many rows are returned by the query above? 1. 1 row 2. 3 rows 3. 5 rows 4. 8 rows 5. 15 rows  1
hi sql gurus, here is my question 4 u. i wanna use triggers for sending reminder mail to all users who are registered to the site. if any one knws the code plz send me ans here : chayabs3@gmail.com thnx advance  1
declare v_count number(8,3); v_sal scott.emp.sal%type := '&P_sal'; cursor cur_name is select sal from scott.emp where sal between (v_sal-100) and (v_sal +1000); begin v_count :=nvl(sql%rowcount ,0); if v_count = 0 then dbms_output.put_line('no records are fetch in the given sal range'); else dbms_output.put_line('There is/are '||to_char(v_count)|| ' salaries are selected in the given range '); end if; end; in the above programm .....for any sal range ....always it shows the following message.. no records are fetch in the given sal range please find the mistake and share with me...with thansk and regards..sarao.... Satyam2
Hello All, Could any well write a query for the following scenario. Account(table name) No Name Amount 1 ABCD 2000.00 2 DEFG -2000.00 3 GHIJ 3000.50 4 JKLM 4000.00 5 MNOP 6000.00 O/p Should be in this format No Name Credit Debit 1 ABCD 2000.00 0 2 DEFG 0 -2000.00 3 GHIJ 3000.50 4 JKLM 0 -4000.00 5 MNOP 6000.00 o could any one give appropriate query for this Thnks in Advance Suneel Reddy Target4
What is the default value of CHAR type? Bosch1
What is the basic structure of PL/SQL ?  5
what is meant by DML? HCL5
 
For more SQL PLSQL Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com