返回首页

gbase数据、南大通用产品文档:GBase8sGCIDirPathColArrayReset

更新日期:2024年09月11日



sword GCIDirPathColArrayReset(
GCIDirPathColArray *dpca,
GCIError *errhp
);

重置数据数组,以便再次重新设置新的内容。

参数
输入
/输出


dpca
输入
数据数组描述符指针
errhp
输入
错误信息句柄, 该接口调用失败时, 错误信息会存在该句柄上

如果执行成功, 返回GCI_SUCCESS,否则返回GCI_ERROR。

dectodbl() 函数将 decimal 类型数值转换为 C double 类型值。
语法
mint dectodbl(dec_val, dbl_val)
dec_t *dec_val;
double *dbl_val;
dec_val

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 661 -

指向 dectodbl() 将其值转换为 double 类型值的 decimal 结构的指针。
dbl_val
指向 dectodbl() 放置转换的结果处的 double 类型的指针。

用法
在 decimal 类型数值转换为 double 类型数值 过程中,主计算机的浮点格式可导致
精度的损失。

返回代码
0
转换成功。
<0
转换失败。

示例

demo 目录中的 dectodbl.ec 文件包含下列样例程序。
/*
* dectodbl.ec *

The following program converts two DECIMAL numbers to doubles and displays the
results.
*/

#include

EXEC SQL include decimal;

char string1[] = "2949.3829398204382";
char string2[] = "3238299493";
char result[40];

main()

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 662 -

{
mint x;
double d = 0;
dec_t num;

printf("DECTODBL Sample ESQL Program running.\n\n");

if (x = deccvasc(string1, strlen(string1), #))
{
printf("Error %d in converting string1 to DECIMAL\n", x);
exit(1);
}
if (x = dectodbl(#, &d))
{
printf("Error %d in converting DECIMAL1 to double\n", x);
exit(1);
}
printf("String 1 = %s\n", string1);
printf("Double value = %.15f\n", d);

if (x = deccvasc(string2, strlen(string2), #))
{
printf("Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
if (x = dectodbl(#, &d))
{
printf("Error %d in converting DECIMAL2 to double\n", x);
exit(1);
}
printf("String 2 = %s\n", string2);
printf("Double value = %f\n", d);


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 663 -

printf("\nDECTODBL Sample Program over.\n\n");
exit(0);
}
输出
DECTODBL Sample ESQL Program running.

String 1 = 2949.3829398204382
Double value = 2949.382939820438423

String 2 = 3238299493
Double value = 3238299493.000000

DECTODBL Sample Program over.

返回expr 的标准方差(standard variance)。这是对标准SQL 的扩展。标准SQL 函
数VAR_POP()可以代替使用。
GBase UP 扩展了GROUP BY 的用法。
在SELECT 表达式中,
用户可以使用或计算
没有出现在GROUP BY 部分中的列,它代表这个组的任何可能的值。用户可以使
用它避免在不必要的分类项目上进行排序和分组,这样会得到更好的性能。
示例

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 572
示例1:
gbase> SELECT C.C_CITY, L.LO_SHIPMODE,L.LO_SUPPLYCOST,MAX(L.LO_SUPPLYCOST) FROM
SSBM.LINEORDER L, SSBM.CUSTOMER C WHERE L.LO_CUSTKEY=C.C_CUSTKEY GROUP BY
L.LO_SHIPMODE;
+------------+----------------------------------------------------+
| C_CITY | LO_SHIPMODE | LO_SUPPLYCOST | MAX(L.LO_SUPPLYCOST) |
+-------+----------------------------------+----------------------+
| SAUDI ARAO | TRUCK | 74711 | 125939 |
| SAUDI ARAO | MAIL | 76638 | 125939 |
| SAUDI ARAO | REG AIR | 99822 | 125939 |
| SAUDI ARAO | AIR | 62047 | 125939 |
| SAUDI ARAO | FOB | 57061 | 125939 |
| RUSSIA 5 | RAIL | 70570 | 125939 |
| EGYPT 9 | SHIP | 88646 | 125939 |
+-------+---------------------------------------------------------+
7 rows in set (4.71 sec)
如果用户在GROUP BY 部分省略的列在分组中不是唯一的,请不要使用这个特性,
否则将得到不可预知的结果。
GROUP BY 优化
使用hint 优化GROUP BY:
drop table if exists users,products,orders;
create table users(u_id int,u_name char(10),birthday datetime,address varchar(10));
create table products(p_id int,p_name char(10),price float,stocks int);

create table orders(o_id int,u_id int,p_id int,amount int);

insert into users values (0,'zhao','1990-12-29 12:00:00','中国.吉林.长春');
insert into users values (1,'qian','1990-12-29 12:00:00','中国.北京');
insert into users values (2,'sun','1990-12-29 12:00:00','中国.上海');
insert into users values (3,'li','1990-12-29 12:00:00','中国.天津');
insert into users values (4,'zhou','1990-12-29 12:00:00','中国.湖北.武汉');
insert into users values (5,'wu','1990-12-29 12:00:00','中国.湖南.长沙');
insert into users values (6,'zheng','1990-12-29 12:00:00','中国.河北.沧州');
insert into users values (7,'wang','1990-12-29 12:00:00','中国.辽宁.沈阳');
insert into users values (8,'zhao','1990-12-29 12:00:00','中国.云南.昆明');
insert into users values (9,'li','1990-12-29 12:00:00','中国.西藏.拉萨');
insert into orders values (600001,1,100010,2500);
insert into orders values (600002,3,100008,3500);
insert into orders values (600003,4,100009,500);
insert into orders values (600004,5,100007,5000);
insert into orders values (600005,9,100003,2510);
insert into orders values (600006,0,100004,10500);

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 573
insert into orders values (600007,3,100002,5500);
insert into orders values (600008,3,100001,6000);
insert into orders values (600009,4,100009,2100);
insert into orders values (600010,5,100001,1300);
insert into orders values (600011,6,100007,8900);
insert into orders values (600012,9,100008,2900);
insert into orders values (600013,2,100009,6900);
insert into orders values (600014,1,100002,3600);
insert into orders values (600015,1,100003,1500);
SELECT /*+ first_groupby */ distinct `users`.u_name , sum(orders.amount) FROM users,
orders WHERE
users.u_id =
orders.u_id
GROUP BY
`users`.u_name
ORDER BY `users`.u_name
limit 3;
上面的sql 会先在orders 表上做group by 之后再去join users。
注意
如果使用命令行工具,在启动命令行工具时需要加 -c 参数。
由于数据库之间的差异,VARIANCE()同oracle VARIANCE()的函数行为不一
致。
OLAP 函数
GBase UP 提供了丰富的OLAP 函数,辅助用户完成一些复杂的查询统计。在使用
这些函数时,请注意以下几点事项:

OLAP 函数中的PARTITION BY 和ORDER BY 的括号内不再支持使用别名。
SELECT a AS e ,RANK() OVER(ORDER BY e) FROM t1; -- a AS e 后OVER(ORDER
BY e)引用了别名e,不支持此种别名引用。

OLAP 函数中的PARTITION
BY 和ORDER
BY 的括号内的整型数值不是用于指定查
询结果列的索引。
SELECT a, RANK() OVER(ORDER BY 1) FROM t1;在这个查询语句中,ORDER BY
括号里的1 不是用于指定引用查询结果列的索引的含义,即不是指代a 列,而
是当作常量1 来处理。
GROUP BY 类函数
演示所用的表及数据。
DROP TABLE IF EXISTS t3;
CREATE TABLE t3 (color_type varchar(20),color_count int, in_date date);
插入演示数据。

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 574
INSERT INTO t3 (color_type,in_date,color_count) VALUES('black','2010-09-11',18),('b
lack','2010-10-05',18),('black','2010-10-13',31),('blue','2010-09-21',23),('blue','
2010-09-30',15),('blue','2010-10-11',62),('red','2010-09-12',41),('red','2010-10-01
',12),('red','2010-10-05',11);