SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 7th, 2013, 03:02 AM
vb123 vb123 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 vb123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 38 sec
Reputation Power: 0
Update the local variable

Hi guys,


using the SELECT statement i am retrieving some values from the table along with that i am also taking one local variable.

ex

select emp_age , variable from employee.


in the above query variable is a local variable and i set it to 0.

suppose if the above query selects 5 rows from the table then i expect the following the results.

emp_age variable value

10 1
12 2
13 3
14 4
15 5

please help me to achieve the same thing

Reply With Quote
  #2  
Old June 4th, 2013, 07:00 AM
Rajbhoj Rajbhoj is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jun 2013
Location: India
Posts: 3 Rajbhoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 40 sec
Reputation Power: 0
Have a look at the below code. Hope it helps you


SET SERVEROUTPUT ON
DECLARE
VARIABLE_A NUMBER;
TYPE ARRAY_T IS VARRAY(100) OF VARCHAR2(100);
ARRAYV ARRAY_T ;
BEGIN
SELECT EMP_AGE bulk collect INTO ARRAYV FROM EMP;
FOR I IN 1..ARRAYV.COUNT
LOOP
VARIABLE_A :=I;
DBMS_OUTPUT.PUT_LINE(' Emp Age '||ARRAYV(i)||','||' your variable '||variable_a);
END LOOP;
END;

Reply With Quote
  #3  
Old August 10th, 2013, 12:14 AM
jethrow jethrow is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2013
Posts: 83 jethrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 51 m 6 sec
Reputation Power: 1
Question: are you sure you need a variable? It looks like you are just inserting row numbers, which could be achieved like this:
sql Code:
Original - sql Code
  1. DECLARE @employee TABLE (emp_age int);
  2. INSERT INTO @employee VALUES
  3.     (10),(12),(13),(14),(15);
  4.  
  5. SELECT  emp_age,
  6.         ROW_NUMBER() Over(ORDER BY Emp_Age) [variable value]
  7. FROM    @employee;

Reply With Quote
  #4  
Old August 30th, 2013, 03:45 AM
amranth amranth is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2013
Posts: 12 amranth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 23 sec
Reputation Power: 0
Can we use alter command to achieve this. If yes then which one is better?

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Update the local variable


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap