Usebenzisa njani ukuGuqulwa kohlobo lweDatha yeCAST nge-SQL

Ngu-Allen G. Taylor

Ngokufanelekileyo, ikholamu nganye kwitafile yedatha ye-SQL inokukhetha ngokuchanekileyo kohlobo lwedatha. Kweli hlabathi lingenakulungeleka, nangona kunjalo, kanye kanye nokuba loluphi ukhetho olugqibeleleyo lunokuba akusoloko kucacile. Ekuchazeni itafile yedatha, masithi unikezela uhlobo lwedatha kwikholamu esebenza ngokugqibeleleyo kwisicelo sakho sangoku.



Masithi kamva ufuna ukwandisa ubungakanani besicelo sakho - okanye ubhale isicelo esitsha esisebenzisa idatha ngokwahlukileyo. Olu setyenziso lutsha lunokufuna uhlobo lwedatha eyahlukileyo kuleyo ubukhethe yona kwasekuqaleni.



Unokufuna ukuthelekisa ikholamu yohlobo olunye kwitafile enye kunye nekholamu yohlobo olwahlukileyo kwitafile eyahlukileyo. Umzekelo, unokuba nemihla egcinwe njengedatha yomlinganiswa kwitafile enye kunye nedatha yomhla kwenye itafile.

Nokuba zombini iikholamu ziqulathe uhlobo olufanayo lolwazi (imihla, umzekelo), inyani yokuba ezi ntlobo zahlukile inokukuthintela ekwenzeni uthelekiso. Kwimigangatho yokuqala ye-SQL, i-SQL-86 kunye ne-SQL-89, uhlobo lokungangqinelani lubangele ingxaki enkulu. I-SQL-92, nangona kunjalo, yazisa isisombululo ekulula ukusisebenzisa kwifayile ye-QHUBAintetho.



Inkqubo ye-QHUBAintetho iguqula idatha yeetafile okanye ukubamba okungafaniyo kolunye uhlobo ukuya kolunye uhlobo. Emva kokwenza uguquko, ungaqhubeka nokusebenza okanye uhlalutyo obukucinga ngalo kwasekuqaleni.

Ngokwendalo, ujongene nezithintelo ezithile xa usebenzisa ifayile ye-QHUBAintetho. Awunakho ukuguqula ngokungakhethiyo idatha yalo naluphi na uhlobo lube lolunye uhlobo. Idatha oyiguqulayo kufuneka ihambelane nodidi lwedatha entsha. Unokwenza, umzekelo, usebenziseQHUBAukuguqulaCHAR (10 GS amanqaku).umtya ongumlinganiswa‘2007-04-26’kwiUMHLAchwetheza.

Kodwa awukwazi ukusebenzisaQHUBAukuguqulaCHAR (10 GS amanqaku).umtya ongumlinganiswa‘Umkhombe’kwiUMHLAchwetheza. Awunakho ukuguqula iNGAPHAKATHIkwiIntetho yesibongo, imvelaphi, ukuhambelana kwefayili SMALLINChwetheza ukuba eyangaphambili ingaphezulu kobukhulu beIntetho yesibongo, imvelaphi, ukuhambelana kwefayili SMALLIN.



Ungawuguqula umba walo naluphi na uhlobo lomlinganiswa uluguqulele nakwezinye iintlobo (ezinamanani okanye umhla) ngaphandle kokuba ixabiso lento linefomathi yohlobo lwenene. Ngokuchasene noko, unokuguqula into yalo naluphi na uhlobo lube kulo naluphi na udidi lweempawu, ukuba ixabiso yento leyo inefomathi yokoqobo yohlobo loqobo.

Olu luhlu lulandelayo luchaza ezinye iinguqulelo onokuzenza:

  • Naluphi na uhlobo lwamanani kulo naluphi na olunye uhlobo lwamanani. Ukuba uguqulela kuhlobo oluchanekileyo olungahlukanga kangako, inkqubo iyajikeleza okanye inciphise iziphumo.

  • Naluphi na uhlobo lwenani oluchanekileyo kwisithuba esinye secandelo, njengeUSUKU LWANGAPHAKATHIokanyeUKUNGENELA UMZuzwana.

  • Nokuba yeyiphiUMHLAiya kuIXESHA ELITSHA. Ixesha lexesha leIXESHA ELITSHAUgcwalisa ngoziro.

  • Nokuba yeyiphiIXESHAiya kuIXESHAngokuchaneka ngokwahlukileyo kwemizuzwana engama-fractional okanye aIXESHA ELITSHA. Inxalenye yomhlaIXESHA ELITSHAizalisa umhla okhoyo ngoku.

  • Nokuba yeyiphiIXESHA ELITSHAiya kuUMHLA, ukuyaIXESHA, okanye aIXESHA ELITSHAngokuchaneka okwahlukileyo kwemizuzwana eqingqiweyo.

  • Nawuphi na unyaka-wenyangaNGAPHAKATHIkuhlobo ngqo lwamanani okanye kwenye inyanga-yenyangaNGAPHAKATHIngokuchaneka okungafaniyo kwentsimi.

  • Naliphi na ixesha losukuNGAPHAKATHIkuhlobo ngqo lwamanani okanye elinye ixesha losukuNGAPHAKATHIngokuchaneka okungafaniyo kwentsimi.

    Kutheni ndihlala ndilambile

Uyisebenzisa kanjani i-CAST ngaphakathi kwe-SQL

Masithi usebenzela inkampani egcina umkhondo wabo banokuba ngabasebenzi kunye nabasebenzi obaqeshileyo. Uludwe lwabasebenzi abanokubakho kwitheyibhile enamagamaINKQUBO, Kwaye uyahlulahlula ngamanani abo oKhuseleko lweNtlalo, oya kuthi ugcinwe njengeCHAR (9)chwetheza.

Uludwe lwabasebenzi kwitheyibhile enamagamaUMQESHWA, kwaye uyabahlula ngenani labo loKhuseleko lwezeNtlalontle, elileliNGAPHAKATHIchwetheza. Ngoku ufuna ukuvelisa uluhlu lwabo bonke abantu ababonakala kuzo zombini iitafile. UngasebenzisaQHUBAukwenza lo msebenzi:

SELECT * FROM EMPLOYEE WHERE EMPLOYEE.SSN = CAST(PROSPECT.SSN AS INTEGER) ;

Uyisebenzisa kanjani i-CAST phakathi kwe-SQL kunye nolwimi olusindayo

Ukusetyenziswa okuphambili kweQHUBAUkujongana neentlobo zedatha ezikhoyo kwi-SQL kodwa hayi kulwimi olusindayo olusebenzisayo. Olu luhlu lulandelayo lubonelela ngemizekelo yezi ntlobo zedatha:

  • I-SQL inayoISIGQIBOkwayeNGOLWAZI, kodwa i-FORTRAN noPascal abayenzi.

  • I-SQL inayoUMKHAMBAkwayeYINYANISO, kodwa i-COBOL esemgangathweni ayenzi njalo.

  • I-SQL inayoIXESHA LEXESHA, Alukho olunye ulwimi olunalo.

Masithi ufuna ukusebenzisa i-FORTRAN okanye iPascal ukufikelela kwiitafile ngeISIGQIBO (5,3)iikholamu, kwaye awufuni nakuphi na ukungalunganga okunokubangela ukuguqula loo maxabiso aye kwiYINYANISOUhlobo lwedatha olusetyenziswa yi-FORTRAN kunye noPascal. Unokwenza lo msebenzi ngokusebenzisaQHUBAukuhambisa idatha ukuya nokusuka kumtya womlinganiswa oguquguqukayo.

Ufumana umvuzo wamanani we-198.37 njengo-aCHAR (10 GS amanqaku).Ixabiso le‘0000198.37’. Ke, ukuba ufuna ukuhlaziya loo mvuzo uye kuma-203.74, ungabeka elo xabiso kwiCHAR (10 GS amanqaku).njenge‘0000203.74’. Kuqala usebenzisaQHUBAUkutshintsha i-SQLISIGQIBO (5,3)uhlobo lwedatha kwiCHAR (10 GS amanqaku).Chwetheza umqeshwa onombolo yakhe yesazisi oyigcinileyo kumamkeli wenginginya: emp_id_var, ngoku Landelayo:

SELECT CAST(Salary AS CHAR(10)) INTO :salary_var FROM EMP WHERE EmpID = :emp_id_var ;

Isicelo se-FORTRAN okanye sePascal sivavanya ixabiso lomtya ongumlinganiso onesiphumo: umvuzo_var, ngokunokwenzeka ubeka umtya kwixabiso elitsha le-‘000203.74’, Kwaye emva koko uhlaziye isiseko sedatha ngokubiza le khowudi ilandelayo ye-SQL:

UPDATE EMP SET Salary = CAST(:salary_var AS DECIMAL(5,3)) WHERE EmpID = :emp_id_var ;

Ukujongana namaxabiso omtya womlinganiswa onje nge‘000198.37’kunzima kwi-FORTRAN okanye kwi-Pascal, kodwa ungabhala iseti yeemowudi zokwenza ubuqhetseba obuyimfuneko. Emva koko unokufumana kwaye uhlaziye nayiphi na idatha ye-SQL kulo naluphi na ulwimi lokubamba, kwaye ufumane-kwaye usete-amaxabiso ngqo.

Umbono ngokubanzi kukubaQHUBAibaluleke kakhulu ekuguquleni phakathi kweendidi zokubamba kunye nesiseko sedatha kunokuguqula ngaphakathi kwiziko ledatha.