Found 6702 Articles for Database

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

Mandalika
Updated on 30-Nov-2020 08:58:19

3K+ Views

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

692 Views

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

2K+ Views

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

How does spring boot connect localhost MySQL

AmitDiwan
Updated on 20-Nov-2020 07:33:57

2K+ Views

For this, use application.properties −spring.datasource.username=yourMySQLUserName spring.datasource.password=yourMySQLPassword spring.datasource.url=jdbc:mysql://localhost:3306/yoruDatabaseName spring.datasource.driver-class-name=com.mysql.cj.jdbc.DriverTo understand the above syntax, let us create a table −mysql> create table demo71 −> ( −> id int, −> name varchar(20) −> ); Query OK, 0 rows affected (3.81 sec)Insert some records into the table with the help of insert command −mysql> insert into demo71 values(100, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo71 values(101, 'David'); Query OK, 1 row affected (0.49 sec) mysql> insert into demo71 values(102, 'Bob'); Query OK, 1 row affected (0.15 sec)Display records from the table using select statement −mysql> select *from ... Read More

What is the difference Between AND, OR operator in MySQL while Retrieving the Rows?

AmitDiwan
Updated on 20-Nov-2020 07:31:21

2K+ Views

The difference between AND, OR is that AND evaluates both conditions must be true for the overall condition to be true. The OR evaluates one condition must be true for the overall condition to be true.Let us create a table −mysql> create table demo70 −> ( −> id int not null auto_increment primary key, −> name varchar(20), −> age int −> ); Query OK, 0 rows affected (0.67 sec)Insert some records into the table with the help of insert command −mysql> insert into demo70(name, age) values('John', 23); Query OK, 1 row affected (0.18 sec) mysql> insert into demo70(name, age) ... Read More

Update all varchar column rows to display values before slash in MySQL?

AmitDiwan
Updated on 20-Nov-2020 07:29:12

175 Views

For this, use UPDATE command along with SUBSTRING_INDEX(). Let us first create a table −mysql> create table demo69 −> ( −> name varchar(40) −> ); Query OK, 0 rows affected (5.04 sec)Insert some records into the table with the help of insert command −mysql> insert into demo69 values('John/Smith'); Query OK, 1 row affected (0.83 sec) mysql> insert into demo69 values('David/Miller'); Query OK, 1 row affected (0.23 sec) mysql> insert into demo69 values('Chris/Brown'); Query OK, 1 row affected (0.40 sec) mysql> insert into demo69 values('Carol/Taylor'); Query OK, 1 row affected (0.36 sec)Display records from the table using select ... Read More

How to combine few row records in MySQL?

AmitDiwan
Updated on 20-Nov-2020 07:28:10

66 Views

For this, use CASE WHEN concept. Let us first create a table −mysql> create table demo68 −> ( −> id int not null auto_increment primary key, −> company_name varchar(50), −> employee_name varchar(50), −> country_name varchar(50) −> ); Query OK, 0 rows affected (1.86 sec)Insert some records into the table with the help of insert command −mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'John', 'US'); Query OK, 1 row affected (0.29 sec) mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'Bob', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'David', 'AUS'); Query OK, ... Read More

MySQL limit in a range fail to display first 3 row?

AmitDiwan
Updated on 20-Nov-2020 07:25:50

90 Views

Following is the syntax to display only the first 3 rows with LIMIT set in a range −select *from yourTableName limit yourStartIndex, yourEndIndex;Let us first create a table −mysql> create table demo67 −> ( −> id int, −> user_name varchar(40), −> user_country_name varchar(20) −> ); Query OK, 0 rows affected (0.72 sec)Insert some records into the table with the help of insert command −mysql> insert into demo67 values(10, 'John', 'US'); Query OK, 1 row affected (0.19 sec) mysql> insert into demo67 values(1001, 'David', 'AUS'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo67 values(101, 'Mike', 'UK'); ... Read More

MySQL database field type for search query?

AmitDiwan
Updated on 20-Nov-2020 07:21:08

116 Views

Following is the syntax −select *from yourTableName where REGEXP_INSTR(yourColumnName, yourSearchValue);To understand the above syntax, let us first create a table −mysql> create table demo64 −> ( −> id int not null auto_increment primary key, −> name varchar(40) −> ); Query OK, 0 rows affected (3.06 sec)Insert some records into the table with the help of insert command −mysql> insert into demo64(name) values('John Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into demo64(name) values('John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo64(name) values('Chris Brown'); Query OK, 1 row affected (0.08 sec) mysql> ... Read More

Encrypt and Decrypt a string in MySQL?

AmitDiwan
Updated on 20-Nov-2020 07:18:17

6K+ Views

To encrypt and decrypt in MySQL, use the AES_ENCRYPT() and AES_DECRYPT() in MySQL −insert into yourTableName values(AES_ENCRYPT(yourValue, yourSecretKey)); select cast(AES_DECRYPT(yourColumnName, yourSecretKey) as char) from yourTableName;To understand the above syntax, let us first create a table −mysql> create table demo63 −> ( −> value blob −> ); Query OK, 0 rows affected (2.60 sec)Insert some records into the table with the help of insert command. We are encrypting while inserting −mysql> insert into demo63 values(AES_ENCRYPT('John', 'PASS')); Query OK, 1 row affected (0.18 sec) mysql> insert into demo63 values(AES_ENCRYPT('David', 'PASS')); Query OK, 1 row affected (0.41 sec) mysql> insert ... Read More

Advertisements