0

programming languages Online Quiz - 49

Description: programming languages Online Quiz - 49
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which of the following queries can be used to delete duplicate records from a table -

  1. delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);

  2. delete from table_name where rowid in (select max(rowid) from table group by duplicate_values_field_name);

  3. c)delete from table_name where rowid not in (select max(rowid) from table);

  4. delete from table_name where rowid not in (select rowid from table group by duplicate_values_field_name);


Correct Option: A

Which statement selects the odd number of records :

  1. select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);

  2. select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp);

  3. select * from emp where (rowid,1) in (select rowid, mod(rownum,1) from emp);

  4. select * from emp where (rowid,1) in (select rowid, mod(rownum,3) from emp);


Correct Option: A

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.

  1. Change line 1 to read "SELECT DISTINCT bus_name, profits "

  2. Change line 3 to read "where city IN ("

  3. Change line 5 to read "where max (city) LIKE 'NOID%' "

  4. Change line 7 to read "order by city , profits desc "


Correct Option: B

An attribute declared as primary key can have null values.

  1. True

  2. False


Correct Option: B

While creating tables, the concept that is used to reduce redundancy in data is called

  1. Views

  2. Normalization

  3. Integrity

  4. Consistency


Correct Option: B

SELECT ROUND(123.456,2) , TRUNC(123.456,2), ROUND(125.456, -1) , TRUNC(126.456,-2) FROM DUAL;

  1. 123.46,123.45,130,100

  2. 123.46,123.45,130,120

  3. 123.46,123.45,120,100

  4. 123.46,123.45,125,100


Correct Option: A

AI Explanation

To determine the correct answer, let's break down the given SQL statement:

SELECT ROUND(123.456,2) , TRUNC(123.456,2), ROUND(125.456, -1) , TRUNC(126.456,-2) FROM DUAL;

The ROUND function is used to round a number to a specific decimal place, and the TRUNC function is used to remove decimal places from a number.

Let's evaluate each part of the statement:

  • ROUND(123.456,2) rounds the number 123.456 to 2 decimal places, resulting in 123.46.
  • TRUNC(123.456,2) removes all decimal places after 2, resulting in 123.45.
  • ROUND(125.456, -1) rounds the number 125.456 to the nearest 10, resulting in 130.
  • TRUNC(126.456,-2) removes all decimal places after the nearest 100, resulting in 100.

So, the resulting values are: 123.46, 123.45, 130, 100.

Comparing the resulting values with the answer choices:

A) 123.46, 123.45, 130, 100 - This option matches the resulting values. B) 123.46, 123.45, 130, 120 - The last value should be 100, not 120. C) 123.46, 123.45, 120, 100 - The third value should be 130, not 120. D) 123.46, 123.45, 125, 100 - The third value should be 130, not 125.

Therefore, the correct answer is option A) 123.46, 123.45, 130, 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;

  1. 3,2,1

  2. 3,2,2

  3. 4,2,1

  4. 4,3,2


Correct Option: A

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:

  1. Employees who work for a department that is not listed in DEPT table.

  2. Employees who work from department 1

  3. Employees who work for a department with more than 1 employee

  4. Employees who work for a department other than department 1


Correct Option: A
  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. }
  1. 5 6 7

  2. 5 followed by an exception

  3. Compilation fails with an error on line 7

  4. Compilation fails with an error on line 8

  5. Compilation fails with an error on line 9

  6. Compilation fails with an error on line 10


Correct Option: D,E

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 5 6 7 - This option is incorrect because it suggests that the code will successfully compile and print the values of variables a, b, and c. However, the code will not compile due to errors.

Option B) 5 followed by an exception - This option is incorrect because it suggests that the code will compile successfully and print the value of variable a, followed by an exception. However, the code will not compile due to errors.

Option C) Compilation fails with an error on line 7 - This option is incorrect because line 7 does not contain any syntax errors. The error occurs later in the code.

Option D) Compilation fails with an error on line 8 - This option is correct. The code fails to compile on line 8 because the class Foo is in a different package (pkgA) than the class Baz (pkgB). Even though the import statement is present on line 4, the protected variable b is not accessible outside of the package.

Option E) Compilation fails with an error on line 9 - This option is correct. The code fails to compile on line 9 because the protected variable b is not accessible outside of the package, even with the import statement. Protected variables can only be accessed by subclasses or classes in the same package.

Option F) Compilation fails with an error on line 10 - This option is incorrect because the variable c is declared as public and can be accessed from any package. Therefore, there will be no compilation error on line 10.

The correct answer is D,E. The code fails to compile with errors on line 8 and line 9.

  1. 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. }
  1. Compilation succeeds

  2. Compilation fails with an error on line 6

  3. Compilation fails with an error on line 7

  4. Compilation fails with an error on line 8

  5. Compilation fails with an error on line 9

  6. Compilation fails with an error on line 10


Correct Option: C,D,F
  1. 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. }
  1. x2.do2();

  2. (Y)x2.do2();

  3. ((Y)x2).do2();

  4. None of the above statements will compile


Correct Option: C
  1. 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"; } }
  1. fa fa

  2. fa la

  3. la la

  4. Compilation fails


Correct Option: B
  1. 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. }
  1. h hn x

  2. hn x h

  3. b h hn x

  4. b hn x h

  5. bn x h hn x


Correct Option: C

AI Explanation

To understand the given code and determine the output, let's analyze each part of it step by step:

  1. The code starts with the definition of a class Building.
  2. The Building class has two constructors: Building() and Building(String name).
  3. The first constructor Building() prints "b ".
  4. The second constructor Building(String name) calls the first constructor using this(), and then prints "bn " followed by the value of name.
  5. Next, there is a class House that extends the Building class.
  6. The House class has two constructors: House() and House(String name).
  7. The first constructor House() prints "h ".
  8. The second constructor House(String name) calls the first constructor using this(), and then prints "hn " followed by the value of name.
  9. Finally, the main method of the House class creates a new House object with the value "x " as the argument.

Now, let's go through the options to determine the correct output:

Option A) h hn x

This option is incorrect. It suggests that the output will be "h hn x". However, it doesn't consider the constructors of the Building class.

Option B) hn x h

This option is incorrect. It suggests that the output will be "hn x h". However, it doesn't consider the constructors of the Building class.

Option C) b h hn x

This option is correct. As per the given code, the output will be "b h hn x". The House constructor calls the Building constructor using this(), which in turn calls the Building() constructor, printing "b ". Then, the House constructor prints "h ", followed by "hn " and the value "x ".

Option D) b hn x h

This option is incorrect. It suggests that the output will be "b hn x h". However, it doesn't consider the order of constructor calls.

Option E) bn x h hn x

This option is incorrect. It suggests that the output will be "bn x h hn x". However, it doesn't consider the order of constructor calls.

Therefore, the correct answer is option C) b h hn x.

The __________ attribute is used to declare variables based on definitions of columns in table

  1. %ROWTYPE

  2. %TYPE

  3. AS_COLUMN

  4. None of the above


Correct Option: B

Raw types are used to store _________ data.

  1. Binary

  2. Character

  3. ASCII

  4. All of the above


Correct Option: A

SQL has facility for programmed handling of errors that arise during the manipulation of data

  1. TRUE

  2. FALSE

  3. Both

  4. None


Correct Option: B

_________ data type stores unstructured binary data upto 4GB length

  1. CLOB

  2. BLOB

  3. LONG

  4. All of the above


Correct Option: B

In a PL/SQL block structure, which parts are optional?

  1. DELCARE and BEGIN

  2. DECALRE and EXCEPTION

  3. EXCEPTION and END

  4. BEGIN and END


Correct Option: B

AI Explanation

To answer this question, we need to understand the structure of a PL/SQL block.

A PL/SQL block consists of four main parts: DECLARE, BEGIN, EXCEPTION, and END.

The DECLARE section is used to declare variables, cursors, and other PL/SQL objects. It is optional in a PL/SQL block.

The BEGIN section is where the executable statements of the block are placed. It is also optional in a PL/SQL block.

The EXCEPTION section is used to handle exceptions that may occur during the execution of the block. It is optional in a PL/SQL block.

The END section marks the end of the block. It is a required part of a PL/SQL block.

Based on the given options, let's go through each one:

Option A) DELCARE and BEGIN - Both DECLARE and BEGIN are optional parts of a PL/SQL block. This option is incorrect.

Option B) DECALRE and EXCEPTION - Both DECLARE and EXCEPTION are optional parts of a PL/SQL block. This option is correct.

Option C) EXCEPTION and END - The EXCEPTION section is optional, but the END section is required. This option is incorrect.

Option D) BEGIN and END - The BEGIN section is optional, but the END section is required. This option is incorrect.

Therefore, the correct answer is B) DECALRE and EXCEPTION. These parts are optional in a PL/SQL block.

Procedure C is a local construct to the package. What happens when this package is compiled?

  1. It produces the output Procedure B calling C

  2. It produces the output Procedure C calling B

  3. It produces a compilation error because procedure C requires a forward declaration

  4. It produces a compilation error because procedure B requires a forward declaration.


Correct Option: C

A Rollback statement cannot be used to close transaction

  1. TRUE

  2. FALSE

  3. Both

  4. None


Correct Option: C
- Hide questions