P. 1
80902365-Imp-Queries

|Views: 4|Likes:
imp queries
imp queries

See more
See less

06/13/2013

pdf

text

original

# INDEX 1. Query for retrieving N highest paid employees FROM each Department. I select empsal,e1.

deptno from emp e1 where :n = (select count(distinct empsal) from emp e2 where e2.empsal >= e1.empsal and e2.deptno = e1.deptno ) 2. Query that will display the total no. of employees, and of that total the number who were hired in 1980, 1981, 1982, and 1983. II select to_char(join_date,'YYYY') Year,count(*) from emp group by to_char(join_date,'YYYY') 3. Query for listing Deptno, ename, sal, SUM(sal in that dept). III select deptno ,empname ,empsal ,(select sum(empsal) from emp where deptno = e1.deptno) Sum from emp e1 4. Matrix query to display the job, the salary for that job based on department number, and the total salary for that job for all departments. IV 5. Nth Top Salary of all the employees. V select empsal,e1.deptno from emp e1 where :n = (select count(distinct empsal) from emp e2 where e2.empsal >= e1.empsal ) 6. Retrieving the Nth row FROM a table. VI select * from emp where rownum < :n+1 minus select * from emp where rownum < :n 7. Tree Query. VII 8. Eliminate duplicates rows in a table. VIII 9. Displaying EVERY Nth row in a table. IX 10. Top N rows FROM a table. X 11. COUNT/SUM RANGES of data values in a column. XI 12. For equal size ranges it might be easier to calculate it with DECODE(TRUNC(value/range), 0, rate_0, 1, rate_1, ...). XII 13. Count different data values in a column. XIII

Query to list all the suppliers who r supplying all the parts supplied by supplier 'S2'. XXIII 24. XXX 31. Spool only the query result to a file in SQLPLUS. Query to SELECT last N rows FROM a table. XXVII 28. Query to get the DB Name. XV 16. XX select DECODE(mod(to_number(:Year1).0 . Function for getting the Element Value. Function for displaying Rupees in Words.4) .:Year1||' . Query to get the product of all the values of a column. Query for getting the following output as many number of rows in the table. Query to display only the duplicate records in a table. XXXIV 35. Function to check for a leap year. Query to get the last Sunday of any month. XXXVI 37. XXXI 32. XXXVII . Query to get all the column names of a particular table. Procedure for sending Email. XXIX 30. Getting the current default schema. XXV 26. XVIII 19. Alternate Query for DECODE function. Function for getting the Balance Value. SELECT Query for counting No of words. Query to get all those who have no children themselves.14. XVII 18. XVI 17. XXVIII 29. Query for translating a column values to INITCAP. XXXIII 34.Leap Year' .:Year1||' . Query for removing all non-numeric. XXII 23. XIV 15. XXVI 27. XXXV 36. XIX 20. Create table adding Constraint to a date field to SYSDATE or 3 months later. Query for deleting alternate even rows FROM a table. XXI 22. XXIV 25. Query for deleting alternate odd rows FROM a table.Not Leap Year' ) Leap from dual 21. XXXII 33. SELECT with variables.

XXXXXIV . XXXXVII 48. XXXXXIII 54. XXXXI 42. Query for getting the current SessionID. Concatenate a column value with multiple rows. Query to get the first inserted record FROM a table. XXXXX 51. Create Query to restrict the user to a single row. Time difference between two date columns. Procedure to read/write data from/to a text file. sub children of a parent. SQL Query for getting Orphan Records. XXXXXII 53. XXXIX 40. XXXXVI 47. Query to count no. Query to display random number between any two given numbers. XXXX 41. Query to display rows FROM m to n. Inserting an & symbol in a Varchar2 column. XXXVIII 39. Samples for executing Dynamic SQL Statements. XXXXII 43. XXXXV 46. Procedure to increase the buffer length. XXXXIX 50. Of columns in a table. XXXXVIII 49.38. Differences between SQL and MS-Access. Query to display all the children. XXXXIV 45. Query to delete all the tables at once. XXXXIII 44. XXXXXI 52. Removing Trailing blanks in a spooled file.

COUNT(DECODE(TO_CHAR (hiredate. COUNT (DECODE (TO_CHAR (hiredate.3 DESC. empno)) "1980". 'YYYY'). 1982. (The following query retrieves "2" highest paid employees FROM each Department : SELECT deptno. '1982'. empno)) "1981". COUNT (DECODE (TO_CHAR (hiredate. 'YYYY'). sal FROM emp e WHERE 2 > ( SELECT COUNT(e1. of employees.'1980'. Query that will display the total no.deptno AND e.I. empno. We need to stick to this format.sal ) ORDER BY 1.sal) FROM emp e1 WHERE e. 1981. '1981'. Total ----------14 1980 -----------1 1981 -----------10 1982 ------------2 1983 ----------1 SELECT COUNT (*).deptno = e1. 'YYYY'). and of that total the number who were hired in 1980. empno)) "1982". I am looking at the following output. . Give appropriate column headings. and 1983. Index II.sal < e1.

'YYYY'). '1983'. empno)) "1983" FROM emp. sal. The output is as follows . ename.deptno) FROM emp a ORDER BY a.COUNT (DECODE (TO_CHAR (hiredate. SUM (DECODE (deptno. SUM (DECODE (deptno. the salary for that job based on department number. (SELECT SUM(sal) FROM emp b WHERE a. sal)) "Dept 20".deptno = b.deptno. 30. sal. ename. sal)) "Dept 30". 10. giving each column an appropriate heading. SUM (sal) "Total" FROM emp GROUP BY job . Index III.deptno. sal)) "Dept 10". 4 Top Salary of all the employees : . Index th V. SUM (DECODE (deptno.we need to stick to this format : Job ---------ANALYST CLERK MANAGER PRESIDENT SALESMAN Dept 10 --------------1300 2450 5000 Dept 20 ------------6000 1900 2975 Dept 30 ------------950 2850 5600 Total --------6000 4150 8275 5000 5600 ENAME SAL ======= ==== KING 5000 BLAKE 2850 CLARK 2450 JONES 2975 MARTIN 1250 ALLEN 1600 TURNER 1500 JAMES 950 WARD 2750 SMITH 8000 SCOTT 3000 MILLER 20000 SUM (SAL) ========= 11725 10900 11725 11725 10900 10900 10900 10900 10900 33000 33000 33000 SELECT job "Job". OUTPUT : ======= DEPTNO ========= 10 30 10 10 30 30 30 30 30 20 20 20 Index IV. 20. and the total salary for that job for all departments. SUM(sal in that dept) : SELECT a. Create a matrix query to display the job. Query for listing Deptno.

ENAME. Index VIII. Top N rows FROM a table : (Displays top 9 salaried people) . Index VI. Eliminate duplicates rows in a table : DELETE FROM table_name A WHERE ROWID > ( SELECT min(ROWID) FROM table_name B WHERE A.SAL) FROM EMP B WHERE A. Retrieving the 5th row FROM a table : SELECT DEPTNO. Index IX. MOD(ROWNUM. SAL FROM EMP A WHERE 3 = (SELECT COUNT(B.0) IN (SELECT ROWID.2) SELECT sub.col = B. Index X.4) FROM emp).SAL) ORDER BY SAL DESC.SAL < B. Tree Query : Name Null? Type ------------------------------------------------------------------SUB NOT NULL VARCHAR2(4) SUPER VARCHAR2(4) PRICE NUMBER(6.8. Displaying EVERY 4th row in a table : (If a table has 14 rows.SELECT DEPTNO. super FROM parts CONNECT BY PRIOR sub = super START WITH sub = 'p1'. 4. ENAME.12 rows will be selected) SELECT * FROM emp WHERE (ROWID.col). SAL FROM EMP WHERE ROWID = (SELECT ROWID FROM EMP WHERE ROWNUM <= 5 MINUS SELECT ROWID FROM EMP WHERE ROWNUM < 5) Index VII.

0. 0. 0. rate_1. Query to get the product of all the values of a column : SELECT EXP(SUM(LN(col1))) FROM srinu. SUM(DECODE(sex. SELECT f2.). 1. 0)) "Range 30-59". 59). 1. XIII. Index XI. COUNT(DECODE(greatest(f1. COUNT(DECODE(greatest(f1.. 0.0)) MALE.0. 0)) "Range 00-29" FROM my_table GROUP BY f2. sal "Salary".59).1)) TOTAL FROM t1 GROUP BY dno. y) = LEAST(x. 1. 0.30). 1. 0. 0).1. SUM(DECODE(sex.1. How does one count different data values in a column? COL NAME DATATYPE ---------------------------------------DNO NUMBER SEX CHAR SELECT dno. 0). deptno.100).3) "Tax rate" FROM emp. Index XII.2..'F'. COUNT(DECODE(sex. 1. . COUNT(DECODE(greatest(f1. least(f1. 3.29).1. Index XV. 2. Query to display only the duplicate records in a table: SELECT num FROM satyam GROUP BY num . For equal size ranges it migth be easier to calculate it with DECODE(TRUNC(value/range). least(f1. sal FROM (SELECT * FROM emp ORDER BY sal DESC) WHERE ROWNUM < 10. Index XIV.1.SELECT ename. z). rate_0. least(f1.'M'.'M'. DECODE( TRUNC(sal/1000.'F'. 0)) "Range 60-100".0)) FEMALE. How does one count/sum RANGES of data values in a column? A value x will be between values y and z if GREATEST(x. SELECT ename "Name".

get_value(l_defined_bal_id.'*'). pay_balance_dimensions pbd WHERE pbt.HAVING COUNT(*) > 1. l_defined_bal_id number. Query for getting the following output as many number of rows in the table : * ** *** **** ***** SELECT RPAD(DECODE(temp. pay_defined_balances pdb.balance_dimension_id = pbd.balance_type_id = pdb. SELECT defined_balance_id INTO l_defined_bal_id FROM pay_balance_types pbt.ROWNUM. Function for getting the Balance Value : FUNCTION F_BALANCE_VALUE (p_business_group_id number. p_balance_name varchar2. . Index XVII. BEGIN SELECT assignment_action_id INTO l_assignment_action_id FROM pay_assignment_actions WHERE assignment_id = :p_assignment_id AND payroll_action_id = p_payroll_action_id.business_group_id AND pbt. RETURN (l_bal). l_bal := pay_balance_pkg.business_group_id = pdb.balance_name) = UPPER(p_balance_name) AND pbt.balance_type_id AND UPPER(pbd.l_assignment_action_id).business_group_id = p_business_group_id AND UPPER(pbt. p_payroll_action_id number. Index XVI.'*') FROM srinu1. l_assignment_action_id number.temp. p_dimension_name varchar2) RETURN NUMBER IS l_bal number.dimension_name) = UPPER(p_dimension_name) AND pdb.balance_dimension_id.

RETURN (l_element_value).run_result_id = prr.0) INTO l_element_value FROM pay_run_result_values prrv.exception WHEN no_data_found THEN RETURN 0.assignment_action_id AND paa.classification_id = pec. BEGIN SELECT DISTINCT element_type_id INTO l_element_type_id FROM pay_element_types_f pet.payroll_action_id = p_payroll_action_id.2) default 0.assignment_ACTION_ID = paa.input_value_id%type. Index XVIII. p_payroll_action_id in number.assignment_id = p_assignment_id AND input_value_id = l_input_value_id AND paa. SELECT input_value_id INTO l_input_value_id FROM pay_input_values_f WHERE upper(name) = upper(p_input_value_name) AND element_type_id = l_element_type_id. p_input_value_name in varchar2.element_type_id%type.run_result_id AND prr.classification_id AND upper(classification_name) = upper(p_classification_name) AND upper(element_name) = upper(p_element_name) AND pet. . END. exception WHEN no_data_found THEN RETURN 0. Function for getting the Element Value : FUNCTION f_element_value( p_classification_name in varchar2. p_business_group_id in number.result_value. END. pay_run_results prr. p_element_name in varchar2. l_element_type_id pay_element_types_f.business_group_id = p_business_group_id. p_assignment_id in number ) RETURN number IS l_element_value number(14. SELECT NVL(prrv. pay_assignment_actions paa WHERE prrv. pay_element_classifications pec WHERE pet. l_input_value_id pay_input_values_f.

This will replace every space with nothing in the above result. SQL> SELECT hiredate.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'' '.' @').''))+1 -. Index XXI.This will translate all the characters FROM A-Z including a single quote to a space.' '.'DD-Mon-YYYY').' @').This will give u the count of @ characters in the above result. 'Day') weekday FROM emp WHERE is_leap_year (hiredate) = 'Y'.' @'). It will also translate a space to a @. LENGTH(REPLACE(TRANSLATE(UPPER(RTRIM(ename)).'') FROM DUAL. SELECT Query for counting No of words : SELECT ename. END is_leap_year.Index XIX. Explanation : TRANSLATE(UPPER(RTRIM(ename)).'. Query for removing all non-numeric : SELECT TRANSLATE(LOWER(ssn). Query for translating a column values to INITCAP : SELECT .'') -. Index XXII. BEGIN v_test := TO_DATE ('29-Feb-' || TO_CHAR (p_date.'abcdefghijklmnopqrstuvwxyz.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'' '.1) word_length FROM emp. EXCEPTION WHEN OTHERS THEN RETURN 'N'. REPLACE(TRANSLATE(UPPER(RTRIM(ename)). NVL(LENGTH(REPLACE(TRANSLATE(UPPER(RTRIM(ename)).' @') -. RETURN 'Y'.' '. TO_CHAR (hiredate.'YYYY'). Index XX.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'' '.' '. Function to check for a leap year : CREATE OR REPLACE FUNCTION is_leap_year (p_date IN DATE) RETURN VARCHAR2 AS v_test DATE.'ABCDEFGHIJKLMNOPQRSTUVWXY Z'' '.''))+1.

3).2). BEGIN IF ((amount = 0) OR (amount IS NULL)) THEN v_word := 'zero'. v_word VARCHAR2 (4000) := NULL. v_word1 := ' AND ' || (TO_CHAR (TO_DATE (SUBSTR (v_num2. v_amount := SUBSTR(amount. INSTR (amount. '. '999999999') . ' '. v_str myarray := myarray (' Thousand '. INSTR(temp.1).'''')+1))) FROM srinu1. v_word := v_word || ' ' || v_word1 || ' only '. v_amount := SUBSTR (v_amount. v_word := TO_CHAR (TO_DATE (SUBSTR (v_amount. LENGTH (v_amount) . END IF.1. LOWER(SUBSTR(temp. '. ' Lakh '. ELSIF (TO_CHAR (amount) LIKE '%. SUBSTR(temp. LENGTH (v_amount) .') + 1). v_amount := SUBSTR (v_amount. LENGTH (v_amount) . 'JSP' ))|| ' paise '.') + 1) > 0) THEN v_num2 := SUBSTR (amount. RETURN INITCAP (v_word). Function for displaying Rupees in Words : CREATE OR REPLACE FUNCTION to_word_i (amount IN NUMBER) RETURN VARCHAR2 AS v_length INTEGER := 0. v_word := REPLACE (RTRIM (v_word).2). v_amount VARCHAR2 (50) := TO_CHAR (TRUNC (amount)). v_str. 'JSP'). 'Jsp' ) || v_str (i) || v_word. 1.1. Index XXIII.1. INSTR(temp. '. '-'.'''')+1. v_word := TO_CHAR (TO_DATE (SUBSTR (v_amount. END IF.2.TRANSLATE(INITCAP(temp). IF (LENGTH (v_num2) < 2) THEN v_num2 := v_num2 * 10. 1.%') THEN IF (SUBSTR (amount. TYPE myarray IS TABLE OF VARCHAR2 (255). ' Crore '). v_word1 VARCHAR2 (4000) := NULL. ELSE v_word := TO_CHAR ( TO_DATE ( TO_CHAR ( amount. END IF. LENGTH (v_amount) .3). INSTR (amount. LENGTH (v_num2) . ' ').2). ' '). 'J').. END LOOP. FOR i in 1 . 'J'). v_word := REPLACE (RTRIM (v_word). 'J').INSTR (amount.COUNT LOOP EXIT WHEN (v_amount IS NULL). .')-1). 'Jsp' ) || v_word. v_num2 VARCHAR2 (50) := NULL. 'J').

Index XXV.. utl_smtp. lv_crlf || message). END.END to_word_i. subject VARCHAR2(100) := 'Test Message'.write_data ( l_mail_conn. utl_smtp. Index XXVI. Query for deleting alternate even rows FROM a table : DELETE FROM srinu WHERE (ROWID.PUT_LINE('Error'). message VARCHAR2(1000) := 'This is a sample mail .connection.write_data ( l_mail_conn. utl_smtp.mail ( l_mail_conn. l_mail_conn utl_smtp. / Index XXVII. Index XXIV.open_connection (lv_mailhost..write_data ( l_mail_conn.quit(l_mail_conn). MOD(ROWNUM. lv_mailhost). sender). Alternate Query for DECODE function : . recipient).rcpt ( l_mail_conn. utl_smtp. Procedure for sending Email : CREATE OR REPLACE PROCEDURE Send_Mail IS sender VARCHAR2(50) := 'sender@something.com'. lv_mailhost VARCHAR2(30) := 'HOTNT002'.0) IN (SELECT ROWID. 'To: ' || recipient || lv_crlf).'. 'Subject:' || subject || lv_crlf). recipient VARCHAR2(50) := 'recipient@something.close_data(l_mail_conn).com'. utl_smtp. 'FROM: ' || sender || lv_crlf). MOD(ROWNUM. utl_smtp. Query for deleting alternate odd rows FROM a table : DELETE FROM srinu WHERE (ROWID. utl_smtp.2) FROM srinu). lv_crlf VARCHAR2(2):= CHR( 13 ) || CHR( 10 ). utl_smtp. utl_smtp..write_data ( l_mail_conn. EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.1) IN (SELECT ROWID. utl_smtp.helo ( l_mail_conn.open_data (l_mail_conn). BEGIN l_mail_conn := utl_smtp. 80).2) FROM srinu).

3))). .SELECT case WHEN sex = 'm' THEN 'male' WHEN sex = 'f' THEN 'female' ELSE 'unknown' END FROM mytable.SUPP HAVING COUNT(DISTINCT a. Table : orders SUPP PARTS -------------------.supp != 'S2' AND a.PARTS) >= (SELECT COUNT(DISTINCT PARTS) FROM ORDERS WHERE supp = 'S2').------S1 P1 S1 P2 S1 P3 S1 P4 S1 P5 S1 P6 S2 P1 S2 P2 S3 P2 S4 P2 S4 P4 S4 P5 Index XXX. dt2 date. Index XXVIII.'sunday') FROM DUAL. Query to get the last Sunday of any month : SELECT NEXT_DAY(LAST_DAY(TO_DATE('26-10-2001'.'DD-MM-YYYY')) . Query to list all the suppliers who supply all the parts supplied by supplier 'S2' : SELECT DISTINCT a.SUPP FROM ORDERS a WHERE a. Index XXIX. CONSTRAINT check_dt2 CHECK ((dt2 >= dt1) AND (dt2 <= ADD_MONTHS(SYSDATE.parts IN (SELECT DISTINCT PARTS FROM ORDERS WHERE supp = 'S2') GROUP BY a.7. Create table adding Constraint to a date field to SYSDATE or 3 months later: CREATE TABLE srinu(dt1 date DEFAULT SYSDATE.

xQuery varchar2(100). Index XXXII.PUT_LINE(xQuery).a child of 1 3 c 1 4 d 2 . SELECT with variables: CREATE OR REPLACE PROCEDURE disp AS xTableName varchar2(25):='emp'. END. EXECUTE IMMEDIATE xQuery INTO xValue. xFieldName varchar2(25):='ename'. DBMS_OUTPUT.a child of 2 5 e 2 6 f 3 7 g 3 8 h 4 9 i 8 10 j 9 SELECT ID FROM MY_TABlE WHERE PARENT_ID IS NOT NULL MINUS SELECT PARENT_ID FROM MY_TABlE.PUT_LINE(xValue).Index XXXI. Index XXXIII. Query to get all those who have no children themselves : table data : id name parent_id ------------------------------1 a NULL . Query to SELECT last N rows FROM a table : SELECT empno FROM emp WHERE ROWID in (SELECT ROWID FROM emp MINUS SELECT ROWID FROM emp WHERE ROWNUM <= (SELECT COUNT(*)-5 FROM emp)). BEGIN xQuery := 'SELECT SAL FROM ' || xTableName || ' WHERE ' || xFieldName || ' = ''' || name || ''''. . DBMS_OUTPUT. xValue NUMBER. name varchar2(10) := 'CLARK'.the top level entry 2 b 1 .

Index XXXIX. Query for getting the current SessionID : SELECT SYS_CONTEXT('USERENV'.Index XXXIV. /* Write your Query here */ spool off / Index XXXVIII. Index XXXVII. Query to get all the column names of a particular table : SELECT column_name FROM all_tab_columns WHERE TABLE_NAME = 'ORDERS'. SAL FROM EMP WHERE ROWID IN (SELECT ROWID FROM EMP WHERE ROWNUM <= 7 MINUS SELECT ROWID FROM EMP . How do I spool only the query result to a file in SQLPLUS : Place the following lines of code in a file and execute the file in SQLPLUS : set heading off set feedback off set colsep ' ' set termout off set verify off spool c:\srini. Query to get the DB Name: SELECT name FROM v\$database.'CURRENT_SCHEMA') FROM DUAL. Index XXXV. Index XXXVI.ename FROM emp.txt SELECT empno.'SESSIONID') Session_ID FROM DUAL. Query to display rows FROM m to n : To display rows 5 to 7 : SELECT DEPTNO. Getting the current default schema : SELECT SYS_CONTEXT('USERENV'. ENAME.

How to concatenate a column value with multiple rows : . Query to count no. END.enable(4000). Query to get the first inserted record FROM a table : Index XXXXV.PUT_LINE(i). ename HAVING ROWNUM > 1 and ROWNUM < 3. set define '~' Index XXXXIII. Create Query to restrict the user to a single row : Index XXXXIV. / Index XXXXII. Of columns in a table: SELECT COUNT(column_name) FROM user_tab_columns WHERE table_name = 'MYTABLE'. Index XXXX. Procedure to increase the buffer length : dbms_output.enable(4000). Inserting an & symbol in a Varchar2 column : Set the following to some other character. FOR i IN 1. END LOOP. OR SELECT ename FROM emp GROUP BY ROWNUM.WHERE ROWNUM < 5)..400 LOOP DBMS_OUTPUT. Index XXXXI. By default it is &. /*allows the output buffer to be increased to the specified number of bytes */ DECLARE BEGIN dbms_output.

EXECUTE IMMEDIATE sql_stmt USING dept_id.'. sql_stmt := 'INSERT INTO dept VALUES (:1.raise_salary(:id.PUT_LINE('Total No. Samples for executing Dynamic SQL Statements : Sample :1 CREATE OR REPLACE PROCEDURE CNT(P_TABLE_NAME IN VARCHAR2) AS SqlString VARCHAR2(200). emp_id NUMBER(4) := 7566.Of Records In ' || P_TABLE_NAME || ' ARE=' || tot). . BEGIN EXECUTE IMMEDIATE 'CREATE TABLE bonus (id NUMBER. END. EXECUTE IMMEDIATE SqlString INTO tot. Sample :2 DECLARE sql_stmt VARCHAR2(200). sql_stmt := 'SELECT * FROM emp WHERE empno = :id'. EXECUTE IMMEDIATE plsql_block USING 7788. tot number. location VARCHAR2(13) := ’DALLAS’.Index XXXXVI. :amt). 500.2). sql_stmt := 'UPDATE emp SET sal = 2000 WHERE empno = :1 RETURNING sal INTO :2'. salary NUMBER(7. plsql_block := 'BEGIN emp_pkg. dept_id NUMBER(2) := 50. dept_name. SQL Query for getting Orphan Records : Index XXXXVIII. EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id. emp_rec emp%ROWTYPE. DBMS_OUTPUT. :3)'. BEGIN SqlString:='SELECT COUNT(*) FROM '|| P_TABLE_NAME. END. location. plsql_block VARCHAR2(500). amt NUMBER)'. dept_name VARCHAR2(14) := ’PERSONNEL’. :2. How do you remove Trailing blanks in a spooled file : Change the Environment Options Like this : set trimspool on set trimout on Index XXXXIX. Query to delete all the tables at once : Index XXXXVII.

PUT_LINE('Deptartment name: '||v_dname). DBMS_SQL. ':x'. END.PARSE(v_cursor. EXECUTE IMMEDIATE 'DELETE FROM dept WHERE deptno = :num' USING dept_id. Difference 2: Access: SELECT TOP 2 name FROM Table1. DBMS_OUTPUT.COLUMN_VALUE_CHAR(v_cursor.EXECUTE IMMEDIATE sql_stmt USING emp_id RETURNING INTO salary. v_dname char(20).CLOSE_CURSOR(v_cursor).OPEN_CURSOR. Sample 3 CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT. DBMS_SQL. Oracle : will not work there is no such TOP key word. 20). v_rows := DBMS_SQL. v_dname).DEFINE_COLUMN_CHAR(v_cursor. Query to display all the children.name FROM hr_all_organization_units WHERE organization_id in ( SELECT ORGANIZATION_ID_CHILD FROM PER_ORG_STRUCTURE_ELEMENTS . 'select dname from dept where deptno > :x'. Access: select name from table1 where name like 'k*'.DEPTNO%TYPE) AS v_cursor integer. DBMS_SQL.CLOSE_CURSOR(v_cursor). END LOOP. EXCEPTION WHEN OTHERS THEN DBMS_SQL. BEGIN v_cursor := DBMS_SQL. Differences between SQL and MS-Access : Difference 1: Oracle : select name from table1 where name like 'k%'. sub children of a parent : SELECT organization_id. DBMS_SQL. END IF. 1.V7).EXECUTE(v_cursor). 'Unknown Exception Raised: '||sqlcode||' '|| sqlerrm). v_dname. raise_application_error(-20000. DBMS_SQL. LOOP IF DBMS_SQL. Index XXXXX. v_rows integer. DBMS_SQL. 1. Index XXXXXI. END. no).BIND_VARIABLE(v_cursor. EXECUTE IMMEDIATE ’ALTER SESSION SET SQL_TRACE TRUE’.FETCH_ROWS(v_cursor) = 0 THEN EXIT.

v_buffer).c_file_name.CONNECT BY PRIOR ORGANIZATION_ID_CHILD = ORGANIZATION_ID_PARENT START WITH ORGANIZATION_ID_CHILD = (SELECT organization_id FROM hr_all_organization_units WHERE name = 'EBG Corporate Group')).GET_LINE(v_file_id.file_type.PUT_LINE(v_file_id.FCLOSE(v_file_id).FCLOSE(v_file_id). How can I get the time difference between two date columns : SELECT FLOOR((date1-date2)*24*60*60)/3600) || ' HOURS ' || FLOOR((((date1-date2)*24*60*60) FLOOR(((date1-date2)*24*60*60)/3600)*3600)/60) || ' MINUTES ' || ROUND((((date1-date2)*24*60*60) FLOOR(((date1-date2)*24*60*60)/3600)*3600 (FLOOR((((date1-date2)*24*60*60) FLOOR(((date1-date2)*24*60*60)/3600)*3600)/60)*60))) || ' SECS ' time_difference FROM my_table.'w'). Index XXXXXIV. DBMS_OUTPUT. END. Procedure to read/write data from a text file : CREATE OR REPLACE PROCEDURE read_data AS c_path varchar2(100) := '/usr/tmp'.PUT_LINE(v_buffer). v_file_id := UTL_FILE. UTL_FILE. UTL_FILE. / Index XXXXXIII. Index XXXXXII.2) FROM DUAL.VALUE (1. c_file_name varchar2(20) := 'EKGSEP01. v_file_id utl_file.CSV'. Query to display random number between any two given numbers : SELECT DBMS_RANDOM. UTL_FILE. BEGIN v_file_id := UTL_FILE. v_buffer).FOPEN(c_path. UTL_FILE. Index . v_buffer varchar2(1022) := This is a sample text’.'r').FOPEN(c_path.c_file_name.

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->