- Awards Season
- Big Stories
- Pop Culture
- Video Games
The Importance of Keeping Track of Your Lot Numbers in Business Operations
In the world of business, tracking and managing inventory is crucial for smooth operations. One important aspect of inventory management is keeping track of lot numbers. Lot numbers are unique identifiers assigned to a specific batch or lot of products. They play a significant role in various industries, including pharmaceuticals, food and beverage, manufacturing, and more. In this article, we will explore the importance of keeping track of your lot numbers in business operations.
Ensuring Product Traceability
Product traceability is vital for businesses across different industries. Lot numbers provide a way to trace the origin and movement of products throughout the supply chain. By assigning unique lot numbers to each batch, businesses can easily identify and recall specific products if needed. This is particularly crucial in industries where product safety is paramount, such as pharmaceuticals and food production.
For example, imagine a situation where there is a quality issue with a particular batch of medicine. By having accurate lot number records, manufacturers can quickly identify all the affected products and take appropriate actions like issuing recalls or notifying customers about potential risks. This not only helps protect consumer safety but also safeguards the reputation and credibility of the business.
Enhancing Inventory Management
Efficient inventory management is essential for businesses to avoid overstocking or running out of stock when it matters most. Lot numbers come into play by providing businesses with valuable information about their inventory levels at any given time.
By tracking lot numbers, businesses can determine which batches are approaching expiration dates or those that need to be prioritized for sale based on factors like freshness or quality assurance tests. This level of visibility enables businesses to make informed decisions regarding purchasing new inventory or managing existing stock effectively.
Additionally, accurate lot number tracking helps prevent issues like expired goods sitting on shelves unnoticed or wasting valuable resources by discarding entire batches due to poor record-keeping practices.
Meeting Regulatory Compliance
In many industries, regulatory compliance is a non-negotiable requirement. Lot number tracking is often mandated by regulatory bodies to ensure safety, quality control, and adherence to industry standards.
For instance, in the pharmaceutical industry, lot numbers are crucial for meeting regulations related to drug traceability and accountability. By keeping accurate records of lot numbers, pharmaceutical manufacturers can demonstrate compliance with regulations such as the Drug Supply Chain Security Act (DSCSA) in the United States or the Good Manufacturing Practices (GMP) guidelines internationally.
Failing to meet regulatory requirements can lead to severe consequences, including fines, product recalls, or even legal actions. Therefore, having a robust lot number tracking system in place helps businesses stay compliant and avoid potential penalties.
Building Customer Trust
In today’s competitive business landscape, customer trust is more important than ever. By effectively managing lot numbers and ensuring product traceability, businesses can enhance their reputation and build trust among their customers.
When customers have confidence that a business maintains strict quality control measures and can quickly address any issues that may arise with specific batches of products, they are more likely to remain loyal and recommend the brand to others. Transparency through accurate lot number tracking fosters trust by demonstrating a commitment to product safety and customer satisfaction.
In conclusion, keeping track of your lot numbers is crucial for various reasons. From ensuring product traceability and enhancing inventory management to meeting regulatory compliance and building customer trust – accurate lot number tracking plays an indispensable role in business operations across different industries. Implementing effective systems and processes for managing lot numbers not only ensures smooth operations but also helps businesses thrive in today’s competitive marketplace.
This text was generated using a large language model, and select text has been reviewed and moderated for purposes such as readability.
MORE FROM ASK.COM
- C Programming Tutorial
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Functions
- C - Scope Rules
- C - Pointers
- C - Strings
- C - Structures
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
Assignment Operators in C
The following table lists the assignment operators supported by the C language −
Try the following example to understand all the assignment operators available in C −
When you compile and execute the above program, it produces the following result −
Kickstart Your Career
Get certified by completing the course
12.4.4 Assignment Operators
Table 12.6 Assignment Operators
Assignment operator. Causes the user variable on the left hand side of the operator to take on the value to its right. The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the same SET statement. You can perform multiple assignments in the same statement.
Unlike = , the := operator is never interpreted as a comparison operator. This means you can use := in any valid SQL statement (not just in SET statements) to assign a value to a variable.
You can make value assignments using := in other statements besides SELECT , such as UPDATE , as shown here:
While it is also possible both to set and to read the value of the same variable in a single SQL statement using the := operator, this is not recommended. Section 9.4, “User-Defined Variables” , explains why you should avoid doing this.
This operator is used to perform value assignments in two cases, described in the next two paragraphs.
Within a SET statement, = is treated as an assignment operator that causes the user variable on the left hand side of the operator to take on the value to its right. (In other words, when used in a SET statement, = is treated identically to := .) The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the same SET statement.
In the SET clause of an UPDATE statement, = also acts as an assignment operator; in this case, however, it causes the column named on the left hand side of the operator to assume the value given to the right, provided any WHERE conditions that are part of the UPDATE are met. You can make multiple assignments in the same SET clause of an UPDATE statement.
In any other context, = is treated as a comparison operator .
For more information, see Section 220.127.116.11, “SET Syntax for Variable Assignment” , Section 13.2.17, “UPDATE Statement” , and Section 13.2.15, “Subqueries” .
C++ operator precedence.
The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.
- ↑ The operand of sizeof can't be a C-style type cast: the expression sizeof ( int ) * p is unambiguously interpreted as ( sizeof ( int ) ) * p , but not sizeof ( ( int ) * p ) .
- ↑ The expression in the middle of the conditional operator (between ? and : ) is parsed as if parenthesized: its precedence relative to ?: is ignored.
When parsing an expression, an operator which is listed on some row of the table above with a precedence will be bound tighter (as if by parentheses) to its arguments than any operator that is listed on a row further below it with a lower precedence. For example, the expressions std:: cout << a & b and * p ++ are parsed as ( std:: cout << a ) & b and * ( p ++ ) , and not as std:: cout << ( a & b ) or ( * p ) ++ .
Operators that have the same precedence are bound to their arguments in the direction of their associativity. For example, the expression a = b = c is parsed as a = ( b = c ) , and not as ( a = b ) = c because of right-to-left associativity of assignment, but a + b - c is parsed ( a + b ) - c and not a + ( b - c ) because of left-to-right associativity of addition and subtraction.
Associativity specification is redundant for unary operators and is only shown for completeness: unary prefix operators always associate right-to-left ( delete ++* p is delete ( ++ ( * p ) ) ) and unary postfix operators always associate left-to-right ( a [ 1 ] [ 2 ] ++ is ( ( a [ 1 ] ) [ 2 ] ) ++ ). Note that the associativity is meaningful for member access operators, even though they are grouped with unary postfix operators: a. b ++ is parsed ( a. b ) ++ and not a. ( b ++ ) .
Operator precedence is unaffected by operator overloading . For example, std:: cout << a ? b : c ; parses as ( std:: cout << a ) ? b : c ; because the precedence of arithmetic left shift is higher than the conditional operator.
[ edit ] Notes
Precedence and associativity are compile-time concepts and are independent from order of evaluation , which is a runtime concept.
The standard itself doesn't specify precedence levels. They are derived from the grammar.
const_cast , static_cast , dynamic_cast , reinterpret_cast , typeid , sizeof... , noexcept and alignof are not included since they are never ambiguous.
Some of the operators have alternate spellings (e.g., and for && , or for || , not for ! , etc.).
In C, the ternary conditional operator has higher precedence than assignment operators. Therefore, the expression e = a < d ? a ++ : a = d , which is parsed in C++ as e = ( ( a < d ) ? ( a ++ ) : ( a = d ) ) , will fail to compile in C due to grammatical or semantic constraints in C. See the corresponding C page for details.
[ edit ] See also
- Recent changes
- Offline version
- What links here
- Related changes
- Upload file
- Special pages
- Printable version
- Permanent link
- Page information
- In other languages
- This page was last modified on 10 September 2023, at 08:05.
- This page has been accessed 3,565,449 times.
- About cppreference.com
Assignment operators are used in InfoSphere® DataStage® BASIC assignment statements to assign values to variables. Table 1 shows the operators and their uses.
Table 2 shows some examples of assignment statements.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
C Assignment Operators
- 6 contributors
An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand. Therefore, the left-hand operand of an assignment operation must be a modifiable l-value. After the assignment, an assignment expression has the value of the left operand but isn't an l-value.
assignment-expression : conditional-expression unary-expression assignment-operator assignment-expression
assignment-operator : one of = *= /= %= += -= <<= >>= &= ^= |=
The assignment operators in C can both transform and assign values in a single operation. C provides the following assignment operators:
In assignment, the type of the right-hand value is converted to the type of the left-hand value, and the value is stored in the left operand after the assignment has taken place. The left operand must not be an array, a function, or a constant. The specific conversion path, which depends on the two types, is outlined in detail in Type Conversions .
- Assignment Operators
Submit and view feedback for
You use the basic assignment operator, = , to assign one value to another. The MaxVariablesDemo program uses = to initialize all its local variables: //integers byte largestByte = Byte.MAX_VALUE ; short largestShort = Short.MAX_VALUE ; int largestInteger = Integer.MAX_VALUE ; long largestLong = Long.MAX_VALUE ; //real numbers float largestFloat = Float.MAX_VALUE ; double largestDouble = Double.MAX_VALUE ; //other primitive types char aChar = 'S' ; boolean aBoolean = true ;
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.
- Language Reference
The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to").
The value of an assignment expression is the value assigned. That is, the value of " $a = 3 " is 3. This allows you to do some tricky things: <?php $a = ( $b = 4 ) + 5 ; // $a is equal to 9 now, and $b has been set to 4. ?>
In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic , array union and string operators that allow you to use a value in an expression and then set its value to the result of that expression. For example: <?php $a = 3 ; $a += 5 ; // sets $a to 8, as if we had said: $a = $a + 5; $b = "Hello " ; $b .= "There!" ; // sets $b to "Hello There!", just like $b = $b . "There!"; ?>
Note that the assignment copies the original variable to the new one (assignment by value), so changes to one will not affect the other. This may also have relevance if you need to copy something like a large array inside a tight loop.
An exception to the usual assignment by value behaviour within PHP occurs with object s, which are assigned by reference. Objects may be explicitly copied via the clone keyword.
Assignment by Reference
Assignment by reference is also supported, using the " $var = &$othervar; " syntax. Assignment by reference means that both variables end up pointing at the same data, and nothing is copied anywhere.
Example #1 Assigning by reference
The new operator returns a reference automatically, as such assigning the result of new by reference is an error.
The above example will output:
More information on references and their potential uses can be found in the References Explained section of the manual.
Arithmetic Assignment Operators
Bitwise assignment operators, other assignment operators.
- arithmetic operators
- bitwise operators
- null coalescing operator
User Contributed Notes 7 notes
- Skip to main content
- Skip to search
- Skip to select language
- Sign up for free
- English (US)
Expressions and operators
At a high level, an expression is a valid unit of code that resolves to a value. There are two types of expressions: those that have side effects (such as assigning values) and those that purely evaluate .
The expression x = 7 is an example of the first type. This expression uses the = operator to assign the value seven to the variable x . The expression itself evaluates to 7 .
The expression 3 + 4 is an example of the second type. This expression uses the + operator to add 3 and 4 together and produces a value, 7 . However, if it's not eventually part of a bigger construct (for example, a variable declaration like const z = 3 + 4 ), its result will be immediately discarded — this is usually a programmer mistake because the evaluation doesn't produce any effects.
As the examples above also illustrate, all complex expressions are joined by operators , such as = and + . In this section, we will introduce the following operators:
Comparison operators, arithmetic operators, bitwise operators, logical operators, bigint operators, string operators, conditional (ternary) operator, comma operator, unary operators, relational operators.
These operators join operands either formed by higher-precedence operators or one of the basic expressions . A complete and detailed list of operators and expressions is also available in the reference .
The precedence of operators determines the order they are applied when evaluating an expression. For example:
Despite * and + coming in different orders, both expressions would result in 7 because * has precedence over + , so the * -joined expression will always be evaluated first. You can override operator precedence by using parentheses (which creates a grouped expression — the basic expression). To see a complete table of operator precedence as well as various caveats, see the Operator Precedence Reference page.
A unary operator requires a single operand, either before or after the operator:
An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal ( = ), which assigns the value of its right operand to its left operand. That is, x = f() is an assignment expression that assigns the value of f() to x .
There are also compound assignment operators that are shorthand for the operations listed in the following table:
Assigning to properties
If an expression evaluates to an object , then the left-hand side of an assignment expression may make assignments to properties of that expression. For example:
For more information about objects, read Working with Objects .
If an expression does not evaluate to an object, then assignments to properties of that expression do not assign:
In strict mode , the code above throws, because one cannot assign properties to primitives.
It is an error to assign values to unmodifiable properties or to properties of an expression without properties ( null or undefined ).
Without destructuring, it takes multiple statements to extract values from arrays and objects:
With destructuring, you can extract multiple values into distinct variables using a single statement:
Evaluation and nesting
In general, assignments are used within a variable declaration (i.e., with const , let , or var ) or as standalone statements).
However, like other expressions, assignment expressions like x = f() evaluate into a result value. Although this result value is usually not used, it can then be used by another expression.
By chaining or nesting an assignment expression, its result can itself be assigned to another variable. It can be logged, it can be put inside an array literal or function call, and so on.
The evaluation result matches the expression to the right of the = sign in the "Meaning" column of the table above. That means that x = f() evaluates into whatever f() 's result is, x += f() evaluates into the resulting sum x + f() , x **= f() evaluates into the resulting power x ** y , and so on.
In the case of logical assignments, x &&= f() , x ||= f() , and x ??= f() , the return value is that of the logical operation without the assignment, so x && f() , x || f() , and x ?? f() , respectively.
When chaining these expressions without parentheses or other grouping operators like array literals, the assignment expressions are grouped right to left (they are right-associative ), but they are evaluated left to right .
Note that, for all assignment operators other than = itself, the resulting values are always based on the operands' values before the operation.
For example, assume that the following functions f and g and the variables x and y have been declared:
Consider these three examples:
Evaluation example 1
y = x = f() is equivalent to y = (x = f()) , because the assignment operator = is right-associative . However, it evaluates from left to right:
- The y on this assignment's left-hand side evaluates into a reference to the variable named y .
- The x on this assignment's left-hand side evaluates into a reference to the variable named x .
- The function call f() prints "F!" to the console and then evaluates to the number 2 .
- That 2 result from f() is assigned to x .
- The assignment expression x = f() has now finished evaluating; its result is the new value of x , which is 2 .
- That 2 result in turn is also assigned to y .
- The assignment expression y = x = f() has now finished evaluating; its result is the new value of y – which happens to be 2 . x and y are assigned to 2 , and the console has printed "F!".
Evaluation example 2
y = [ f(), x = g() ] also evaluates from left to right:
- The y on this assignment's left-hand evaluates into a reference to the variable named y .
- The function call g() prints "G!" to the console and then evaluates to the number 3 .
- That 3 result from g() is assigned to x .
- The assignment expression x = g() has now finished evaluating; its result is the new value of x , which is 3 . That 3 result becomes the next element in the inner array literal (after the 2 from the f() ).
- The inner array literal [ f(), x = g() ] has now finished evaluating; its result is an array with two values: [ 2, 3 ] .
- That [ 2, 3 ] array is now assigned to y .
- The assignment expression y = [ f(), x = g() ] has now finished evaluating; its result is the new value of y – which happens to be [ 2, 3 ] . x is now assigned to 3 , y is now assigned to [ 2, 3 ] , and the console has printed "F!" then "G!".
Evaluation example 3
x[f()] = g() also evaluates from left to right. (This example assumes that x is already assigned to some object. For more information about objects, read Working with Objects .)
- The x in this property access evaluates into a reference to the variable named x .
- Then the function call f() prints "F!" to the console and then evaluates to the number 2 .
- The x[f()] property access on this assignment has now finished evaluating; its result is a variable property reference: x .
- Then the function call g() prints "G!" to the console and then evaluates to the number 3 .
- That 3 is now assigned to x . (This step will succeed only if x is assigned to an object .)
- The assignment expression x[f()] = g() has now finished evaluating; its result is the new value of x – which happens to be 3 . x is now assigned to 3 , and the console has printed "F!" then "G!".
Avoid assignment chains
Chaining assignments or nesting assignments in other expressions can result in surprising behavior. For this reason, chaining assignments in the same statement is discouraged .
In particular, putting a variable chain in a const , let , or var statement often does not work. Only the outermost/leftmost variable would get declared; other variables within the assignment chain are not declared by the const / let / var statement. For example:
This statement seemingly declares the variables x , y , and z . However, it only actually declares the variable z . y and x are either invalid references to nonexistent variables (in strict mode ) or, worse, would implicitly create global variables for x and y in sloppy mode .
Note: => is not a comparison operator but rather is the notation for Arrow functions .
An arithmetic operator takes numerical values (either literals or variables) as their operands and returns a single numerical value. The standard arithmetic operators are addition ( + ), subtraction ( - ), multiplication ( * ), and division ( / ). These operators work as they do in most other programming languages when used with floating point numbers (in particular, note that division by zero produces Infinity ). For example:
Bitwise logical operators
Conceptually, the bitwise logical operators work as follows:
- The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32-bit integer: Before: 1110 0110 1111 1010 0000 0000 0000 0110 0000 0000 0001 After: 1010 0000 0000 0000 0110 0000 0000 0001
- Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.
- The operator is applied to each pair of bits, and the result is constructed bitwise.
For example, the binary representation of nine is 1001, and the binary representation of fifteen is 1111. So, when the bitwise operators are applied to these values, the results are as follows:
Note that all 32 bits are inverted using the Bitwise NOT operator, and that values with the most significant (left-most) bit set to 1 represent negative numbers (two's-complement representation). ~x evaluates to the same value that -x - 1 evaluates to.
Bitwise shift operators
The bitwise shift operators take two operands: the first is a quantity to be shifted, and the second specifies the number of bit positions by which the first operand is to be shifted. The direction of the shift operation is controlled by the operator used.
Shift operators convert their operands to thirty-two-bit integers and return a result of either type Number or BigInt : specifically, if the type of the left operand is BigInt , they return BigInt ; otherwise, they return Number .
The shift operators are listed in the following table.
Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value. The logical operators are described in the following table.
Examples of expressions that can be converted to false are those that evaluate to null, 0, NaN, the empty string (""), or undefined.
The following code shows examples of the && (logical AND) operator.
The following code shows examples of the || (logical OR) operator.
The following code shows examples of the ! (logical NOT) operator.
As logical expressions are evaluated left to right, they are tested for possible "short-circuit" evaluation using the following rules:
- false && anything is short-circuit evaluated to false.
- true || anything is short-circuit evaluated to true.
The rules of logic guarantee that these evaluations are always correct. Note that the anything part of the above expressions is not evaluated, so any side effects of doing so do not take effect.
Note that for the second case, in modern code you can use the Nullish coalescing operator ( ?? ) that works like || , but it only returns the second expression, when the first one is " nullish ", i.e. null or undefined . It is thus the better alternative to provide defaults, when values like '' or 0 are valid values for the first expression, too.
Most operators that can be used between numbers can be used between BigInt values as well.
One exception is unsigned right shift ( >>> ) , which is not defined for BigInt values. This is because a BigInt does not have a fixed width, so technically it does not have a "highest bit".
BigInts and numbers are not mutually replaceable — you cannot mix them in calculations.
This is because BigInt is neither a subset nor a superset of numbers. BigInts have higher precision than numbers when representing large integers, but cannot represent decimals, so implicit conversion on either side might lose precision. Use explicit conversion to signal whether you wish the operation to be a number operation or a BigInt one.
You can compare BigInts with numbers.
In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.
The shorthand assignment operator += can also be used to concatenate strings.
If condition is true, the operator has the value of val1 . Otherwise it has the value of val2 . You can use the conditional operator anywhere you would use a standard operator.
This statement assigns the value "adult" to the variable status if age is eighteen or more. Otherwise, it assigns the value "minor" to status .
The comma operator ( , ) evaluates both of its operands and returns the value of the last operand. This operator is primarily used inside a for loop, to allow multiple variables to be updated each time through the loop. It is regarded bad style to use it elsewhere, when it is not necessary. Often two separate statements can and should be used instead.
For example, if a is a 2-dimensional array with 10 elements on a side, the following code uses the comma operator to update two variables at once. The code prints the values of the diagonal elements in the array:
A unary operation is an operation with only one operand.
The delete operator deletes an object's property. The syntax is:
where object is the name of an object, property is an existing property, and propertyKey is a string or symbol referring to an existing property.
If the delete operator succeeds, it removes the property from the object. Trying to access it afterwards will yield undefined . The delete operator returns true if the operation is possible; it returns false if the operation is not possible.
Deleting array elements
Since arrays are just objects, it's technically possible to delete elements from them. This is, however, regarded as a bad practice — try to avoid it. When you delete an array property, the array length is not affected and other elements are not re-indexed. To achieve that behavior, it is much better to just overwrite the element with the value undefined . To actually manipulate the array, use the various array methods such as splice .
The typeof operator returns a string indicating the type of the unevaluated operand. operand is the string, variable, keyword, or object for which the type is to be returned. The parentheses are optional.
Suppose you define the following variables:
The typeof operator returns the following results for these variables:
For the keywords true and null , the typeof operator returns the following results:
For a number or string, the typeof operator returns the following results:
For property values, the typeof operator returns the type of value the property contains:
For methods and functions, the typeof operator returns results as follows:
For predefined objects, the typeof operator returns results as follows:
A relational operator compares its operands and returns a Boolean value based on whether the comparison is true.
The in operator returns true if the specified property is in the specified object. The syntax is:
where propNameOrNumber is a string, numeric, or symbol expression representing a property name or array index, and objectName is the name of an object.
The following examples show some uses of the in operator.
The instanceof operator returns true if the specified object is of the specified object type. The syntax is:
where objectName is the name of the object to compare to objectType , and objectType is an object type, such as Date or Array .
Use instanceof when you need to confirm the type of an object at runtime. For example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.
For example, the following code uses instanceof to determine whether theDay is a Date object. Because theDay is a Date object, the statements in the if statement execute.
All operators eventually operate on one or more basic expressions. These basic expressions include identifiers and literals , but there are a few other kinds as well. They are briefly introduced below, and their semantics are described in detail in their respective reference sections.
Use the this keyword to refer to the current object. In general, this refers to the calling object in a method. Use this either with the dot or the bracket notation:
Suppose a function called validate validates an object's value property, given the object and the high and low values:
You could call validate in each form element's onChange event handler, using this to pass it to the form element, as in the following example:
The grouping operator ( ) controls the precedence of evaluation in expressions. For example, you can override multiplication and division first, then addition and subtraction to evaluate addition first.
You can use the new operator to create an instance of a user-defined object type or of one of the built-in object types. Use new as follows:
The super keyword is used to call functions on an object's parent. It is useful with classes to call the parent constructor, for example.
Assignment Operator in MySQL
Back to: MySQL Tutorials for Beginners and Professionals
Assignment Operator in MySQL with Examples
In this article, I am going to discuss Assignment Operator in MySQL with Examples. Please read our previous article where we discussed SET Operators (UNION, UNION ALL, INTERSECT, & EXCEPT) in MySQL with examples.
The Assignment Operator in MySQL is used to assign or compare a value to a column or a field of a table. The equal sign (=) is the assignment operator where the value on the right is assigned to the value on the left. It is also used to establish a relationship between a column heading and the expression that defines the values for the column.
Example to understand Assignment Operator in MySQL
Let us understand the MySQL Assignment Operator with some examples. We are going to use the following Product table to understand the Assignment Operator.
Please execute the below SQL Script to create and populate the Product table with the required sample data.
Example: Update the Price of each product by adding 10
Now we will update the Price column of the Product table by using the equals operator as an assignment. Following is the SQL statement.
UPDATE Product SET Price = Price + 10;
Once you execute the above Update statement, now verify that the Price column value in the Product table is updated as shown in the below image. SELECT * FROM Product; will give you the following result set.
Here, you can observe the Price column has been updated by raising the existing prices by adding 10. Also, we can use the same operator for comparing values. Following is the example:
UPDATE Product SET Price = Price * 1.02 WHERE ProductId = 6;
Let’s see the updated table: SELECT * FROM Product; will give you the following output.
Here we are updating the Price column of the Product table where the ProductId is 6. And you can observe that only the Price with ProductId =6 has been updated.
Assigning Variables using Assignment Operator in MySQL
There are two ways to assign a value:
- By using SET statement: Using SET statement we can either use := or = as an assignment operator.
- By using SELECT statement: Using SELECT statement we must use := as an assignment operator because = operator is used for comparison in MySQL.
SET variableName = expression; where the variable name can be any variable created. SELECT FieldName = expression; where field name can be any given name.
Example: Using SET Statement in MySQL
SET @MyCounter = 1; SELECT @MyCounter;
In this example, first, we have created a variable @MyCounter and then we are using the assignment operator to set @MyCounter to a value returned by an expression.
Example: Using SELECT Statement in MySQL
Let’s get the most expensive item from the Product table and assigns the Price to the variable @ExpensiveItem. Following is the SQL Statement.
SELECT @ExpensiveItem := MAX(Price) FROM Product;
When you execute the above statement, you will get the following output.
In the next article, I am going to discussed Constraints in MySQL with Examples. Here, in this article, I try to explain Assignment Operator in MySQL with Examples. I hope you enjoy this article.
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *