Quick preface: this answer was based on the originally incorrect tag that this question was relating to SQL Server. I'm no longer aware of its validity on Oracle SQL Developer.*
ALTER TABLE Employees ADD FullName AS (FirstName + ' ' + LastName)
Although in practice I'd advise that you do that operation in your SELECT . That's somewhat personal preference, but I tend to think doing things in your end queries is a bit cleaner, more readable, and easier to maintain than storing extra, calculated columns.
Edit:
This was eventually found as the answer, and listed by the OP as a comment on this post. The following is appropriate syntax for Oracle Sql Database.
ALTER TABLE emps MODIFY (FULL_NAME VARCHAR2(50) GENERATED ALWAYS AS (first_name || ' ' || last_name) VIRTUAL);
In addition to @Jacky 's answer, if you are trying to add this to a query and not the table, there is also the CONCAT() function that you can use in the select statement
SELECT CONCAT(FirstName, ' ', LastName) as FullName
FROM table_name
5条答案
按热度按时间hvvq6cgz1#
Although in practice I'd advise that you do that operation in your
SELECT
. That's somewhat personal preference, but I tend to think doing things in your end queries is a bit cleaner, more readable, and easier to maintain than storing extra, calculated columns.Edit:
This was eventually found as the answer, and listed by the OP as a comment on this post. The following is appropriate syntax for Oracle Sql Database.
2w2cym1i2#
如果在从数据库中选择时始终需要fullname列,则可以在创建employee表时创建计算列。
例如:
92dk7w1h3#
这取决于您的目的,您是真的需要向数据库中添加新列,还是只需要根据需要查询出“全名”。
要动态查看,只需运行查询即可
SELECT firstname + ' ' + lastname AS FullName FROM employees
除此之外,您还可以创建一个简单的存储过程来存储它。
ttisahbt4#
(For单一结果在where条件中使用等于)
nue99wik5#
In addition to @Jacky 's answer, if you are trying to add this to a query and not the table, there is also the CONCAT() function that you can use in the select statement