473,667 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[pl/sql] Assign a query's value to a variable

17 New Member
Hello everybody,
i create a stored producedure in Oracle that will get the user name who connect to Oracle database.
For exemple, i declare a variable "o_user" and i want to assign the value of the query (select user from dual) to the variable.
It's possible?

i know that it's possible to do by this statement "select user into o_user from dual". But i want to know if we have another way to do by using the operation ( := ) to assign.
So thanks before hand, and sorry for my poor english.
Trakal
Sep 11 '07 #1
7 18154
amitpatel66
2,367 Recognized Expert Top Contributor
Hello everybody,
i create a stored producedure in Oracle that will get the user name who connect to Oracle database.
For exemple, i declare a variable "o_user" and i want to assign the value of the query (select user from dual) to the variable.
It's possible?

i know that it's possible to do by this statement "select user into o_user from dual". But i want to know if we have another way to do by using the operation ( := ) to assign.
So thanks before hand, and sorry for my poor english.
Trakal
make use of a CURSOR if u want to use assignment operator:

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. o_user VARCHAR2(10);
  3. CURSOR C1 IS SELECT USER FROM DUAL;
  4. BEGIN
  5. FOR I IN C1 LOOP
  6. IF(C1%FOUND) THEN
  7. o_user := I.user;
  8. END IF;
  9. END LOOP;
  10. END;
Sep 11 '07 #2
trakal
17 New Member
Hello amitpatel66 and everybody,
So thanks for your quickly answer. this answer is useful for me.
But if you don't mind me, can i ask you another question because this code is look complicated for my programme.
I don't know if you know SQL Server.

Let see this example in SQL Server

CREATE PROCEDURE [dbo].[test]
( @username[nvarchar] (64) = NULL)
AS
IF@username IS NULL
BEGIN
SELECT DISTINCT @username = SYSTEM_USER
END....

This is the extrait of a procedure that let to assign directly the name of database's user. The procedure have a user name as a parameter. it verify if this parameter is null or not, if it's null, it will assign the name of user to this parameter.
I want to use the operator assign (:=) because i hope that it has a query look like the one in SQL Server. it's maybe simplier for generate.
(if you don't understand my question, please let me know, i'll reforme my question)
thanks in advance.
Sep 11 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Hello amitpatel66 and everybody,
So thanks for your quickly answer. this answer is useful for me.
But if you don't mind me, can i ask you another question because this code is look complicated for my programme.
I don't know if you know SQL Server.

Let see this example in SQL Server

CREATE PROCEDURE [dbo].[test]
( @username[nvarchar] (64) = NULL)
AS
IF@username IS NULL
BEGIN
SELECT DISTINCT @username = SYSTEM_USER
END....

This is the extrait of a procedure that let to assign directly the name of database's user. The procedure have a user name as a parameter. it verify if this parameter is null or not, if it's null, it will assign the name of user to this parameter.
I want to use the operator assign (:=) because i hope that it has a query look like the one in SQL Server. it's maybe simplier for generate.
(if you don't understand my question, please let me know, i'll reforme my question)
thanks in advance.
Hi,

In PLSQL, you can assign a value to a variable either using INTO clause or using an explicit cursor as I have shown above.
Sep 12 '07 #4
trakal
17 New Member
good morning,
Thanks alot for your answer.
Have a nice day
Sep 12 '07 #5
Saii
145 Recognized Expert New Member
USER can be simply assigned to a variable just like sysdate. You dont need to do select ....from dual;
<variable>:=USE R;
Sep 12 '07 #6
trakal
17 New Member
USER can be simply assigned to a variable just like sysdate. You dont need to do select ....from dual;
<variable>:=USE R;
can i do something like SQL Server?
For exemple: SELECT DISTINCT o_user := USER FROM DUAL;
I think that it's impossible. But i just try to ask you all if you already see this problem and solve it.
Thank.
Sep 13 '07 #7
Saii
145 Recognized Expert New Member
can i do something like SQL Server?
For exemple: SELECT DISTINCT o_user := USER FROM DUAL;
I think that it's impossible. But i just try to ask you all if you already see this problem and solve it.
Thank.
I am not sure about the SQL Server.
Sep 13 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
6411
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was opened. The reports record source is a query. The query uses the value from the form text box to restrict the query. Table name = EggsTable one of the columns in the table is named: EggColor Form name = EggColorForm Form text box name = ColorTextBox
0
1711
by: Omar K | last post by:
Hi, I am quite new to frontpage and SQL but I have a Stock Control access database / frontpage to set up. My last problem deals with the automatic updating of the total quantity of stock with parts move in or out of the warehouse. The following shows my page layout (i posted this on the frontpage group, but I think their level is too high for my skills, since i use the DRR most of the time) I have form.htm that asks the user for two...
13
6581
by: MLH | last post by:
Suppose I have this simple SQL string... SELECT tblDrivers.DriverID, tblDrivers.DName FROM tblDrivers WHERE (((tblDrivers.DName) Like "N*")) ORDER BY tblDrivers.DriverID; And suppose that its not a saved querydef - just an SQL string that I cooked up in code and assigned to a global var strMySQL.
5
14284
by: devx777 | last post by:
Hello, I am trying to find some information or an example on how to build a dynamic query in DB2 that would allow me to join a table which its name is stored as a field value on another table. I have done this in the past in SQL server, but DB2 is not as easy... Anyone out there that can help me? Your help will be much appreciated.
0
2670
by: woollymammoth | last post by:
I can't assign a MS SQL Server table record value to a simple VB variable, should be an easy thing. Sample SQL Server table has the data in the record as a char(30) string, the column for that record is named "Try". The VB script function accessing the record value is running on a web hosting server with ASP.Net 2.0 on a web page. Result always is it "can't convert from a Field to type 'String'". Printing out the SQL variable results in...
1
5815
by: woollymammoth | last post by:
I can't assign a MS SQL Server table record value to a simple VB variable, should be a really easy thing. Sample SQL Server table has the data in the record as a char(30) string, the column for that record is named "Try". The VB script function accessing the record value is running on a web hosting server with ASP.Net 2.0 on a web page. Result always is it "can't convert from a Field to type 'String'". Printing out the SQL variable results...
10
11300
by: Tony K | last post by:
How would I assign the result of a SQL query to a variable. The result of the following statement will ALWAYS result in 1 row returned. SELECT ProductDescription, ProductID FROM Products WHERE (ProductIDNumber = ?) How do I assign the...say, ProductDescription to a variable called prodDesc? Thanks,
7
3101
by: Peter Nurse | last post by:
Two (almost) identical SQL Server databases (DB1 backed up and restored to DB2 yesterday). DB2.dbo.GetSchPaymentsTD took 1.5 seconds (!) to execute DB1.dbo.GetSchPaymentsTD took less than a millisecond with identical code and data. I'm guessing this is some sort of indexing issue and the code is below but I'm not sure it's relevant because . . . .. . . I dropped DB2.dbo.GetSchPaymentsTD and then recreated it (with identical code)...
7
1665
by: RachH | last post by:
I am using Access 2003 and need some guidance on the correct way to reference a variable in two different procedures when the variable's value is based on a SQL query. The database form has a button that, when clicked, will send an email, summarizing in the subject line the $ amount sold so far for the day. This email may be sent several times per day as needed, depending on the pricing volume. Then at the end of the day when all the pricing...
0
8458
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8366
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.