70-433 - Table Value Constructor

Filed under: , , by:

Table Value Constructor is a new feature within SQL Server 2008, and also can be part of existing features like INSERT or MERGE, which allows for new syntax only available within T-SQL (maybe that's another reason I decided to write about TVC after having studied Oracle SQL, which doesn't have this feature). So Table Value Constructor is nothing else than a T-SQL syntax that allows multiple rows of data to be specified in a single DML statement. TVC can be used only within the following DML statements:

  • INSERT statement
  • USING clause of MERGE statement
  • inline view or derived table in FROM clause
It can only be used to construct 1000 rows of data. The syntax is the same as the VALUES clause within INSERT statement, with the difference that TVC allows providing a list of values separated by comma.
[Table Value Constructor within INSERT statement]

[Table Value Constructor as DERIVED TABLE]

As far as table value constructor within MERGE statement, I'll demonstrate that in the next post , which will be dedicated entirely to MERGE statement as it is also a brand new feature in SQL Server 2008 and it is a little different than the one in Oracle. So it is really important to revisit it before the test.

70-433 - Exam

Filed under: , , by:

After having passed the 1Z0-047 Oracle Database SQL Expert Exam, I decided that it would make sense to take 70-433 (Microsoft SQL Server 2008, Database Development Exam) as my next exam. First of all, I have taken 70-431 (Microsoft SQL Server 2005 - Implementation and Maintenance) exam before, so it would make sense to update it to current version of SQL Server, plus I practices writing a lot of queries to the Oracle exam (even though the syntax sometimes can be so much different) and finally it would make sense to take this exam before I start studying to the .NET 4.0 exams, which based on my experience from previous exams might have a few questions regarding SQL Server 2008. So as always before starting studying to the exam, I try to learn about the exam as much as possible from those who have taken the exam.


There isn't much of very useful information, however one can find that MCTS Self-Paced Training Kit book doesn't even come close to covering topics in the exam, so if you go for the test without a considerable amount of SQL2008 and other version experience or training you are going to be in trouble when you take the exam. One interesting point I found was that "when you seat for the real test, Microsoft will try to "kill" you with really strange T-SQL options and queries that you barely see in real world". As far as Real MCTS Server 2008 70-433 book, it can help a lot but it's not quite enough to actually pass the exam (like no information about Service Broker). Dave mentioned some things that are either new or not very well known that each test taker should know like (filtered index, using APPLY operator to run Table Value Function against all rows in the table, or that an indexed view needs to use WITH SCHEMABINDING, and as a consequence the index must be UNIQUE CLUSTERED). The Best Study Guide for 70-433 site mentions only that to continue preparing with the SQL 2005 materials if you have as SQL 2008 added *new* things to SQL 2005, but there’s nothing in SQL 2005 that won’t be valid knowledge in SQL 2008, and then focus efforts on the *new* things in SQL2008 using SQL Server Books Online.
So based on the information as above, my study plan is to use the following books:
One might ask why some many books on SQL Server 2005. The answer is very simple: because I already own them so I don't feel like spending all the money on the same books for 2008, which will contain only few pages that are not in the previous books. That's why I will use SQL Server 2008 Books Online to learn new features that I could not find the books I already have. As far as posts are considered, I'll probably try to write about the new features introduced by SQL Server 2008 or maybe about some syntax that is typical to T-SQL like Output clause or recursive CTE.

1Z0-047 - Passed

Filed under: , by:

2 weeks ago I took the exam - I was going to wait but the following week I was starting new job, so I didn't feel like taking 2 hours off from work right away to take the exam. And I think the decision was good as I had passed the exam and I was pretty busy during my first days at the new place. As far as the exam, the only thing that surprised me was the number of questions testing your theoretical knowledge about Oracle database thereby requiring remembering and and understanding definitions items covered in the exam objectives. However, most questions tested understanding syntax of Oracle statements and using those statements to meet the requirements as described in the questions, but there was also quite a few questions that tested understanding required and optional parameters or arguments in the syntax, so there is a lot of things that you need to memorize or just remember from working with Oracle - fortunately most of those questions are not too hard. You have 120 minutes to answer 70 questions, so it's not that bad. However, almost always there is an exhibit with some database diagram. One thing I noticed is that only few questions really required that diagram and a lot of questions used the same one. Don't even try to study it as it may contain more information like tables than you need to answer the question. So my score was 98%, which means I failed on one question. As far as learning materials, I would definitely recommend Oracle-Database-Expert-Exam-Guide. Of course I also used other materials like Oracle-Database-Complete-Reference and of course SQL Language Reference, but the main source of information was still SQL Certified Expert Exam Guide. It covers all topics and contains a lot of definitions and explanations that are required to pass the test. Moreover, you have 2 full practice exam that have some questions with answers that are not in the book, which encourages you to learn from other sources than the book like Oracle Documentation. I would say that if you learn only from the book and fully understand the queries, syntax and definitions in the book, and you're going to read the questions very carefully on the exam, you will pass. Maybe not with the high score, but you should definitely score more than 66%.  As far as certificate or Success Kit Status as it is named on certview.oracle.com site, it looks like it will be shipped within 30 days but I didn't received it yet, so I will edit this post to show how it looks like. So after having passed Oracle exam, time to take SQL Server 2008 Database Development (70-433) Exam next  before starting taking exams from .NET 4.0.

1Z0-047 - WITH CLAUSE

Filed under: , by:

The WITH clause lets you assign a name to a subquery block. You can then reference the subquery block multiple places in the query by specifying the query name. Oracle Database optimizes the query by treating the query name as either an inline view or as a temporary table. You can specify this clause in any top-level SELECT statement and in most types of subqueries. The query name is visible to the main query and to all subsequent subqueries except the subquery that defines the query name itself. The query syntax is as follows:


WITH query_name1 AS (subquery)
[, query_name2 AS (subquery) ]
SELECT ... FROM ... WHERE ...

The WITH clause has been incorporated starting from Oracle 9.2 as a tool for materializing subqueries to save Oracle from having to recompute them multiple times. The advantage of loading subquery data into a temporary table is that repeated references to the subquery may be more efficient as the data is easily retrieved from the temporary table, rather than being requeried by each reference.
The WITH clause is subject to the following restrictions:
  • You can specify only one WITH clause in a single SQL statement. You cannot specify a query_name in its own subquery. However, any query_name defined in the WITH clause can be used in any subsequent named query block in the WITH clause.
  • In a compound query with set operators, you cannot use the query_name for any of the component queries, but you can use the query_name in the FROM clause of any of the component queries.
Based on my experience as a software developer, I learned that not many software developers are aware of the WITH clause. But when to look at the obvious advantages of refactoring complex queries with WITH clause, it is hard to find a reason why software developers don't want to use it - maybe one would be that it is not part of original ANSI SQL, but even though, MS SQL Server has WITH clause as CTE and also IBM DB2 has WITH clause, so if the concern is compatibility of sql queries with different databases, then this might be a very good argument. After all, WITH clause usually introduces performance gain and definitely simplifies complex queries. I have tested WITH clause against a table that had 90k records and had no indexes. The table zip_to_geography has zip codes with additional 4 digit codes and the population value based on the zip code.
The query was to find the number of zip codes that had population for the given zip code (5 digit code only) above average of total population. So the regular query looked like this:
[Regular query]

There was nothing wrong with this query except maybe the total time of execution: 15 minutes, which is understandable due to the fact that the table was missing obvious indexes. The same query refactored using WITH clause looked like this:
[Refactored query using WITH clause]

First of all, this query is way easier to read and is pretty much self-explanatory, therefore it's easier to maintain the query, but the biggest benefit of refactoring was the performance gain as the query using WITH clause ran 1s, which is 900 times faster with 0.11% of the time the regular query required to run. Of course, not all queries when refactoring to use WITH clause will give that kind of performance gain, but every developer should always remember to check if WITH clause can speed up the query or at least simplify it so it's easier to read it and it makes other developers more confident with the changes or tweaks to the query.

1Z0-047 - Dictionary views

Filed under: , by:

One of the exam requirements is "Use the data dictionary views to research data on your objects". Knowing dictionary views and tables is essential as dictionary data contains information about the database (concept of metadata) and its state. They are used for management, tunning and monitoring of the database. The data dictionary is created when the Oracle database is created. It is owned by the SYS user, and is stored principally in the SYSTEM tablespace, though some components are stored in the SYSAUX tablespace in Oracle Database 10g.The data dictionary views come in three main flavors:

  • User views - views with information about the user's objects
  • All views - views with information about objects accessible to the user
  • DBA views - views with information of all objects in the database
Below is a list of dictionary views with description of their purpose. The list contains probably more dictionary views than it is required for this exam, but it's better be safe than sorry.
  • ALL_ALL_TABLES - Description of all object and relational tables accessible to the user
  • ALL_ASSOCIATIONS - All associations available to the user
  • ALL_CATALOG - All tables, views, synonyms, sequences accessible to the user
  • ALL_COLL_TYPES - Description of named collection types accessible to the user
  • ALL_COL_COMMENTS - Comments on columns of accessible tables and views
  • ALL_COL_PRIVS - Grants on columns for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
  • ALL_COL_PRIVS_MADE - Grants on columns for which the user is owner or grantor
  • ALL_COL_PRIVS_RECD - Grants on columns for which the user, PUBLIC or enabled role is the grantee
  • ALL_CONSTRAINTS - Constraint definitions on accessible tables
  • ALL_CONS_COLUMNS - Information about accessible columns in constraint definitions
  • ALL_CONS_OBJ_COLUMNS - List of types an object column or attribute is constrained to in the tables accessible to the user
  • ALL_DB_LINKS - Database links accessible to the user
  • ALL_DEPENDENCIES - Dependencies to and from objects accessible to the user
  • ALL_DIRECTORIES - Description of all directories accessible to the user
  • ALL_ERRORS - Current errors on stored objects that user is allowed to create
  • ALL_EXTERNAL_LOCATIONS - Description of the external tables locations accessible to the user
  • ALL_EXTERNAL_TABLES - Description of the external tables accessible to the user
  • ALL_FILE_GROUPS - Details about file groups
  • ALL_INDEXES - Descriptions of indexes on tables accessible to the user
  • ALL_INDEXTYPES - All indextypes available to the user
  • ALL_IND_COLUMNS - Columns comprising indexes on accessible tables
  • ALL_IND_EXPRESSIONS - Functional index expressions on accessible tables
  • ALL_JOIN_IND_COLUMNS - Join Index columns comprising the join conditions
  • ALL_LIBRARIES - Description of libraries accessible to the user
  • ALL_MVIEWS - All materialized views in the database
  • ALL_NESTED_TABLES - Description of nested tables in tables accessible to the user
  • ALL_NESTED_TABLE_COLS - Columns of nested tables
  • ALL_OBJECTS - Objects accessible to the user
  • ALL_RULES - Rules seen by the user
  • ALL_SEQUENCES - Description of SEQUENCEs accessible to the user
  • ALL_SYNONYMS - All synonyms for base objects accessible to the user and session
  • ALL_TABLES - Description of relational tables accessible to the user
  • ALL_TAB_COLS - Columns of user's tables, views and clusters
  • ALL_TAB_COLUMNS - Columns of user's tables, views and clusters
  • ALL_TAB_COL_STATISTICS - Columns of user's tables, views and clusters
  • ALL_TAB_COMMENTS - Comments on tables and views accessible to the user
  • ALL_TAB_PRIVS - Grants on objects for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
  • ALL_TAB_PRIVS_MADE - User's grants and grants on user's objects
  • ALL_TAB_PRIVS_RECD - Grants on objects for which the user, PUBLIC or enabled role is the grantee
  • ALL_TYPES - Description of types accessible to the user
  • ALL_UNUSED_COL_TABS - All tables with unused columns accessible to the user
  • ALL_UPDATABLE_COLUMNS - Description of all updatable columns
  • ALL_USERS - Information about all users of the database
  • ALL_USTATS - All statistics
  • ALL_VIEWS - Description of views accessible to the user
  • CAT - Synonym for USER_CATALOG
  • COLS - Synonym for USER_TAB_COLUMNS
  • COLUMN_PRIVILEGES - Grants on columns for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
  • DICT - Synonym for DICTIONARY
  • DICTIONARY - Description of data dictionary tables and views
  • DICT_COLUMNS - Description of columns in data dictionary tables and views
  • GV$ACTIVE_INSTANCES - Synonym for GV_$ACTIVE_INSTANCES
  • GV$NLS_PARAMETERS - Synonym for GV_$NLS_PARAMETERS
  • GV$TIMEZONE_NAMES - Synonym for GV_$TIMEZONE_NAMES
  • GV$VERSION - Synonym for GV_$VERSION
  • IND - Synonym for USER_INDEXES
  • NLS_INSTANCE_PARAMETERS - NLS parameters of the instance
  • NLS_SESSION_PARAMETERS - NLS parameters of the user session
  • OBJ - Synonym for USER_OBJECTS
  • RECYCLEBIN - Synonym for USER_RECYCLEBIN
  • ROLE_ROLE_PRIVS - Roles which are granted to roles
  • ROLE_SYS_PRIVS - System privileges granted to roles
  • ROLE_TAB_PRIVS - Table privileges granted to roles
  • SEQ - Synonym for USER_SEQUENCES
  • SESSION_PRIVS - Privileges which the user currently has set
  • SESSION_ROLES - Roles which the user currently has enabled.
  • SM$VERSION - Synonym for SM_$VERSION
  • SYN - Synonym for USER_SYNONYMS
  • TABLE_PRIVILEGES - Grants on objects for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
  • TABS - Synonym for USER_TABLES
  • USER_ALL_TABLES - Description of all object and relational tables owned by the user's
  • USER_CATALOG - Tables, Views, Synonyms and Sequences owned by the user
  • USER_COL_COMMENTS - Comments on columns of user's tables and views
  • USER_COL_PRIVS - Grants on columns for which the user is the owner, grantor or grantee
  • USER_COL_PRIVS_MADE - All grants on columns of objects owned by the user
  • USER_COL_PRIVS_RECD - Grants on columns for which the user is the grantee
  • USER_CONSTRAINTS - Constraint definitions on user's own tables
  • USER_CONS_COLUMNS - Information about accessible columns in constraint definitions
  • USER_CONS_OBJ_COLUMNS - List of types an object column or attribute is constrained to in the tables owned by the user
  • USER_DB_LINKS - Database links owned by the user
  • USER_DEPENDENCIES - Dependencies to and from a users objects
  • USER_ERRORS - Current errors on stored objects owned by the user
  • USER_EXTERNAL_LOCATIONS - Description of the user's external tables locations
  • USER_EXTERNAL_TABLES - Description of the user's own external tables
  • USER_FREE_SPACE - Free extents in tablespaces accessible to the user
  • USER_INDEXES - Description of the user's own indexes
  • USER_INDEXTYPES - All user indextypes
  • USER_INDEXTYPE_ARRAYTYPES - All array types specified by the indextype
  • USER_INDEXTYPE_COMMENTS - Comments for user-defined indextypes
  • USER_INDEXTYPE_OPERATORS - All user indextype operators
  • USER_IND_COLUMNS - columns comprising user's indexes and indexes on user's tables
  • USER_IND_EXPRESSIONS - Functional index expressions in user's indexes and indexes on user's tables
  • USER_JOIN_IND_COLUMNS - Join Index columns comprising the join conditions
  • USER_LIBRARIES - Description of the user's own libraries
  • USER_MVIEWS - All materialized views in the database
  • USER_NESTED_TABLES - Description of nested tables contained in the user's own tables
  • USER_NESTED_TABLE_COLS - Columns of nested tables
  • USER_OBJECTS - Objects owned by the user
  • USER_OBJECT_TABLES - Description of the user's own object tables
  • USER_PASSWORD_LIMITS - Display password limits of the user
  • USER_RECYCLEBIN - User view of his recyclebin
  • USER_ROLE_PRIVS - Roles granted to current user
  • USER_RULES - Rules owned by the user
  • USER_SEQUENCES - Description of the user's own SEQUENCEs
  • USER_SYNONYMS - The user's private synonyms
  • USER_SYS_PRIVS - System privileges granted to current user
  • USER_TABLES - Description of the user's own relational tables
  • USER_TABLESPACES - Description of accessible tablespaces
  • USER_TAB_COLS - Columns of user's tables, views and clusters
  • USER_TAB_COLUMNS - Columns of user's tables, views and clusters
  • USER_TAB_COMMENTS - Comments on the tables and views owned by the user
  • USER_TAB_PRIVS - Grants on objects for which the user is the owner, grantor or grantee
  • USER_TAB_PRIVS_MADE - All grants on objects owned by the user
  • USER_TAB_PRIVS_RECD - Grants on objects for which the user is the grantee
  • USER_TYPES - Description of the user's own types
  • USER_UNUSED_COL_TABS - User tables with unused columns
  • USER_UPDATABLE_COLUMNS - Description of updatable columns
  • USER_USERS - Information about the current user
  • USER_USTATS - All statistics on tables or indexes owned by the user
  • USER_VIEWS - Description of the user's own views
  • V$NLS_PARAMETERS - Synonym for V_$NLS_PARAMETERS
  • V$NLS_VALID_VALUES - Synonym for V_$NLS_VALID_VALUES
  • V$OPEN_CURSOR - Synonym for V_$OPEN_CURSOR
  • V$SESSION - Synonym for V_$SESSION
  • V$SQLTEXT_WITH_NEWLINES - Synonym for V_$SQLTEXT_WITH_NEWLINES
  • V$SQL_PLAN - Synonym for V_$SQL_PLAN
  • V$TIMEZONE_NAMES - Synonym for V_$TIMEZONE_NAMES
  • V$TRANSACTION - Synonym for V_$TRANSACTION
  • V$VERSION - Synonym for V_$VERSION

1Z0-047 - Question 10

Filed under: by:

View the Exhibit (no exhibit was provided) and examine a sample of the data existing in the STORES table.
You need to generate a report that shows the following details:
1) The total QTY_SOLD of each product in each region of each country.
2) The total QTY_SOLD of all products in each region of each country.
3) The total QTY_SOLD of all products in each country.
Which SQL statement gives the required output?
A. SELECT country_id, region, prod_no, SUM(qty_sold)
FROM stores
GROUP BY CUBE(country_id,region,prod_no);
B. SELECT country_id, region, prod_no, SUM(qty_sold)
FROM stores
GROUP BY ROLLUP(country_id,region,prod_no);
C. SELECT country, region, prod_no, SUM(qty_sold)
FROM stores
GROUP BY GROUPING SETS(country_id,region),prod_no);
D. SELECT country, region, prod_no, SUM(qty_sold), GROUPING(country_id) G1, GROUPING(region) G2, GROUPING(prod_no)
FROM stores
GROUP BY CUBE (country_id,region,prod_no);

Theory:

Since the question contains SELECT queries with GROUP BY clause and functions GROUPING, GROUPING SETS, CUBE and ROLLUP, so the information required to answer the question can be found as follows: SELECT, GROUP BY, CUBE, ROLLUP and GROUPING SETS and GROUPING.

You specify the GROUP BY clause if you want the database to group the selected rows based on the value of expr(s) for each row and return a single row of summary information for each group. If this clause contains CUBE or ROLLUP extensions, then the database produces superaggregate groupings in addition to the regular groupings. Expressions in the GROUP BY clause can contain any columns of the tables, views, or materialized views in the FROM clause, regardless of whether the columns appear in the select list. The GROUP BY clause groups rows but does not guarantee the order of the result set. To order the groupings, use the ORDER BY clause. The ROLLUP operation in the simple_grouping_clause groups the selected rows based on the values of the first n, n-1, n-2, ... 0 expressions in the GROUP BY specification, and returns a single row of summary for each group. You can use the ROLLUP operation to produce subtotal values by using it with the SUM function. When used with SUM, ROLLUP generates subtotals from the most detailed level to the grand total. Aggregate functions such as COUNT can be used to produce other kinds of superaggregates. For example, given three expressions (n=3) in the ROLLUP clause of the simple_grouping_clause, the operation results in n+1 = 3+1 = 4 groupings. Rows grouped on the values of the first n expressions are called regular rows, and the others are called superaggregate rows. The CUBE operation in the simple_grouping_clause groups the selected rows based on the values of all possible combinations of expressions in the specification. It returns a single row of summary information for each group. You can use the CUBE operation to produce cross-tabulation values. For example, given three expressions (n=3) in the CUBE clause of the simple_grouping_clause, the operation results in 2n = 23 = 8 groupings. Rows grouped on the values of n expressions are called regular rows, and the rest are called superaggregate rows. GROUPING SETS are a further extension of the GROUP BY clause that let you specify multiple groupings of data. Doing so facilitates efficient aggregation by pruning the aggregates you do not need. You specify just the desired groups, and the database does not need to perform the full set of aggregations generated by CUBE or ROLLUP. Oracle Database computes all groupings specified in the GROUPING SETS clause and combines the results of individual groupings with a UNION ALL operation. The UNION ALL means that the result set can include duplicate rows. A blank set ( ) in the GROUPING SETS clause calculates the overall aggregate. GROUPING distinguishes superaggregate rows from regular grouped rows. GROUP BY extensions such as ROLLUP and CUBE produce superaggregate rows where the set of all values is represented by null. Using the GROUPING function, you can distinguish a null representing the set of all values in a superaggregate row from a null in a regular row. The expr in the GROUPING function must match one of the expressions in the GROUP BY clause. The function returns a value of 1 if the value of expr in the row is a null representing the set of all values. Otherwise, it returns zero. The datatype of the value returned by the GROUPING function is Oracle NUMBER. It might be also worth mentioning here that GROUP BY CUBE( a, b, c) is equivalent to GROUP BY GROUPING SETS ( (a, b, c), (a, b), (b, c), (a, c), (a), (b), (c), ( )), whereas ROLLUP (a, b, c) is equivalent to GROUPING SETS ( (a, b, c), (a, b), (a), ( )).

Answer:

A - Wrong - this query would display more than is needed – all combinations of region, country, product, so it would output for example sum in each region or all products without country, which is not requested in the question
B - Correct - this gives 4 aggregation levels with sums as needed as ROLLUP takes as its argument an ordered list of grouping column, and first it calculates the standard aggregate values specified in the GROUP BY clause, and next it creates progressively higher-level subtotals, moving from right to left through the list of grouping columns, and finally it creates a grand total.
C - Wrong - the query doesn't display data from requirement number 1 and 3 as it displays total of all products in each region of each country and sum per each product, but it does not display sum of each product in each region of each country and sum of all products in each country
D - Wrong - this query would work like the query from answer A but with extra information regarding if a row that is being displayed is a data row or an aggregate, which is not required, however with DECODE function that could be used to filter unnecessary rows from the output but this query doesn't do it

1Z0-047 - Question 9

Filed under: , by:

Examine the data in the DOCNO column of the DOC_DETAILS table:


DOCNO
123-456-7890
233-67-90876
45-789-23456


You need to extract the digits between the hyphens as follows:


SUBSTR
456
67
789


Which SQL statement gives the required result?
A. SELECT REGEXP_SUBSTR(docno,'-[^-]+') "SUBSTR" FROM doc_details;
B. SELECT REGEXP_SUBSTR(docno,'^-[^-]+-')"SUBSTR" FROM doc_details;
C. SELECT REGEXP_SUBSTR(docno,'-[^-]+',2) "SUBSTR" FROM doc_details;
D. SELECT REGEXP_SUBSTR(docno, '[^-]+',1,2) "SUBSTR" FROM doc_details;

Theory:

Since the question contains queries with REGEXP_SUBSTR function and regular expression syntax, so the information required to answer it can found as follows: REGEXP_SUBSTR and REGULAR EXPRESSION SYNTAX.

REGEXP_SUBSTR extends the functionality of the SUBSTR function by letting you search a string for a regular expression pattern. This function is useful if you need the contents of a match string but not its position in the source string. The function returns the string as VARCHAR2 or CLOB data in the same character set as source_string.
  • source_string is a character expression that serves as the search value. It is commonly a character column and can be of any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
  • pattern is the regular expression. It is usually a text literal and can be of any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. It can contain up to 512 bytes.
  • position is a positive integer indicating the character of source_string where Oracle should begin the search. The default is 1, meaning that Oracle begins the search at the first character of source_string.
  • occurrence is a positive integer indicating which occurrence of pattern in source_string Oracle should search for. The default is 1, meaning that Oracle searches for the first occurrence of pattern.
  • match_parameter is a text literal that lets you change the default matching behavior of the function. You can specify one or more value (ie. 'i' specifies case-insensitive matching)
Below are just few regular expression operators and metdasymbols - click on the link above to see the complete list of regular expression symbols
  • "+" - matches one or more occurrences
  • "^" - matches the beginning-of-line character. By default it matches only the beginning of an entire string.
  • "$" - matches the end-of-line character. By default it matches only the end of an entire string.
  • "[]" - specify a matching list that should match any one of the expressions represented in the list. A nonmatching list expression begins with a circumflex (^) and specifies a list that matches any character except for the expressions represented in the list.
Answer:

A - Wrong - the query finds a string that starts with a dash character and that has no other dash character, which would be numbers in the middle of the docno, so the query displays: -456, -67, -789 (dash character is part of the match).
B - Wrong - the search patterns looks for a string that doesn't start with a dash character and that has no dash character, which would be numbers at the beginning of the docno, so the query displays: 123, 233, 45
C - Wrong - the query has the same search pattern as the query from the answer A, except it starts looking from the 2nd character. As a result, it produces the same results as query from the answer A: -456, -67, -789
D - Correct - the search pattern looks for strings that don't have a dash character, so all numbers from the docno match the pattern, but the query takes the second group from the match, so the query displays:  456, 67, 789