|
Deletes rows from a table
Exclui linhas de uma tabela
EXEC SQL
DELETE FROM table_name
WHERE condition
END-EXEC
|
Examples - Exemplos
Example 1:
From the table DSN8C10.EMP delete the row on which the cursor C1 is currently positioned.
A partir da tabela DSN8C10 .EMP, exclua a linha na qual o cursor C1 está posicionado no momento.
EXEC SQL
DELETE FROM DSN8C10.EMP
WHERE CURRENT OF C1
END-EXEC
|
Example 2:
From the table DSN8C10.EMP, delete all rows for departments E11 and D21.
Da tabela DSN8C10 .EMP, exclua todas as linhas dos departamentos E11 e D21.
EXEC SQL
DELETE FROM DSN8C10.EMP
WHERE WORKDEPT = 'E11' OR WORKDEPT = 'D21'
END-EXEC
|
Example 3:
From employee table X, delete the employee who has the most absences.
Na tabela de funcionários X, exclua o funcionário que tem mais faltas.
EXEC SQL
DELETE FROM EMP X
WHERE ABSENT = (SELECT MAX(ABSENT) FROM EMP Y
WHERE X.WORKDEPT = Y.WORKDEPT);
END-EXEC
|
Example 4:
Assuming that cursor CS1 is positioned on a rowset consisting of 10 rows of table T1, delete all 10 rows in the rowset.
Supondo que o cursor CS1 esteja posicionado em um conjunto de linhas que consiste em 10 linhas da tabela T1, exclua todas as 10 linhas do conjunto de linhas.
EXEC SQL
DELETE FROM T1
WHERE CURRENT OF CS1;
END-EXEC
|
Example 5:
Assuming cursor CS1 is positioned on a rowset consisting of 10 rows of table T1, delete the fourth row of the rowset.
Supondo que o cursor CS1 esteja posicionado em um conjunto de linhas que consiste em 10 linhas da tabela T1, exclua a quarta linha do conjunto de linhas.
EXEC SQL
DELETE FROM T1
WHERE CURRENT OF CS1 FOR ROW 4 OF ROWSET;
END-EXEC
|
Example 6:
Delete rows in table T1 if the value for column COL2 matches the cardinality of array INTA.
The array INTA is specified as an argument for the CARDINALITY function in the DELETE statement.
Exclua linhas na tabela T1 se o valor da coluna COL2 corresponder à cardinalidade da matriz INTA.
A matriz INTA é especificada como um argumento para a função CARDINALITY na instrução DELETE.
CREATE TYPE INTARRAY AS INTEGER ARRAY[6];
CREATE VARIABLE INTA AS INTARRAY;
SET INTA = ARRAY[1, 2, 3, 4, 5];
CREATE TABLE T1 (COL1 CHAR(7), COL2 INT);
INSERT INTO T1 VALUES('abc', 10);
DELETE FROM T1 WHERE COL2 = CARDINALITY(INTA);
|
Example 7:
Delete only 3 rows from table T1 where the value of column C2 is greater than 10.
Exclua apenas 3 linhas da tabela T1 onde o valor da coluna C2 é maior que 10.
EXEC SQL
DELETE FROM T1
WHERE C2 > 10
FETCH FIRST 3 ROWS ONLY;
END-EXEC
|
|