retrieve the records from one table to another table by using cursors

retrieve the records from one table to another table by using cursors

Hi I'm fresher to backend(mysql),my requirement is retrieve the records from one table to another table by using cursors.The following is my procedure and tables.After execution it insert one extra record to another table. empproc procedure:

create procedure empproc() begin declare ename varchar(12); declare d int default 0; declare cur cursor for select name from emp; declare continue handler for not found set d=1; open cur; lb1:loop if d=1 then leave lb1; end if; if not d=1 then fetch cur into ename; insert into emp2 values(ename); end if; end loop; close cur; end; //

The actual data is bellow one:

mysql> select * from emp; +------+------+-------+ | eid | name | sal | +------+------+-------+ | 1 | aaaa | 12334 | | 2 | bbbb | 15334 | | 3 | cccc | 15336 | +------+------+-------+ 3 rows in set (0.00 sec)

after executing the procedure i'm getting the following result.print("code sample");

mysql> select * from emp2; +-------+ | ename | +-------+ | aaaa | | bbbb | | cccc | | cccc | +-------+ 4 rows in set (0.00 sec)

View Answers









Related Tutorials/Questions & Answers:
retrieve the records from one table to another table by using cursors
retrieve the records from one table to another table by using cursors  ... from one table to another table by using cursors.The following is my procedure and tables.After execution it insert one extra record to another table. empproc
update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products.... for example TotalQuantity field from Products table should be updated if i
Advertisements
copying data from one table to another
copying data from one table to another  i need to copy data from one table to another table.. i.e the 1st eid of employee table must be copied to the 1st eid in appusers table, 2nd eid of employee to the 2nd eid of appusers
Retrieve database from the table dynamically in jsp from oracle using servlet
Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few columns dynamically. I want to retrieve the table with all columns dynamically
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
retrieve record from table
for a single record. I have to retrieve these data from the field table. Actually...retrieve record from table  Hi. I have a field in database named... chennai as one value, trichy as one value. and i have to show it in html. how
mysql select into table from another table example
from one table into another table. Check the example at MySQLselect into new...mysql select into table from another table example  Can you suggest the correct example of select into table from another table example in MySQL
Retrieving data from table using DBCP
;from a table!\n");     BasicDataSource 
how to move records from one table to other based on its creation time
how to move records from one table to other based on its creation time  Hi all,, As part of my requirement ,the records in one table have to move... to the second table,has to delete from first table.. I am using oracle10, Any suggestions
retrieve record from the field table
,kanchipuram for a single record. I have to retrieve these data from the field table...retrieve record from the field table  Hi. I have a field in database... values like chennai as one value, trichy as one value. and i have to show it in html
How to retrieve record from table
,kanchipuram for a single record. I have to retrieve these data from the field table...How to retrieve record from table  Hi. I have a field in database... like chennai as one value, trichy as one value. and i have to show it in html
Retrieve Value from Table - Hibernate
Retrieve Value from Table   Hai friend, I need help, How can i retrieve values From database using hibernate in web Application. As I new to hibernate I couldn't find solution for this problem.. Can anyone help please.. 
Fetch user records from a table in database
Fetch user records from a table in database  Hi. I have a field...,trichy,kanchipuram for a single record. I have to retrieve these data from the field table. Actually they are separated by comma. I want to take the values
retrieve Dept Name from table dept and retrieve list of employee from emp table for that dept in combobox
retrieve data from database from table1 and display it in another textbox and from the same input paramter then its should retrieve the data from another table...retrieve Dept Name from table dept and retrieve list of employee from emp table
deleting all records from a table in mysql
; This will delete all the records from the table. But if you are using auto...deleting all records from a table in mysql  Hi, I am finding code for deleting all records from a table in mysql. How to delete all rows in mysql
deleting all records from a table in mysql
; This will delete all the records from the table. But if you are using auto...deleting all records from a table in mysql  Hi, I am finding code for deleting all records from a table in mysql. How to delete all rows in mysql
Retrieve multiple data from database into Table.....
Retrieve multiple data from database into Table.....   hi........... I want to Retrieve multiple data from database into Table but i am not able to.... i am only able to retrieve one value not more than that. means in my
Copy One Database Table to Another
Copy data from one database table to another! 4 row(s)affected... Copy One Database Table to Another   ... to another database table. That means we copy one table to a different table
retrieve record from table and show it in HTML
retrieve record from table and show it in HTML  Hi. I have a field...,trichy,kanchipuram for a single record. I have to retrieve these data from the field table. Actually they are separated by comma. I want to take the values
MYSQL retrieve record from Data table
MYSQL retrieve record from Data table  Hi. I have a field in database...,kanchipuram for a single record. I have to retrieve these data from the field table. Actually they are separated by comma. I want to take the values as single
I have to retrieve these data from the field table
I have to retrieve these data from the field table  Hi. I have... chennai,trichy,kanchipuram for a single record. I have to retrieve these data from the field table. Actually they are separated by comma. I want to take the values
HTML & MYSQL - retrieve record from table
HTML & MYSQL - retrieve record from table  Hi. I have a field...,trichy,kanchipuram for a single record. I have to retrieve these data from the field table. Actually they are separated by comma. I want to take the values as single
reading the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database table  Here is my requirement, I want to read the records from a .xlsx file and store that records in database table. I tried like this public class
JDBC: Select Records using Prepared Statement
how to retrieve records of table using Prepared Statement. Select Records ... the common sql query. Select statement is used to retrieve records from the table... are retrieving records from the student table whose roll no is less than 10
Mysql From Table
Mysql From Table       Mysql From Table is used to specify the table from which the records... 'from' is used to specify the table 'Stu' from which records is retrieved
how to count unique and duplicate values from one table in mysql?
how to count unique and duplicate values from one table in mysql?  I have use EMP table.I want to count unique and duplicate records from emp table and how to use in java program
how to retrieve data from table with runtime values in sql?
how to retrieve data from table with runtime values in sql?  how to retrieve data from table with runtime values in sql? For example, I have table... to execute the command with the dates which I pass. I know how to retrieve a particular
How to compare two tables, and insert values which r not in one table to another table?
How to compare two tables, and insert values which r not in one table to another table?  Hi I need to compare two tables MainTable and OUTTable... MT (MT.serialno) values (Select SerialNo Main_Table MT from where not exists
Adding a flex table in another flex table column
Adding a flex table in another flex table column  how to add a flex table in another flex table column
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/servlet-jsp-data
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery... [delete from CONTACT] int i=query.executeUpdate
Insert Records in Table
Insert Records in Table       The Insert data in Table is used to insert  records or rows into the table in database. The Syntax used to insert records into a table
MYSQL - mysql copy table to another table example by creating new table
MYSQL - mysql copy table to another table example by creating new table ... a new table with all the data from this table. How to create a new table... the query: create table <newtable> select * from <old table>; Example
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>"> common.jsp <%String attr=request.getAttribute("param"); out.print(attr
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>"> common.jsp <%String attr=request.getAttribute("param"); out.print(attr
PHP WHERE clause example to fetch records from Database Table
the data within the MYSQL database table. You can also fetch the results using... on the MYSQL Server and will fetch the results from the database table employee...) To test the code we are using existing database table. You can create your own
Retrieving Data from the table using PreparedStatement
Retrieving Data from the table using PreparedStatement... to fetch the data from the database in the table from our java program using... the getWriter() method of the PrintWriter class. We can retrieve the data from
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
storing records which of a file into a table of mssql database
storing records which of a file into a table of mssql database  I... same as column names of a table. I have to store those records into a table as records using hibernate and jdbc
how to insert one table to anothere table
how to insert one table to anothere table  i have insert the record one table then i retrve the value of that table i insert one value at a time
create a table in access2007 from gui application using textfields and combox
create a table in access2007 from gui application using textfields and combox  I want to create a table in ms access 2007 from gui application in which when i click create button the table should get created based on textfield
JDBC : Duplicate records in a table
JDBC : Duplicate records in a table In this tutorial, you will learn how to find the duplicate records in a table. Duplicate records in a table : You can check for duplicate records of table. You can group record by any of fields
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how... to display books based on either bookname or authorname, for this i created one jsp page
Adding checkbox in table using that delete table rows
Adding checkbox in table using that delete table rows  I need coding for how to add checkbox in table,the table data from database.Using that checkbox select more than than one rows,and using delete button i want to delete
Select data from Table in Database
the selected data from table in database. The select query in the database retrieve... in the syntax from table. select * from table; The select query retrieve all... the table, from where the data is retrieve. Understand with Example
Deleting Records using the Prepared Statement
the records from the database table by using the PreparedStatement interface... for deleting the records from the database table. Brief description below... Deleting Records using the Prepared Statement  
Display table performing action on another table
Display table performing action on another table In this section, we have created two tables. The data in table 1 have shown as a result of the database... of the table row, another table will be displayed showing the data of that row

Ads