1 / 11

Functii de conversie

Functii de conversie. Oracle oferă un set bogat de funcţii care vă permit să transformaţi o valoare dintr-un tip de dată în altul. Transformarea din dată calendaristică în şir de caractere.

ashanti
Télécharger la présentation

Functii de conversie

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functii de conversie

  2. Oracle oferă un set bogat de funcţii care vă permit să transformaţi o valoare dintr-un tip de dată în altul.

  3. Transformarea din dată calendaristică în şir de caractere • Transformarea unei date calendaristice în şir de caractere se poate realiza cu ajutorul funcţiei TO_CHAR. Această operaţie se poate dovedi utilă atunci când dorim obţinerea unor rapoarte cu un format precis. Sintaxa acestei funcţii este: • TO_CHAR (dt, format) • dt poate avea unul din tipurile pentru date calendatistice (DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL MONTH TO YEAR, or INTERVAL DAY TO SECOND). Formatul poate conţine mai mulţi parametrii care pot afecta modul în care va arăta şirul returnat.

  4. exemple • select sysdate,to_char(sysdate,'MONTH DD, YYYY') ,to_char(sysdate,'Month DD, YYYY'),to_char(sysdate,'Mon DD, YYYY') from dual • select to_char(sysdate,'"Trimestrul "Q "al anului " Year') from dual • select to_char(sysdate,'"Secolul "CC') from dual • select to_char(sysdate,'Day, dd.RM.YYYY') from dual • Select to_char(sysdate,'Dy, D, DD, DDD') from dual • select to_char(sysdate,'HH24:MI/HH:MI AM') from dual • select to_char(sysdate+1,'ddth') from dual • select to_char(sysdate+1,'ddspth') from dual • select to_char(sysdate+2,'Ddspth') from dual • select to_char(sysdate+10,'DDspth') from dual • select to_char(sysdate,'mmsp') from dual

  5. Formatul RR şiformatul YY

  6. Transformarea din şir de caractere în dată calendaristică • TO_DATEtransforma un şir de caractere într-o dată calendaristică. Sintaxa funcţiei este: • TO_DATE(sir,format) • Formatul nu este obligatoriu, însă dacă nu este precizat, şirul trebuie să respecte formatul implicit al datei calendaristice DD-MON-YYYY sau DD-MON-YY. Formatul poate folosi aceiaşi parametrii de format ca şi funcţia TO_CHAR.

  7. Exemple • Select to_date('7.4.07', 'MM.DD.YY') from dual; • Select to_date('7-4-07') from dual; • select to_date('01022001','ddmmyyyy') from dual • select to_date('010261','ddmmyy') from dual • select to_date('010261','ddmmrr') from dual

  8. Transformarea din număr în şir de caractere TO_CHAR(numar,format)

  9. exemple • select to_char(123.45,'9999.99') from dual 123.45 • select to_char(123.45,'0000.000') from dual 0123.450 • select to_char(123.45,'9.99EEEE') from dual 1.23E+02 • select to_char(-123.45,'999.999PR') from dual <123.450> • select to_char(1.2373,'99999V99') from dual 124 • select to_char(1.2373,'L0000.000') from dual $0001.237

  10. Transformarea şir de caractere în număr • TO_NUMBER(sir,format) select to_number('970.13') + 25.5 FROM dual 995.63 !!! Incorect: select to_number('970.136','999.99') + 25.5 FROM dual Corect: select to_number('970.136','999.999') + 25.5 FROM dual

More Related