sql - Declaring & Setting Variables in a Select Statement -


I am trying to write a simple query where I declare some variables and then in a select statement in Oracle I am using. I am able to do this in SQL Server with the first:

  announcement date @ date1 DATETIME SET @ date1 = '03 -AUG-2010 ' With the use of Visual U. (NOLOCK) where U. UTIUM & gt; @ Date1  

The research I've done looks like you can not declare such a variable in selected statements. Is it true or am I doing something wrong?

The research that I have done shows that you can see such variables in select statements Can not declare. Is it true or am I missing something?

There are two different languages ​​within Oracle PL / SQL and SQL, which have two different engines. You can embed SQL DML inside PL / SQL, and from this You will get a variable. Note the following Unknown PL / SQL block as such that / is not a part of PL / SQL at the end, but SQL * plus tells to send preceding block.

  Announce date of v_Date1: = to_date ('03-Aug-2010', 'DD-Som-YYYY'); V_Count number; Use select count (*) in v_Count, where UseTime & gt; V_Date1; Dbms_output.put_line (v_Count); End; /  

The problem is that one block equal to your T-SQL code will not work:

  SQL & gt; Announce the date 2 v_Date1: = to_date ('03 -AUG-2010 ',' DD-Som-YYYY '); 3 Start 4 Use VisualId 5 to select 6 where UseTime & gt; V_Date1; 7 end; 8 / VisualId on Line 4 * Error: Ora-0650: Line 4, Column 5: PLS-00428: Expecting an INTO section in this selection statement  

To pass the results of one For PL / SQL queries, either an anonymous block, stored procedure or stored function, a cursor should be declared, opened and then returned to the calling program. (Beyond the scope of answering this question. See Edit: )

The client tool that can be connected to the database can be its own bind variable. In SQL * Plus:

  SQL & gt; - SQL * Plus does not have all the types of dates in this context. SQL & gt; - Use varchar2 to capture text and SQL for text; Variable v_Date1 varchar2 (20) sql & gt; SQL & gt; - Bind variable SQL & gt; Use PL / SQL to set the value of Exec: v_Date1: = '02-Aug-2010 '; PL / SQL Process successfully complete SQL & gt; - Since the change in a date, the variable is not yet a date. SQL & gt; - Note the use of colon, it tells the SQL * plus that v_Date1 SQL & gt; - A bind variable is SQL & gt; Select VisualId 2 from Utility 2 where UseTime & gt; To_char (: v_Date1, 'DD-Mon-YYYY'); None of the rows is selected  

In the above mentioned SQL plus, probably (probably not) Todd will work in PL / SQL Developer, etc. SQL are plus commands that are not SQL or PL / SQL commands No row is selected because the table is empty.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -