跳转到内容

生物信息学中的数据管理/整合 SQL 和编程语言

来自维基教科书,自由的教科书

嵌入 SQL

[编辑 | 编辑源代码]
int main ()
{
    EXEC SQL BEGIN DECLARE SECTION
        char name[30];
        char annotation[30];
        int gid;
        char SQLSTATE[6];   // will hold the SQL transaction codes
    EXEC SQL END DECLARE SECTION
    char x[30];

    ...

    cout << "Please enter some values" << endl;
    cin >> name;

    ...

    EXEC SQL
        INSERT INTO GENES VALUES(:gid, :annotation, :name);

    EXEC SQL
        SELECT name
        INTO :x
        FROM Genes
        WHERE gid = 23;
}

使用游标

[编辑 | 编辑源代码]
EXEC SQL DECLARE db_cursor CURSOR
    FOR [
        ...
    ]

EXEC SQL OPEN db_cursor
    EXEC SQL FETCH FROM db_cursor
        INTO ...	// put into array and process
EXEC SQL CLOSE db_cursor

存储过程

[编辑 | 编辑源代码]

保留在数据库空间

CREATE FUNCTION FACTORIAL
AS {
    ...
}
LANGUAGE 'c';

SELECT FACTORIAL(num)
FROM Numbers;
华夏公益教科书