Read data from user and insert them to table : Console Prompt Read « PL SQL « Oracle PL / SQL

Oracle PL / SQL
1. Aggregate Functions
2. Analytical Functions
3. Char Functions
4. Constraints
5. Conversion Functions
6. Cursor
7. Data Type
8. Date Timezone
9. Hierarchical Query
10. Index
11. Insert Delete Update
12. Large Objects
13. Numeric Math Functions
14. Object Oriented Database
15. PL SQL
16. Regular Expressions
17. Report Column Page
18. Result Set
19. Select Query
20. Sequence
21. SQL Plus
22. Stored Procedure Function
23. Subquery
24. System Packages
25. System Tables Views
26. Table
27. Table Joins
28. Trigger
29. User Previliege
30. View
31. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL / SQL » PL SQL » Console Prompt Read 
Read data from user and insert them to table


--Creating the employee table.  
CREATE TABLE employee   
(emp_id           INTEGER,  
 emp_name      VARCHAR2(32),    
 supervised_by      INTEGER,    
 pay_rate               NUMBER(9,2),    
 pay_type              CHAR,    
 emp_dept_id                 INTEGER);  
        
ALTER TABLE employee    
ADD CONSTRAINT pk_emp primary key (emp_id);

insert into employee values (1,'Jack Chen',3,100.50, H, 3);
insert into employee values (2,'Jason Lee',1,300.50, H, 3);
insert into employee values (3,'Ala Wang',5,200.50, H, 3);

-- Creating the department table. 
CREATE TABLE department 
(dept_id           INTEGER,  
 dept_name     VARCHAR2(32));    
        
ALTER TABLE department  
    ADD CONSTRAINT PRIMARY KEY (dept_id);


insert into department values (1,'Computer');
insert into department values (2,'Publish');
insert into department values (3,'Management');


-- Creating the emp_dept table.   
CREATE TABLE emp_dept
(emp_id           INTEGER,   
 dept_id            INTEGER, 
 CONSTRAINT unq_1 unique (emp_id, dept_id));

insert into emp_dept values(1,3);
insert into emp_dept values(2,3);
insert into emp_dept values(3,3);

select from employee;
select from department;
select from emp_dept;



-- Inserting records with PL/SQL code.    
DECLARE               
    i_dept_id  INTEGER, 
    i_dept_name,    
BEGIN   
    INSERT into department values (&i_dept_id,'&dept_name');  
END;    
        
COMMIT;               
        
DECLARE             
    i_id   INTEGER; 
    e_id  INTEGER;  
    i_name  VARCHAR2(32);   
    i_super  INTEGER;   
    i_rate    NUMBER(9,2);  
    i_type   CHAR;  
    i_emp_dept INTEGER; 
    e_emp_dept INTEGER; 
BEGIN   
    e_id:=12
    e_emp_dept:=12;    
        
    INSERT into employee values (e_id, '&i_name',&i_super,&i_rate,'&i_type',e_emp_dept);    
END;    
/



select from employee;
select from department;
select from emp_dept;


drop table employee;
drop table department;
drop table emp_dept;
           
       
Related examples in the same category
1. Read user input
2. A single query can contain multiple runtime variables
3. Dealing with repeating values: using double ampersands
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.