Sunday, May 6, 2018

Insertion in a Table through PLSQL Query

https://plsqlquery.blogspot.com/2018/05/insertion-in-table-through-plsql-query.html

You can add new rows to a table by using the INSERT Statement.


There is a column list before Values Keyword

INSERT into STUDENT
(RNO, NAME, DOB, NIC, GENDER)
VALUES
(1,'ASLAM','23-JAN-1996',21325435435,'M');

1 row created

RNO           NAME               DOB                                    NIC                                GENDER
      1            ASLAM          23-JAN-1996                21325435435                                M


-- Insert a new row containing values for each column.
-- Optionally, list the columns in the INSERT clause.


INSERT into STUDENT
(RNO, NAME, DOB, NIC, GENDER)
VALUES
(2,'SAMINA','31-MAR-1987',65876443534,'F');

1 row created

RNO           NAME               DOB                                    NIC                                GENDER
      2            SAMINA          31-MAR-1987                65876443534                                F

------------------------------------------------------------------------------------------------------

There is not any column list before Values Keyword

INSERT into STUDENT
VALUES
(3,'AAMIR','25-FEB-1992',1234455555,'M');

1 row created

RNO           NAME               DOB                                    NIC                                GENDER
      3            AAMIR         25-FEB-1992                    1234455555                                M


If you do not use the column list, the value must be listed according to the default order of the columns in the table, and a value must be provided for each column.

---------------------------------------------------------------------------------------------------------------------------

INSERT into STUDENT
(
RNO, NAME, DOB, NIC, GENDER
)
VALUES
('4','RAJ KUMAR','25-APR-1997',null,'M'
);

1 row created

In this example NULL Value is moved in NIC column by using NULL Keyword for NIC column.

-------------------------------------------------------------------------------------------------------------------------------

INSERT into STUDENT
(
RNO, NAME, DOB, GENDER
)
VALUES
('5','ZOBIA KHAN','12-AUG-1997','F'
);


1 row created

In this example NULL Value is moved in NIC column by by excluding NIC column from column list.

------------------------------------------------------------------------------------------------------------------------------

INSERT into CLASS values (1,'CLASS ONE');
INSERT into CLASS values (2,'CLASS TWO');
INSERT into CLASS values (3,'CLASS THREE');

CID             CDESC
1                  CLASS ONE
2                  CLASS TWO
3                  CLASS THREE

---------------------------------------------------------------------------------------------------------

INSERT into STD_MARKS Values (1,1,75.32);
INSERT into STD_MARKS Values (2,1,61.16);
INSERT into STD_MARKS Values (3,1,48.95);
INSERT into STD_MARKS Values (4,1,89.91);

RNO      CID            PER
1                1           75.32
2                1           61.16
3                1           48.95
4                1           89.91

---------------------------------------------------------------------------------------------------------

INSERT into STD_GRADE Values ('A1',90,100);
INSERT into STD_GRADE Values ('A',80,89.99);
INSERT into STD_GRADE Values ('B',70,79.99);
INSERT into STD_GRADE Values ('C',60,69.99);
INSERT into STD_GRADE Values ('D',50,59.99);
INSERT into STD_GRADE Values ('F',0,49.99);

GRADE             MIN_PER             MAX_PER
A1                              90                          100
A                                80                        89.99
B                                70                        79.99
C                                60                        69.99
D                                50                        59.99
F                                 0                          49.99

No comments:

Post a Comment

XLA to GL Link

  https://plsqlquery.blogspot.com/2025/12/xla-to-gl-link.html SELECT             acr.cash_receipt_id,             acr.receipt_number,       ...