Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 PL/SQL

Author  Topic 

mrhardy76
Starting Member

6 Posts

Posted - 2008-07-10 : 08:43:46
How do write and execute a PL/SQL script to print running total of numbers 1 to 10?

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 08:51:18
select sum(MyNumber) MyHomeWorkAnswer from (
select 1 as MyNumber union all
select 2 as MyNumber union all
select 3 as MyNumber union all
select 4 as MyNumber union all
select 5 as MyNumber union all
select 6 as MyNumber union all
select 7 as MyNumber union all
select 8 as MyNumber union all
select 9 as MyNumber union all
select 10 as MyNumber
) MyHomeWork


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-10 : 09:16:17
PL SQL ....as in Oracle?

Em
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 09:18:17
I must be asleep I didn't even see that.

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-10 : 09:19:45
This is a Microsoft Sequel Server forum, so you may want to double-check this code to see if it works in Oracle

Jim
DECLARE @homework TABLE (col1 int)

INSERT INTO @homework
select 1 as MyNumber union all
select 2 as MyNumber union all
select 3 as MyNumber union all
select 4 as MyNumber union all
select 5 as MyNumber union all
select 6 as MyNumber union all
select 7 as MyNumber union all
select 8 as MyNumber union all
select 9 as MyNumber union all
select 10 as MyNumber

SELECT a.col1,sum(b.col1)
FROM @homework a
INNER JOIN
@homework b
ON
a.col1 >= b.col1
GROUP BY
a.col1
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-10 : 09:22:16
maybe you will get extra credit by submitting a T-SQL solution


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 09:30:26
For Oracle try
select sum(rownum) as MyHomework from tab where rownum < 11



"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

mrhardy76
Starting Member

6 Posts

Posted - 2008-07-10 : 12:49:29
yes. I need to use for loop as well.

quote:
Originally posted by elancaster

PL SQL ....as in Oracle?

Em

Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-11 : 03:14:57
I think you would probably be best to post your queries on an Oracle Forum. As stated, this is specifically for SQL Server problems

Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-15 : 08:55:14
Duplicate post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=106620
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=106612
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=106365


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-15 : 08:57:33
quote:
Originally posted by mrhardy76

yes. I need to use for loop as well.

quote:
Originally posted by elancaster

PL SQL ....as in Oracle?

Em




Why?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -