Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In Oracle SQL Developer, can a query be assigned to a variable for re-use?

 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I probably should clarify what I'm doing.

I have a single SQL Query Worksheet open, and I have on that sheet something like the following:


Now, I'd like to, instead of having that first select statement copy/pasted a zillion times, assign it to a variable or a reference of some sort, so that I can have the query itself only in one place - thus any debugging or modifications of the query only have to be done once.

Is this possible? If so, how do I do it?

Thanks.
 
Agador Paloi
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would put the sql into a single class if this is all the sql you have. I usually put all sql into separate classes for each object type I need to persist in the database.

Agador
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe, I believe SQL developer supports (nearly all of) the SQL*plus syntax, including the COLUMN command, which can be used to declare a variable:
This at least worked in my SQL Developer (version 3.0)

There may be other ways to define a variable (eg. the DEFINE command), but I'm not very well versed in them.
 
Agador Paloi
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry , missed the sql + reference in your Q.

If your going to execute these queries a zillion time you may want to create a function for each in a pl sql package.

Agad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic