Funkcija niza LENGTH jezika strukturiranih poizvedb vrne število znakov danega niza ali besede.
Sintaksa funkcije niza LENGTH
Sintaksa1: Ta sintaksa uporablja funkcijo LENGTH z imenom stolpca tabele SQL:
SELECT LENGTH(Column_Name) AS Alias_Name FROM Table_Name;
V sintaksi moramo določiti ime tistega stolpca, na katerem želimo izvesti funkcijo niza LENGTH za iskanje števila znakov posamezne vrednosti.
Sintaksa2: Ta sintaksa uporablja funkcijo LENGTH z nizom:
SELECT LENGTH(Original_String);
Primeri funkcije LENGTH String
Primer 1: Naslednja poizvedba SELECT prikazuje skupno število znakov dane besede JAVATPOINT:
java je naslednja
SELECT LENGTH( ' JAVATPOINT') AS LENGTH_word;
Izhod:
LENGTH_beseda |
---|
enajst |
Primer 2: Naslednja poizvedba SELECT prikazuje skupno število znakov danega niza:
SELECT LENGTH( 'JAVATPOINT is a good website') AS LENGTH_string;
Izhod:
LENGTH_niz |
---|
28 |
Primer 3: Naslednja poizvedba SELECT prikazuje dolžino danega stavka:
SELECT LENGTH( 'NEW DELHI IS THE CAPITAL OF INDIA') AS LENGTH_Sentence;
Izhod:
globalne spremenljivke javascript
LENGTH_stavek |
---|
33 |
Primer 4: Naslednja poizvedba SELECT prikazuje dolžino danega niza:
SELECT LENGTH( ' ' ) AS LENGTH_space;
Izhod:
LENGTH_presledek |
---|
1 |
Primer 5: Naslednja poizvedba SELECT prikazuje dolžino besede NULL:
SELECT LENGTH( NULL ) AS Length;
Izhod:
Dolžina |
---|
NIČ |
Primer 6: Ta primer uporablja funkcijo LENGTH s tabelo v jeziku strukturiranih poizvedb.
višina zamika
V tem primeru bomo ustvarili novo tabelo SQL, na kateri želimo izvesti funkcijo LENGTH.
Sintaksa za ustvarjanje nove tabele v bazi podatkov SQL je naslednja:
CREATE TABLE table_name ( First_Column_of_table Data Type (character_size of First Column), Second_Column_of_table Data Type (character_size of the Second column ), Third_Column_of_table Data Type (character_size of the Third column), ... Last_Column_of_table Data Type (character_size of the Last column) );
Naslednji stavek CREATE ustvari Employee_Grade tabela:
CREATE TABLE Employee_Grade ( Employee_ID INT PRIMARY KEY, First_Name VARCHAR (100), Last_Name VARCHAR (100), First_City Varchar(120), Second_City Varchar(120), New_City Varchar(120), Attendance_Remarks INT, Work_Remarks INT, Grade Varchar (80) );
Spodnje poizvedbe INSERT vstavijo zapise zaposlenih z ocenami in pripombami v Employee_Grade tabela:
INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (10, Ramesh, Sharma, Lucknow Aurangabad, Ghaziabad, 88, 95, A2); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES ( 02, Yadu, Sharma, Aurangabad, Ghaziabad, Noida, 95, 82, A1 ); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (07, Vijay, Ramna, Noida, Ghaziabad, Lucknow, 91, 95, A1); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (04, Bhanu, Rangopalr, Ghaziabad, Noida, Lucknow, 85, 82, A2); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (11, Harry, Roy, Noida, Kanpur, Ghaziabad, 95, 97, A1); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (16, Akash, Ramna, Ghaziabad, Meerut, Aurangabad, 95, 90, B1); INSERT INTO Employee_Grade (Employee_ID, First_Name, Last_Name, First_City, Second_City, New_City, Attendance_Remarks, Work_Remarks, Grade) VALUES (19, Ram, Ramna, Lucknow, Ghaziabad, Aurangabad, 89, 95, A2);
Naslednji stavek SELECT prikaže vstavljene zapise zgoraj navedenega Employee_Grade tabela:
mysql seznam uporabnikov
SELECT * FROM Employee_Grade;
Employee_ID | Ime | Priimek | First_City | Drugo_mesto | Novo_mesto | Udeležba_Pripombe | Delo_Pripombe | Ocena |
---|---|---|---|---|---|---|---|---|
10 | Ramesh | Sharma | Lucknow | Aurangabad | Ghaziabad | 88 | 95 | A2 |
02 | Širjenje | Sharma | Aurangabad | Ghaziabad | Ghaziabad | 95 | 82 | A1 |
07 | Vijay | Ramna | Noida | Ghaziabad | Lucknow | 91 | 95 | A1 |
04 | Bhanu | Rangopalr | Ghaziabad | Noida | Lucknow | 85 | 82 | A2 |
enajst | Harry | Roy | Noida | Kanpur | Ghaziabad | 95 | 97 | A1 |
16 | Akaša | Ramna | Ghaziabad | Meerut | Aurangabad | 95 | 90 | B1 |
19 | Oven | Ramna | Lucknow | Ghaziabad | Aurangabad | 89 | 95 | A2 |
Poizvedba 1: Naslednja poizvedba SELECT uporablja funkcijo LENGTH s stolpcem First_Name zgornje tabele Employee_Grade:
SELECT First_Name, LENGTH(First_Name) AS LENGTH_FirstName FROM Employee_Grade;
Ta izjava prikazuje dolžino imena vsakega zaposlenega, ki dela v industriji.
Ime | LENGTH_FirstName |
---|---|
Ramesh | 6 |
Širjenje | 4 |
Vijay | 5 |
Bhanu | 5 |
Harry | 5 |
Akaša | 5 |
Oven | 3 |
Poizvedba 2: Naslednja poizvedba SELECT uporablja funkcijo LENGTH s stolpcem Last_Name zgornje tabele Employee_Grade:
SELECT Last_Name, LENGTH(Last_Name) AS LENGTH_LastName FROM Employee_Grade;
Ta izjava prikazuje dolžino priimka vsakega zaposlenega.
ogrodje zbirk java
Izhod:
Priimek | LENGTH_Priimek |
---|---|
Sharma | 6 |
Sharma | 6 |
Ramna | 5 |
Rangopalr | 9 |
Roy | 3 |
Ramna | 5 |
Ramna | 5 |
Poizvedba 3: Naslednja poizvedba SELECT uporablja funkcijo LENGTH s stolpcema First_City in New_City zgornje tabele Employee_Grade:
SELECT First_City, LENGTH(First_City) AS LENGTH_FirstCity, New_City, LENGTH(New_City) AS LENGTH_NewCity FROM Employee_Grade;
Ta stavek SQL prikazuje dolžino prvega in novega mesta vsakega zaposlenega.
Izhod:
First_City | LENGTH_FirstCity | Novo_mesto | LENGTH_Novo mesto |
---|---|---|---|
Lucknow | 7 | Ghaziabad | 9 |
Aurangabad | 10 | Ghaziabad | 9 |
Noida | 5 | Lucknow | 7 |
Ghaziabad | 9 | Lucknow | 7 |
Noida | 5 | Ghaziabad | 9 |
Ghaziabad | 9 | Aurangabad | 10 |
Lucknow | 7 | Aurangabad | 10 |