Oracle__4. Oracle 1Z0-051 Exam - Select Statement Flashcards
What is the simplest syntax for the SELECT clause to return all fields of a table?
SELECT *
What is the simplest syntax for the SELECT clause to return all unique fields of a table?
SELECT DISTINCT *
What default keyword in the SELECT clause will return all rows including duplicates?
ALLSyntax: SELECT ALL *The keyword ALL is default
What is a clause?
a subset of a command that modifies the command.
What is the correct order of the following clauses in a select statement? ORDER BY SELECT WHERE HAVING GROUP BY
SELECTFROMWHEREGROUP BYHAVINGORDER BY
If table aliases are created in the FROM clause what other clauses can use those aliases?
SELECTWHEREGROUP BYORDER BY
What is the syntax of an ORDER BY clause to display column2 in alphabetical order and column1 in reverse numeric order?
ORDER BY column2 DESC, column1alsoORDER BY 2 DESC, 1
What does ORDER BY 1, 2 mean?
The first column in the select clause is ordered first and then the second column is order within the values of the first column.
What is the keyword in the ORDER BY clause meaning to sort from lowest to highest?
ASCmeaning AscendingASC is the default
What keyword will only display the first 10 rows of a SELECT statement?
WHERE ROWNUM <= 10
What is the syntax of a Select statement if you are adding column1 + column2 but want to have the column name as SUM?
SELECT column1 + column2 AS SUMthe as is optional but recommended
How many columns will be returned from this SELECT clause? Select column1 column2 from T1
1 column which will have the column name (Alias) of Column2.
What is the FROM clause syntax for creating an alias ‘X’ for a table named Table1
FROM table1 AS XThe keyword AS is optional
If column aliases are created in the SELECT clause which other clause CANNOT use those aliases?
GROUP BY
What is the only clause that you can create table aliases?
FROM
What is the only clause that you can create column aliases?
SELECT
What will be the difference of the returned data between these 2 clauses? ORDER BY column1, column2 ORDER BY 1, 2
Identical results
If column aliases are created in the SELECT clause which other clause CAN use those column aliases?
ORDER BY
Will this statement execute without errors? SELECT column1 A, column2 B, column1 + column2 C FROM table GROUP by column1, column2, column1 + column2
This will execute without errorsThe column1 + column2 in the GROUP BY is necessary and will error without it.
Which clause from a SELECT statement is used to eliminate rows from the results?
WHERE
Which clause from a SELECT statement is used to eliminate groups from the results?
HAVING
what is returned from the following statement? SELECT 2*5 + 7 - 6/2 FROM DUAL
142*5 = 106/2 = 310+7-3 = 14
What is DUAL?
a table in ORACLE that has one column named DUMMY with a value of X
Are the following statement equal? SELECT * FROM EMPLOYEES; Select * FROM EMPLOYEES; select * FROM EMPLOYEES;
Yes. Keyword capitalization of keywords has no affect.
What is the syntax of the SELECT clause with column1 having an alias of First Name?
“SELECT column1 AS ““First Name”“The AS is optionalif there is a space in the Alias, quotes are needed”
What is the syntax of a SELECT statement if you want to return all rows which have nulls in column1 of table1?
SELECT *FROM Table1WHERE column1 IS NULL
What is the syntax of a SELECT statement if you wanted to all records without null from column1 in table1?
SELECT *FROM table1WHERE column1 IS NOT NULL
What is the syntax of a SELECT statement wanted to return column2 from Table1 for all values where column2 is not equal zero?
SELECT column2FROM table1WHERE column2 <> 0orSELECT column2FROM table1WHERE NOT column2 = 0
“What is the syntax of a SELECT statement if you wanted to select columns1 and column2 from table1 where column4 is greater than 0 and column7 begins with an ““A”” or ““B”” or ““C””?”
SELECT column1, column2FROM table1Where column4 > 0and column7 BETWEEN ‘A’ AND ‘C’OR SELECT column1, column2FROM table1Where column4 > 0and column7 BETWEEN ‘A’ AND ‘C’
Does this select statement have an expression clause? SELECT column1 CASE owner WHEN ‘SYS’ THEN ‘The owner is SYS’ WHEN ‘SYSTEM’ THEN ‘The owner is ‘SYSTEM’ ELSE ‘unkown Owner’ END FROM table
“YesThe column name ““owner”” after the CASE keyword is the expression clause”
Does this select statement have an expression clause? SELECT column1 CASE WHEN owner = ‘SYS’ THEN ‘The owner is SYS’ WHEN owner = ‘SYSTEM’ THEN ‘The owner is ‘SYSTEM’ ELSE ‘unkown Owner’ END FROM table
“NoThere is no value between CASE and WHENNotice the column name ““owner =”” is in each WHEN clause”
What will the results be if the value in the column named owner column is ‘USER’? SELECT column1 CASE WHEN owner = ‘SYS’ THEN ‘The owner is SYS’ WHEN owner = ‘SYSTEM’ THEN ‘The owner is SYSTEM’ END FROM table
It would return a null because there is not match any value for owner and there is no ELSE clause
Is this a valid CASE statement? SELECT CASE WHEN a < b then ‘A’ WHEN d < e THEN ‘B’ END FROM table
Yes it is valid but the first WHEN clause is evaluated first and if true will return a result and then not evaluate the second WHEN.
If the computer is in Chicago and the user is in California, which date/time is returned by this statement? SELECT SYSDATE FROM dual;
The date and time in Chicago
If the computer is in Chicago and the user is in California, what is the result of this statement? SELECT CURRENT_DATE FROM dual;
The date and time in California
Column aliases can only be defined in which clause of a SQL Statement?
The SELECT Clause
Table aliases can only be defined in which clause of a SQL Statement?
The FROM Clause
What is the scope of an alias?
only within the SQL Statement
What is needed if the alias has a space in the name?
Quote around the entire Alias name
“Using the LIKE operator, create a WHERE clause that would find all records from the column last_name that begin with the letters ““Sm””.”
WHERE last_name LIKE ‘Sm%’
“Using the LIKE operator, create a WHERE clause that would find all records from the column last_name that begin with ““S”” and end with ““h””.”
WHERE last_name LIKE ‘S%h’
In a LIKE comparison, what is the wildcard symbol for matching a string of any length including zero length?
% (percentage sign)
In a LIKE comparison. what is the wildcard symbol for matching a single character?
_ (underscore)
“Using the LIKE operator, create a WHERE clause that would find all records from the column last_name beginning with ““Sm”” and ending with ““th”” but can have only 1 character in between.”
LIKE last_name LIKE ‘Sm_th’
Using the LIKE operator, create a WHERE clause that would find all records from the column Parts which begin with ‘H%’. Remember % is also a wildcard.
WHERE Parts LIKE ‘H%!%’ ESCAPE ‘!’The keyword ESCAPE designates the escape character
The HAVING clause is used in combination of with what other clause?
GROUP BY
Besides the SELECT clause, what other clauses can have the SUM, COUNT, MIN, MAX or AVG functions.
only the HAVING clauseThose functions are not allowed in the WHERE clause or GROUP BY clause.
What is the syntax of a WHERE clause that find records that match state = ‘Texas’ and name = ‘IBM’ as well as any record where the cost is greater than 1000.
WHERE (state = ‘Texas and name = ‘IBM’)OR cost > 1000User parenthesis when combining OR and AND keywords
Which will perform faster? SELECT cust_name, cust_city FROM customers WHERE cust_credit_limit IN (1000,2000,3000) SELECT cust_name, cust_city FROM customers WHERE cust_credit_limit = 1000 OR cust_credit_limit = 2000 OR cust_credit_limit = 3000
The performance will be the same
If hire_date is a date data type, what data type will be returned by this SQL statement? SELECT SYSDATE - hire_date FROM emp
a numeric value
If the column transdate is a numeric data type, will this statement cause an error? SELECT transdate = ‘10’ FROM transactions
NoThe ‘10’ will be implicitly converted from a string to a numeric
If the column transdate is a date data type, will this statement cause an error? SELECT * FROM transactions WHERE transdate = ‘01-JANUARY-07’
NoThe ‘10-JANUARY-07’ will be implicitly converted to ‘10-JAN-07’
If transamount and custno are numeric data types, will this statement cause an error? SELECT transamount FROM transactions WHERE custno > ‘11’
NoThe ‘11’ will implicitly be converted to a numeric
“Will this SQL statement create an error? SELECT promo_name, promo_date ““START DATE”” FROM promotions WHERE promo_date > ‘01-JAN-01’ ORDER BY ““START DATE”” DESC”
The statement will execute without error.Aliases can be used in the ORDER BY clause, but aliases cannot be used in the GROUP BY clause
What is returned from this statement? SELECT ‘Ted’ || q’{‘s Car}’ || ‘ is red.’ FROM dual
Ted’s Car is redThe q keyword act as an escape clauseq’{……..}’
What is returned from this statement? SELECT ‘Ted’ || q’(‘s Car)’ || ‘ is red.’ FROM dual
Ted’s Car is redThe q key word can have any of 4 different pairs of brackets such as: {} [] () <>But no mix match between the pairs such as: { … )
What is returned from this statement? SELECT ‘Ted’ || q’[’s Car]’ || ‘ is red.’ FROM dual
Ted’s Car is red
What is returned from this statement? SELECT ‘Ted’ || q’’ || ‘ is red.’ FROM dual
Ted’s (Car) is red
What will be returned with the following statement? SELECT ‘Ted’ || q’
an error because the bracket types to not match< does not match with ]
Can a column of data type LONG be used in a GROUP BY or an ORDER BY clause
No.A column defined a data type LONG cannot be used in either a GROUP BY or an ORDER BY clause
Can a constraint be defined for a column whose data type is LONG?
No
What data type should a LONG be converted in order to be more modern?
CLOB
Can a CLOB be used in a GROUP BY and an ORDER BY clause?
Yes
What is the results of this statement? SELECT part_name FROM employees WHERE part_name LIKE ‘%SA_’ ESCAPE ‘'
Any part name has SA_ as the last 3 characters.The _ (underscore) is a symbol.ESCAPE is a keyword