1

I have a table with Last Names, First Names, Hours and GPA's.

How do I create a view that displays a concatenated first name and last name, the StudentID and the GPA of the students who have passed at least 90 hours.

The concatenated names should be separated with one space. The three column headings should be FullName, StudentID and GPA. The rows should be sorted by last names, then first names.

Please help. I am lost as to how to approach this.

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
Ana Mar
  • 31
  • 2
  • 3
  • 9
  • 1
    What have you tried? What part of the task is causing you a problem? Do you know how to create a view from a query, for example, but don't know how to write this query? Do you know how to write a select statement in general? Are you just trying to understand the syntax for concatenating strings in Oracle SQL? – Justin Cave Jul 01 '15 at 16:17
  • 1
    see also: http://stackoverflow.com/questions/1619259/oracle-sql-concatenate-multiple-columns-add-text – C8H10N4O2 Jul 01 '15 at 16:21
  • The problem is that when I create the view, it doesn't display the real name, it just says FirstNameLastName, it displays the other values correctly but not the concat name – Ana Mar Jul 01 '15 at 17:16
  • If it just says literally FirstNameLastName for every row it means you're passing the strings "FirstName" and "LastName" instead of the variables for first name and last name as arguments to concat – C8H10N4O2 Jul 01 '15 at 18:50
  • [Edit] your question to include what you have tried. – C-Pound Guru Jul 01 '15 at 19:42

1 Answers1

2

Use the operator || for concatenation (so you don't have to do nested CONCAT()).

Example:

create view v as 
    select (firstname || ' ' || lastname) "FullName", GPA, StudentId 
    from table
    where Hours>90
    order by lastname, firstname
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
  • Do you know why it shows the full name as FirstNameLastName instead of the real values – Ana Mar Jul 01 '15 at 17:17
  • Is it possible that you're passing character strings like `"FirstName"` instead of variable names like `FirstName` into your `select` statement? Check your quotation marks. – C8H10N4O2 Jul 01 '15 at 17:21