473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pass table name as param showing error

Im passing table name & column name which im selecting from cursor.But its inserting correctly and also showing error like cursor is not open .

my proc is as:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE TEST_BUILDINGCODE_PROC (IN v_AppId_Ver INTEGER)
  2. BEGIN
  3.  
  4.     DECLARE v_ObjId,v_LayerName,v_TableName,v_ColumnName varchar(30);
  5.     DECLARE v_CodeNo,v_DataCount integer;
  6.     DECLARE v_Statement,v_Schema,v_Counter varchar(200);
  7.     DECLARE v_stmt STATEMENT;
  8.  
  9.     DECLARE  C1 CURSOR WITH RETURN FOR
  10.     SELECT IDVER,LAYERNAME,CODENO,TABLENAME,COLUMNNAME FROM MPD2021.DA_TEST_LAYERCODE WHERE IDVER=v_AppId_Ver;
  11.  
  12.     SET v_Schema='MPD2021';
  13.  
  14.     SET v_DataCount=(SELECT COUNT(*) FROM MPD2021.DA_TEST_LAYERCODE WHERE IDVER=v_AppId_Ver);
  15.     SET v_Counter=1;
  16.     OPEN C1;
  17.     WHILE(v_Counter<=v_DataCount)
  18.     DO
  19.  
  20.         FETCH C1 INTO v_ObjId,v_LayerName,v_CodeNo,v_TableName,v_ColumnName;
  21.         --SET v_Schema='KKD';
  22.         SET v_Statement ='INSERT  INTO  ' || v_Schema || '. '|| v_TableName ||'(IDVERSION,'||v_ColumnName||') VALUES('||v_AppId_Ver||','||v_CodeNo||')';
  23.         --set v_Statement='INSERT INTO MPD2021.' concat  v_Schema concat ' VALUES ( 'concat ' 4 ' concat ')';
  24.  
  25.         --SET v_Statement = 'INSERT  INTO  ' || v_Schema || '. '|| v_TableName ||'('||v_ColumnName||') VALUES('||3||')';
  26.         PREPARE v_stmt FROM v_Statement;    
  27.         EXECUTE v_stmt;
  28.         COMMIT;
  29.  
  30.         --INSERT INTO TabName (IDVERSION,OBJID,LAYER,v_ColumnName) VALUES(v_AppId_Ver,v_ObjId,v_LayerName,v_CodeNo);
  31.  
  32. --    SET    v_DataCount=v_DataCount-1;
  33.     SET v_Counter = v_Counter + 1;    
  34.     END WHILE;
  35.     CLOSE C1;
  36. END
Feb 13 '13 #1
0 1339

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Luke Airig | last post by:
I am using the Saxon 6.5.3 engine and I have an xsl stylesheet that merges two files on a date_time field and writes out a tab-delimited flat file. My working version has a hard-coded file name in...
2
by: db2group88 | last post by:
hi, we install db2 udb v8.1 on windows 64bit, in our application, we have sql execute "create table .... not logged initially", but from the operating system event viewer showing error stating that...
5
by: adi | last post by:
Hi all, Seems like a fundamental question to me but I dont have a definite answer for it, Gurus please enlighten me. I have a table 'Table1' whose structure changes dynamically based on some...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
0
by: Afaque Khan | last post by:
HI All, I have a requirement, I need to pass table as IN parameter in the stored procedure. But when I do this it just says Table 'database.strtable' doesn't exist . Can you guys please advice...
4
azimmer
by: azimmer | last post by:
I need a function that can calculate percentiles of various tables and columns. I cannot seem, however, to be able to pass table name as a parameter to the function. Here's the code: create...
3
by: jojo41300000 | last post by:
Hi, I am trying to pass the table name to stored procedure and then use the passing table name in select, update or delete query statement. When I tried to do that, I got the error such as...
5
by: raghutumma | last post by:
Hi, I am trying to Pass Column Name(FieldName) using Parameter in SQL Statement... But i am getting error... how can i pass Column name using parameter??? Example: in table i have...
2
by: sudhanthiradevi | last post by:
hello i am new i vb.net. i am working in .net concern i want to fetch datas from sql i gave the coind as below SqlConnection connection; connection = new SqlConnection(); ...
0
by: Schow | last post by:
how to pass table name in DB2 Procedure. i passed as IN variable. like this CREATE PROCEDURE PROC1 (IN TNAME CHAR (12)) BEGIN UPDATE TNAME P But it throws an error as ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.