Sybase database migrated to FAQ (2) of AS 400 DB2

zhaozj2021-02-17  58

The previous introduced the top ten suggestions.

11. If it is a single character, such as "'" how to combine stitching?

A: You can also use char () to perform ASCII conversion

For example: Declare vc_char char (1);

Declare VC_Temp Char (10);

Set vc_char = char (39); - 39 IS 'ASCII

12. How does DB2 creates a constraint?

A: The syntax is as follows: Alter Table XHzq.info_sku_tab

Add constraint xhzq.ckc_c_dianzicheng_fla_info_sku

Check (c_dianzicheng_flag in ('0', '1', '2'));

13. How to create an index under DB2?

A: CREATE UNIQUE INDEX UNIQUE_NAME ON Project (Projname)

Create Index Job_BY_DPT ON EMPLOYEE (WorkDept, Job)

14. How to use the global variable @@ rowcount, DB2 in Sybase?

A: There is also this global variable in DB2, which is specifically used as follows:

Using statements by declaring variable tempcount

Declare Tempcount Bigint Default = 0;

Get Diagnostics Tempcount = row_count;

Get, row_count equivalent to DB2 @@ rowcount

15. How does DB2 manage transactions?

Answer: Transaction management in DB2 is also supporting automatic transaction management and user management transactions.

Create Procedure XXX.Proc_name

(.......)

BEGIN AUTMIC - System Automatic Management

End

Begin

If the system automatically manages transactions, COMMIT, ROLLBACK is not allowed in the script,

Using this method, if you use bundled SQLCode, SQLSTATE, and cursors, the functionality of the system can automatically control the cursor.

IF (xx) THEN

Commit Work hold;

Else

Rollback Work Hold;

END IF;

End

16. DB2 VARCHAR () function usage?

Answer: VARCHAR (PAR, Length) function, convert PAR to become a growing string

PAR: Parameter Character, Integer, Decimal, Numeric, Float, Graph

Length: parameter string length

For example: SELECT VARCHAR (Empno, 10)

INTO: VARHV

From Employee

17. DB2 SING () function usage?

A: Sing (par) function judgment PAR size and zero comparison

If Par <0 returns -1

If PAR> 0 returns 1

If PAR = 0 returns 0

For example: Select Sign (: Profit)

From Employee

18. How do DB2 creates a user-defined function?

A: Give out an example below

/ *

Function name to_char

Argument: (in) TimeStamp, Format

Comm: Convert the date to the format of the character format RUTURN: Develop a format string

Author: Dekker Date: 2003-09-12

* /

Create function xhzq_db.to_char (T1 TimeStamp, Format Varchar (32))

Returns varchar (26)

Language SQL

Reads SQL Data

No External Action

Begin

Declare chs_tmstmp char (26);

Declare Retval Varchar (26);

SET CHS_TMSTMP = CHAR (T1);

Case Trim (Format)

When 'DD'

THEN SET RETVAL = SUBSTR (CHS_TMSTMP, 9, 2);

WHEN 'mm'

THEN SET RETVAL = SUBSTR (CHS_TMSTMP, 6, 2);

When 'YYYY'

THEN SET RETVAL = Substr (CHS_TMSTMP, 1, 4);

When 'YYYY-MM-DD'

THEN SET RETVAL = SUBSTR (CHS_TMSTMP, 1, 10);

Else Signal SqlState '38Z01'

Set message_text = 'invalid format specified.';

End Case;

Return RetVal;

END;

19. Use getDate () in Sybase to get the current date time, how did DB2 get?

A: Now (),

VALUES CURRENT DATE;

VALUES CURRENT TIME;

VALUES CURRENT TIMESTAMP;

20. What is the online help URL of DB2?

Answer http://publib.boulder.ibm.com/iseries/v5r2/ic2989/index.htm?info/db2/rbafzmsthctabl.htm

转载请注明原文地址:https://www.9cbs.com/read-30069.html

New Post(0)