Found 151 Questions for DB2

How can you revert all the DB2 table changes done in a COBOL-DB2 program?

Mandalika
Updated on 30-Nov-2020 08:58:19
We can revert all the changes done on a COBOL-DB2 program using the ROLLBACK statement. However, ROLLBACK is only applicable until COMMIT has not been issued. If we have used a COMMIT statement, then ROLLBACK will revert all the changes made in DB2 tables after the last COMMIT point.For example, after the commit statement, we execute an UPDATE statement to modify the ORDER_PAID column of ORDERS table. After that if we fire ROLLBACK then the UPDATE on the ORDERS table will be reverted.ExampleEXEC SQL COMMIT END-EXEC EXEC SQL UPDATE ORDERS    SET ORDERS_PAID = ‘YES’ WHERE ORDER_DATE = :WS-CURRENT-DATE ... Read More

What is the difference between DB2 JOIN and UNION? Explain with the help of an example

Mandalika
Updated on 30-Nov-2020 08:57:25
Both JOIN and UNION are used to combine the data from one or more tables. In case of JOIN, the additional data appears in column while in case of UNION additional data appears in rows.For example, JOINSuppose we have two DB2 tables, ORDERS and TRANSACTIONS. We have to extract TRANSACTION_ID for each ORDER_ID, then we will use INNER JOIN as below:ExampleSELECT ORDER_ID, TRANSACTION_ID    FROM ORDERS INNER JOIN TRANSACTIONS ON    ORDERS.TRANSACTION_ID = TRANSACTIONS.TRANSACTION_IDThis query will result in 2 columns. One column will be from ORDERS table i.e., ORDER_ID and other column will be from TRANSACTIONS table i.e. TRANSACTION_ID.UNIONSWe have ... Read More

What is the use of the VALUE function in a DB2? Explain with the help of an example

Mandalika
Updated on 30-Nov-2020 08:56:21
The purpose of VALUE function in DB2 is to check for NULL values and it can be used in place of NULL indicator or COALESCE function. The VALUE function replaces the column value with the given argument if it contains a NULL value.For example, if we have an ORDER table and we have to extract ORDER_ID and ORDER_DESCRIPTION from this table. The ORDER_DECRIPTION column can have NULL values.If this is the case, we have to replace ORDER_DESCRIPTION with SPACES, then we can use the below query:ExampleEXEC SQL    SELECT ORDER_ID, VALUE(ORDER_DESCRIPTION, ‘ ‘)    INTO :ORDER-ID, :ORDER-DESCRIPTION    FROM ORDERS ... Read More

What is the usage of scrollable cursor for current positioning?

Mandalika
Updated on 15-Sep-2020 11:14:12
We can use SCROLLABLE CURSOR to directly point the cursor to the mentioned relative position. The relative position is the position of the row in the result table from the current row. For example, consider the table below.ORDER_IDORDER_DATEA223672020-07-28A667562020-07-28A778902020-07-29A968322020-07-29If the cursor is currently pointing to the 2nd absolute row i.e, ORDER_ID A66756 then the relative +2 position will be ORDER_ID A96832 and relative -1 position will be ORDER_ID A22367.The syntax to use relative position in FETCH statement is−EXEC SQL    FETCH RELATIVE +2 ORDER_CURR    INTO :ORDER-ID, :ORDER-DATE END-SQLRead More

What is the usage of scrollable cursor for absolute positioning?

Mandalika
Updated on 15-Sep-2020 11:12:39
The SCROLLABLE CURSOR can be used to directly point the cursor position to the mentioned absolute position. The absolute position is the position of a particular row in the result table from the first row.We can fetch the absolute position by using ABSOLUTE parameter in the FETCH statement. For example, we have to declare a scrollable cursor as below.EXEC SQL       DECLARE ORDER_CURR SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE = ‘2020-07-29’ END-SQLNow if we want to fetch the absolute 9th row then we will ... Read More

What is the difference between SENSITIVE and INSENSITIVE scrollable CURSOR with syntax

Mandalika
Updated on 15-Sep-2020 11:10:15
The INSENSITIVE SCROLLABLE CURSOR are sort of read only cursors in which the result table cannot change once the cursor is opened. The other applications also cannot update the INSENSITIVE SCROLLABLE CURSOR once it is opened. The SENSITIVE SCROLLABLE CURSOR, unlike INSENSITIVE are sensitive to changes made in the result table. The changes made by other applications will be reflected in the result table.We can declare SENSITIVE and INSENSITIVE SCROLLABLE CURSOR like below.EXEC SQL       DECLARE ORDER_CURR SENSITIVE SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE ... Read More

Write the syntax to declare a scrollable cursor on the ORDERS DB2 table.

Mandalika
Updated on 15-Sep-2020 11:08:13
A SCROLLABLE CURSOR can move in both forward and backward direction. In other words, it can fetch next as well as previous rows. A SCROLLABLE CURSOR is declared using the “SCROLL” clause in the DECLARE CURSOR.For example, if we want to declare a SCROLLABLE CURSOR on the ORDERS table then we have to declare the cursor like below.EXEC SQL       DECLARE ORDER_CURR SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE = ‘2020-07-29’ END-SQL

What is the purpose and usage of SCROLLABLE CURSOR in COBOLDB2 program?

Mandalika
Updated on 15-Sep-2020 11:06:45
A cursor can move only in forward direction, which means that it can extract the next row after every fetch. It is not possible to extract the previous row using a cursor.For example, if our resultant cursor contains following rows−ORDER_IDORDER_DATEA223672020-07-28A667562020-07-28A778902020-07-29A968322020-07-29If our cursor is currently pointing to 3rd row i.e. order id A77890 then the next fetch will point the cursor to the next row i.e. order id A96832. It is not possible to point the cursor to the previous order id i.e. A66756.In order to achieve this, we use the concept of SCROLLABLE CURSOR. The SCROLLABLE CURSOR can move both ... Read More

What is the purpose and usage of ATOMIC and NON-ATOMIC clause in multi row insert?

Mandalika
Updated on 15-Sep-2020 11:03:38
The ATOMIC and NON ATOMIC clauses are used with the multi-row insert. ATOMIC is always processed by default if any of the options is not given. The ATOMIC clause states that if there is a failure while inserting any one row during multi-row insertion then the entire query will be failed and all the inserts will be rolled back.The NON ATOMIC clause is just the opposite of the ATOMIC clause. It is used when we have to insert and process all the rows individually in a multi-row insert. For example, this option can be used like below.MOVE 50 TO MAX-ROWS ... Read More

How to insert multiple rows in a table using a single INSERT command in program?

Mandalika
Updated on 15-Sep-2020 10:58:18
If we want to insert a multiple rows in a DB2 table using a single INSERT command then we have to define the host variable array and move the row data we want to insert in that array. We need to define another variable in the working storage section with configuration S9(4) COMP which will hold the number of rows to be inserted. We can insert the multiple rows as below−MOVE 50 TO MAX-ROWS    EXEC SQL    INSERT INTO ORDERS (ORDER_ID, ORDER_DATE)    VALUES(:ORDER-ID, :ORDER-DATE) FOR    :MAX-ROWS ROWS END-EXECThe ORDER-ID and ORDER-DATE are host variables which should be ... Read More
Previous 1 ... 3 4 5 6 7 8 9 ... 16 Next
Advertisements