Docsity

SQL Functions Programmers, Notas de estudo de Eletrônica

Pré-visualização parcial do texto

Baixe SQL Functions Programmers e outras Notas de estudo em PDF para Eletrônica, somente na Docsity!

SQL Functions Programmer’s Reference

Arie Jones

Ryan K. Stephens

Ronald R. Plew

Robert F. Garrett

Alex Kriegel

About the Authors

Arie Jones

Arie Jones is a senior database administrator for Perpetual Technologies, Inc. (www.perptech.com). He holds a master’s degree in physics from Indiana State University and also works as the chief Web architect/DBA for the USPFO for Indiana. Arie’s main specialty is in developing .NET-based database solutions for the gov- ernment. He and his wife and family live outside of Indianapolis, Indiana.

Ryan K. Stephens

Ryan Stephens is the president and CEO of Perpetual Technologies, Inc. (www.perptech.com), an Indianapolis- based IT firm specializing in database technologies. Ryan has been working with SQL and databases for 15 years and has held the positions of project manager, database administrator, and programmer/analyst. Ryan has been teaching database courses for local universities since 1997 and has authored several internationally published books on topics such as database design, SQL, database architecture, database administration, and Oracle. Ryan enjoys discovering new ways to optimize the use of technology to streamline business operations, as well as empowering others to do the same. Ryan and his wife live in Indianapolis with their three children.

Ronald R. Plew

Ronald R. Plew is vice president and CIO for Perpetual Technologies, Inc. (www.perptech.com) in Indianapolis, Indiana. Ron is a Certified Oracle Professional. He has coauthored several internationally published books on SQL and database technology. Ron is also an adjunct professor for Vincennes University in Indiana, where he teaches SQL and various database courses. Ron holds a bachelor of science degree in business administration/management from Indiana Institute of Technology out of Fort Wayne, Indiana. Ron recently retired from the Indiana Army National Guard, where he served as a programmer/analyst. His hobbies include automobile racing, chess, golf, and collecting Indy 500 memorabilia. Ron resides in Indianapolis with his wife Linda.

Robert F. Garrett

Bob Garrett is the software development manager at Perpetual Technologies, Inc. (www.perptech.com). Bob’s languages of preference are Java, C++, and English. He has extensive experience integrating appli- cations with relational databases. Bob has a degree in computer science and mathematics from Purdue University, and lives with his wife and daughter near Indianapolis.

Alex Kriegel

Alex Kriegel is a professional database systems analyst with a major manufacturing firm in Oregon. He has more than 10 years of database experience working with Microsoft SQL Server, Oracle, DB2, Sybase, and PostgreSQL both as developer and DBA. Alex has a bachelor of science degree in solid-state physics from State Polytechnic Institute of Minsk, Belarus, and has earned the Microsoft Certified Solution Developer (MCSD) accreditation. He is the author of SQL Bible. Alex wrote the first draft of approxi- mately two-thirds of this book.

Contributing Authors

Joshua Stephens

Joshua Stephens is a systems administrator/DBA for Perpetual Technologies, Inc. (www.perptech.com). He has eight years of experience in various IT areas. As a former technical writer and trainer, he contin- ues to enjoy helping others through writing. He holds a bachelor of arts degree in pure mathematics and physics from Franklin College. He lives in Franklin, Indiana, with his wife and daughter.

Richard Bulley

Richard is a Ferris State University graduate and received a master of arts degree from Ball State University. He has had 20 years of data processing experience with the United States Air Force and is a United States Air Force Reserves Retiree and currently has over six years of experience as a Sybase and MS SQL Server system DBA.

I would like to dedicate this book to my wife, Jacqueline, for being understanding and supportive during the long hours that it took to complete this book.

— Arie Jones

For Tina, Daniel, Autumn, and Alivia. You are my inspiration.

— Ryan Stephens

For Linda

— Ron Plew

For Becky and Libby

— Bob Garrett

Acknowledgments

Shortly after we accepted this project, it became clear how much of a team effort would be needed to make this book a must-have for anyone’s SQL library. Fortunately, I have an incredible technical team that knows how to come together and get the job done. Most of my thanks go to Arie Jones. Arie stepped up when I needed the most help, unafraid of commitment, confidently accepting another aggressive assignment. Our author team included Arie Jones, Ron Plew, Bob Garrett, Alex Kriegel, and myself. Contributing authors were Joshua Stephens and Richard Bulley. I cannot say enough about their profes- sionalism and technical proficiency. Thank you for being part of another successful project!

Probably as no surprise to the Wiley audience, the author team thanks the editorial staff at Wiley, which is one of the best with whom we have had the pleasure of working. Specifically, we appreciate Jim Minatel’s efforts and confidence in our team, Kevin Shafer’s strict attention to detail, and the technical editorial team’s thoroughness. Their dedication, patience, and thoroughness, we believe, reflect directly on the quality and timely delivery of this book, which would not have been possible without each of them, as well as the unmentioned Wiley staff behind the scenes.

— Ryan Stephens and the author team

Contents

Acknowledgments ix

xii

xiv

xv

xvii

xviii

  • Chapter 1: Exploring Popular SQL Implementations Introduction xxxv
    • Introduction to SQL
    • Understanding the SQL Standard
    • Overview of Vendor Implementations of SQL
      • Oracle
      • IBM DB2 UDB
      • Microsoft SQL Server and Sybase
      • MySQL
      • PostgreSQL
    • Connecting to SQL Databases
    • ANSI SQL Data Types
    • Creating SQL Databases
    • Querying SQL Databases
    • Manipulating Data in SQL Databases
    • Summary
  • Chapter 2: Functions: Concept and Architecture
    • What Is a Function?
      • Simple UNIX Shell Function Example
      • Simple SQL Function Example
    • ANSI SQL Functions
    • Built-in Functions
      • Executing Built-in Functions
      • Practical Uses of Functions
    • Creating, Compiling, and Executing a SQL Function
    • Passing Parameters by Value or by Reference
    • Scope of a Function
      • Better Security
      • Overloading
    • Classifying SQL Functions: Deterministic and Non-Deterministic Functions
      • Oracle
      • IBM DB2 UDB
      • Microsoft SQL Server Contents
      • Sybase
      • MySQL and PostgreSQL
    • Summary
  • Chapter 3: Comparison of Built-in SQL Functions by Vendor
    • Types of Functions
    • Classifying Built-in SQL Functions
      • Oracle
      • IBM DB2 UDB
      • Microsoft SQL Server and Sybase ASE
      • MySQL
      • PostgreSQL
    • Overview of Built-in Functions by Vendor
    • Summary
  • Chapter 4: SQL Procedural Extensions and User-Defined Functions
    • Procedural versus Declarative Languages
    • ANSI SQL Guidance for Procedural Extensions to SQL
    • SQL Procedural Extensions by Vendor
      • Oracle PL/SQL
      • Microsoft or Sybase Transact-SQL
      • IBM Procedural SQL
      • MySQL
      • PostgreSQL
    • Summary
  • Chapter 5: Common ANSI SQL Functions
    • ANSI Query Syntax
    • Aggregate Functions
      • AVG()
      • COUNT()
      • MAX() and MIN()
      • SUM()
    • String Functions
      • ASCII()
      • CHR() or CHAR()
      • CONCAT()
      • LOWER() and UPPER()
      • LENGTH() or LEN()
      • REPLACE()
    • Mathematical Functions Contents
      • ABS()
      • ACOS()
      • ASIN()
      • ATAN() and ATAN2()
      • CEIL() or CEILING() and FLOOR()
      • COS()
      • COSH()
      • COT()
      • DEGREES() and RADIANS()
      • EXP()
      • LOG(), LN(), LOG2(), and LOG10()
      • MOD()
      • PI()
      • POWER()
      • RAND()
      • ROUND()
      • SIGN()
      • SINH()
      • SQUARE()
      • SQRT()
      • TAN()
      • TANH()
      • TRUNC() or TRUNCATE()
    • Miscellaneous Functions
      • COALESCE()
      • NULLIF()
    • Summary
  • Chapter 6: Oracle SQL Functions
    • Oracle Query Syntax
    • Aggregate Functions
      • AVG()
      • CORR()
      • COUNT()
      • GROUPING()
      • MAX() and MIN()
      • STDDEV()
      • SUM()
    • Analytic Functions
  • Character Functions Contents
    • CHR() and NCHR()
    • INITCAP()
    • LPAD() and RPAD()
    • TRIM(), LTRIM(), and RTRIM()
    • REPLACE()
    • SOUNDEX()
    • SUBSTR()
    • TRANSLATE()
  • Regular Expressions
  • Conversion Functions
    • CAST()
    • COMPOSE()
    • CONVERT()
    • DECOMPOSE()
    • TO_CHAR()
    • TRANSLATE...USING
    • UNISTR()
  • Date and Time Functions
    • ADD_MONTHS()
    • DBTIMEZONE and SESSIONTIMEZONE
    • EXTRACT()
    • MONTH_BETWEEN()
    • NEW_TIME()
    • ROUND()
    • SYSDATE
    • TRUNC()
  • Numeric Functions
    • ABS()
    • BITAND()
    • CEIL() and FLOOR()
    • MOD()
    • SIGN()
    • ROUND()
    • TRUNC()
  • Object Reference Functions
  • Miscellaneous Single-Row Functions
    • COALESCE()
    • DECODE()
    • DUMP()
    • GREATEST()
    • NULLIF()
    • NVL()
      • NVL2() Contents
      • UID
      • VSIZE()
    • Summary
  • Chapter 7: IBM DB2 Universal Database (UDB) SQL Functions
    • DB2 UDB Query Syntax
    • String Functions
      • CONCAT()
      • INSERT()
      • LEFT() and RIGHT()
      • LENGTH()
      • LOCATE() and POSSTR()
      • LTRIM() and RTRIM()
      • REPEAT()
      • REPLACE()
      • SOUNDEX()
      • SPACE()
      • SUBSTR()
      • TRUNC() or TRUNCATE()
    • Date and Time Functions
      • DATE()
      • DAY()
      • DAYNAME()
      • DAYOFWEEK()
      • DAYOFWEEK_ISO()
      • DAYOFYEAR()
      • DAYS()
      • HOUR()
      • JULIAN_DAY()
      • MICROSECOND()
      • MIDNIGHT_SECONDS()
      • MINUTE()
      • MONTH()
      • MONTHNAME()
      • SECOND()
      • TIME()
      • TIMESTAMP()
      • TIMESTAMPDIFF()
      • TIMESTAMP_FORMAT()
      • TIMESTAMP_ISO()
      • WEEK()
    • WEEK_ISO() Contents
    • YEAR()
  • Conversion Functions
    • DEC or DECIMAL
    • HEX()
    • DOUBLE or DOUBLE_PRECISION
    • INT() or INTEGER() and SMALLINT()
    • TRANSLATE()
    • VARCHAR()
  • Security Functions
    • DECRYPT_BIN()
    • DECRYPT_CHAR()
    • ENCRYPT()
    • GETHINT()
  • IBM DB2 UDB Special Registers
    • CURRENT DATE
    • CURRENT DEFAULT TRANSFORM GROUP
    • CURRENT DEGREE
    • CURRENT EXPLAIN MODE
    • CURRENT EXPLAIN SNAPSHOT
    • CURRENT ISOLATION
    • CURRENT NODE
    • CURRENT PATH
    • CURRENT QUERY OPTIMIZATION
    • CURRENT REFRESH AGE
    • CURRENT SCHEMA
    • CURRENT SERVER
    • CURRENT TIME
    • CURRENT TIMESTAMP
    • CURRENT TIMEZONE
    • SESSION_USER
    • USER
  • Miscellaneous Functions
    • COALESCE() and VALUE()
    • DIGITS()
    • GENERATE_UNIQUE()
    • NULLIF()
    • RAND()
    • TABLE_NAME()
    • TYPE_ID()
    • TYPE_NAME()
  • Summary
  • Chapter 8: Microsoft SQL Server Functions Contents
    • SQL Server Query Syntax
    • String Functions
      • ASCII()
      • CHAR()
      • CHARINDEX()
      • DIFFERENCE()
      • LEFT() and RIGHT()
      • LEN()
      • LOWER()
      • LTRIM() and RTRIM()
      • NCHAR()
      • PATINDEX()
      • REPLACE()
      • QUOTENAME()
      • REPLICATE()
      • REVERSE()
      • SOUNDEX()
      • SPACE()
      • STR()
      • STUFF()
      • SUBSTRING()
      • UNICODE()
      • UPPER()
    • Date and Time Functions
      • DATEADD()
      • DATEDIFF()
      • @@DATEFIRST()
      • DATENAME()
      • DATEPART()
      • DAY()
      • GETDATE() and GETUTCDATE()
      • MONTH()
      • YEAR()
    • Metadata Functions
      • COL_LENGTH()
      • DB_ID()
      • DB_NAME()
      • FILE_ID()
      • FILE_NAME()
  • Configuration Functions Contents
    • @@CONNECTION
    • @@LANGID
    • @@LANGUAGE
    • @@LOCK_TIMEOUT
    • @@MAX_CONNECTIONS
    • @@NESTLEVEL
    • @@OPTIONS
    • @@SPID
    • @@VERSION
  • Security Functions
    • HAS_DBACCESS()
    • SUSER_SID()
    • SUSER_SNAME()
    • USER
    • USER_ID()
    • USER_NAME()
  • System Functions
    • APP_NAME()
    • CASE
    • CAST() and CONVERT()
    • COALESCE()
    • CURRENT_TIMESTAMP
    • CURRENT_USER
    • DATALENGTH()
    • @@ERROR
    • HOST_ID()
    • HOST_NAME()
    • @@IDENTITY
    • IDENTITY()
    • ISDATE()
    • ISNULL()
    • ISNUMERIC()
    • NEWID()
    • PERMISSIONS()
    • ROWCOUNT_BIG and @@ROWCOUNT
    • @@TRANCOUNT
    • COLLATIONPROPERTY()
    • SCOPE_IDENTITY()
  • System Statistical Functions
    • @@CPU_BUSY
    • @@IDLE