0

I m trying to create a method where I can pass a parameter (a number) and get the number as my number of output. See below:

def get_data(i):
  for i in range(0,i):
    TNG = "SELECT DISTINCT hub, value, date_inserted FROM ZE_DATA.AESO_CSD_SUMMARY where opr_date >= trunc(sysdate) order by date_inserted desc fetch first i rows only" 

Where i is a number. Inside the query "fetch first i rows only" , i want it to query i number of rows.

Thoughts on the syntax?

  • What is the use of for loop here? Do you want to retrieve 4 rows then 5 rows and 6 rows etc. ? Or are you just looking for limit or top clause depending on the db – mad_ Jul 30 '18 at 18:37
  • the latter. for instance, if there are 4 distinct categories i wish to pull fro mthe data, then i can run the method with i=4 to only get 4 rows of queries – Dean Stuart Jul 30 '18 at 18:45
  • To me, categories would be columns and actually, your question does not make much of sense to me. Have you had a chance to look at limit. https://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering – mad_ Jul 30 '18 at 18:48

1 Answers1

0

Seems like you're looking for a limit argument. You didn't mention what type of SQL you're using, but here are a couple of examples for various SQL languages.

I'm also a little confused by the structure of that function, seems like you may want to query the result set, then iterate through it rather than query the result set i number of times.

Artichoke
  • 94
  • 1
  • 4