SQL, PL-SQL, and Java Programming Quiz
Test your knowledge of database programming with SQL and PL-SQL, and object-oriented programming concepts in Java including constructors, inheritance, casting, and access modifiers.
Questions
Which of the following queries can be used to delete duplicate records from a table -
- delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
- delete from table_name where rowid in (select max(rowid) from table group by duplicate_values_field_name);
- c)delete from table_name where rowid not in (select max(rowid) from table);
- delete from table_name where rowid not in (select rowid from table group by duplicate_values_field_name);
Which statement selects the odd number of records :
- select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
- select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp);
- select * from emp where (rowid,1) in (select rowid, mod(rownum,1) from emp);
- select * from emp where (rowid,1) in (select rowid, mod(rownum,3) from emp);
1)SELECT bus_name, profit 2) FROM business 3) WHERE city = 4) (SELECT city FROM locations 5) WHERE city LIKE 'Noid_' 6) AND state = 'UP') 7) ORDER BY profits desc; How do you modify the above code if you want to avoid causing an error if the subquery returns more than one row.
- Change line 1 to read "SELECT DISTINCT bus_name, profits "
- Change line 3 to read "where city IN ("
- Change line 5 to read "where max (city) LIKE 'NOID%' "
- Change line 7 to read "order by city , profits desc "
An attribute declared as primary key can have null values.
- True
- False
While creating tables, the concept that is used to reduce redundancy in data is called
- Views
- Normalization
- Integrity
- Consistency
SELECT ROUND(123.456,2) , TRUNC(123.456,2), ROUND(125.456, -1) , TRUNC(126.456,-2) FROM DUAL;
- 123.46,123.45,130,100
- 123.46,123.45,130,120
- 123.46,123.45,120,100
- 123.46,123.45,125,100
A table has following 2 columns with the given valuesc1 c2 -------------- 1 1 1 NULL 2 0 NULL NULL . What will be the output of the following query :select count(*) , count (c1+c2) , count (distinct (c1 + c2)) from temp;
- 3,2,1
- 3,2,2
- 4,2,1
- 4,3,2
SELECT name,salary , dept FROM emp e WHERE NOT EXISTS (SELECT 1 FROM dept WHERE deptno = e.dept); Which employees are retrieved from the above query:
- Employees who work for a department that is not listed in DEPT table.
- Employees who work from department 1
- Employees who work for a department with more than 1 employee
- Employees who work for a department other than department 1
- package pkgA; 2. public class Foo { 3. int a = 5; 4. protected int b = 6; 5. public int c = 7; 6. } 3. package pkgB; 4. import pkgA.*; 5. public class Baz { 6. public static void main(String[] args) { 7. Foo f = new Foo(); 8. System.out.print(" " + f.a); 9. System.out.print(" " + f.b); 10. System.out.print(" " + f.c); 11. } 12. }
- 5 6 7
- 5 followed by an exception
- Compilation fails with an error on line 7
- Compilation fails with an error on line 8
- Compilation fails with an error on line 9
- Compilation fails with an error on line 10
- class Announce { 5. public static void main(String[] args) { 6. for(int __x = 0; __x < 3; __x++) ; 7. int #lb = 7; 8. long [] x [5]; 9. Boolean []ba[]; 10. enum Traffic { RED, YELLOW, GREEN }; 11. } 12. }
- Compilation succeeds
- Compilation fails with an error on line 6
- Compilation fails with an error on line 7
- Compilation fails with an error on line 8
- Compilation fails with an error on line 9
- Compilation fails with an error on line 10
- class X { void do1() { } } 2. class Y extends X { void do2() { } } 3. 4. class Chrome { 5. public static void main(String [] args) { 6. X x1 = new X(); 7. X x2 = new Y(); 8. Y y1 = new Y(); 9. // insert code here 10. } 11. }
- x2.do2();
- (Y)x2.do2();
- ((Y)x2).do2();
- None of the above statements will compile
- public class Tenor extends Singer { 4. public static String sing() { return "fa"; } 5. public static void main(String[] args) { 6. Tenor t = new Tenor(); 7. Singer s = new Tenor(); 8. System.out.println(t.sing() + " " + s.sing()); 9. } 10. } 11. class Singer { public static String sing() { return "la"; } }
- fa fa
- fa la
- la la
- Compilation fails
- class Building { 4. Building() { System.out.print("b "); } 5. Building(String name) { 6. this(); System.out.print("bn " + name); 7. } 8. } 9. public class House extends Building { 10. House() { System.out.print("h "); } 11. House(String name) { 12. this(); System.out.print("hn " + name); 13. } 14. public static void main(String[] args) { new House("x "); } 15. }
- h hn x
- hn x h
- b h hn x
- b hn x h
- bn x h hn x
The __________ attribute is used to declare variables based on definitions of columns in table
- %ROWTYPE
- %TYPE
- AS_COLUMN
- None of the above
Raw types are used to store _________ data.
- Binary
- Character
- ASCII
- All of the above
SQL has facility for programmed handling of errors that arise during the manipulation of data
- TRUE
- FALSE
- Both
- None
_________ data type stores unstructured binary data upto 4GB length
- CLOB
- BLOB
- LONG
- All of the above
In a PL/SQL block structure, which parts are optional?
- DELCARE and BEGIN
- DECALRE and EXCEPTION
- EXCEPTION and END
- BEGIN and END
Procedure C is a local construct to the package. What happens when this package is compiled?
- It produces the output Procedure B calling C
- It produces the output Procedure C calling B
- It produces a compilation error because procedure C requires a forward declaration
- It produces a compilation error because procedure B requires a forward declaration.
A Rollback statement cannot be used to close transaction
- TRUE
- FALSE
- Both
- None