473,382 Members | 1,225 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,382 software developers and data experts.

Creating a cursor to select from a field - which field is determined by variable.

Hi everybody

I'm wrinting a stored procedure in order to use this last one in a migration script.

During the writing i've notice that i have to use a variable in a cursor ..

For example

I fetch the variable var_name which give the result of one request in this i have for example ashley, kate etc ..

I wanna use ashlet, kate .. in order to selecte the specifies fields in another table

So i want to make SELECT ashley,kate FROM table; in orde rto see what is stocked in the column ashley and in the column kate but instead of having the informations of theses columns when i make SELECT var_name FROM table i've ashley, kate like i've write SELECT 'ashley', 'kate' FROM table or 1 if i write SELECT 1 FROM table

The string stocked in the variable isn't interpreted as a column names

>So it's possible tu use a variable to select fields ???

> Thanks for your help
Sep 11 '07 #1
2 1400
amitpatel66
2,367 Expert 2GB
Hi everybody

I'm wrinting a stored procedure in order to use this last one in a migration script.

During the writing i've notice that i have to use a variable in a cursor ..

For example

I fetch the variable var_name which give the result of one request in this i have for example ashley, kate etc ..

I wanna use ashlet, kate .. in order to selecte the specifies fields in another table

So i want to make SELECT ashley,kate FROM table; in orde rto see what is stocked in the column ashley and in the column kate but instead of having the informations of theses columns when i make SELECT var_name FROM table i've ashley, kate like i've write SELECT 'ashley', 'kate' FROM table or 1 if i write SELECT 1 FROM table

The string stocked in the variable isn't interpreted as a column names

>So it's possible tu use a variable to select fields ???

> Thanks for your help
Check out the logic for executing dynamic SELECT statement using PLSQL 9i:

Expand|Select|Wrap|Line Numbers
  1. declare
  2. ab varchar2(20) := 'item'; -- This variable stores column name of table a
  3. b varchar2(20);
  4. str varchar2(100);
  5. begin
  6. str:= 'SELECT '||ab||' from a where item ='||CHR(39)||'apple'||CHR(39);
  7. EXECUTE IMMEDIATE str;
  8. end; 
  9.  
Try applying the same logic to your requirement....to make use of variable as column names
Sep 11 '07 #2
pbmods
5,821 Expert 4TB
Heya, Cour. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Try using a prepared statement.
Sep 11 '07 #3

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

Similar topics

6
by: kaosyeti | last post by:
is there a way to create simple help file that i plan on linking to a command button on a form using what's already in access? i will probably be giving out this db that i've written to a number...
1
by: traceable1 | last post by:
SQL Server 2000 SP4 with AWE hotfix. Windows 2003 SP1. I have a stored procedure which is not working the way I think it should be. I have a CURSOR which has a variable in the WHERE clause: ...
3
by: GISDude | last post by:
Hi all. I am trying to create a little script(I think) that will basically use a search cursor. I am a GIS(geographic information systems) Analyst and in our software(ESRI ARCGIS 9.1) ESRI has...
0
debasisdas
by: debasisdas | last post by:
RESTRICTIONS ON CURSOR VARIABLES ================================= Currently, cursor variables are subject to the following restrictions: Cannot declare cursor variables in a package spec. ...
0
debasisdas
by: debasisdas | last post by:
SAMPLE CODE TO SHOW USE OF REFCURSOR ======================================= EXAMPLE #1 ---------------------- declare --declare the fer cursor. type my_ref_cur_typ is ref cursor; --declare...
0
debasisdas
by: debasisdas | last post by:
Cursor Variable Returning %ROWTYPE ----------------------------------------------------------- DECLARE TYPE TmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; tmp_cv TmpCurTyp;TYPE EmpCurTyp IS REF...
3
by: mckbill | last post by:
Is there a way I can direct the cursor to a specific field (variable) in a form by typing the field name while in form view? I have a form with many fields, and it would be nice if there were...
2
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.