1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-->
<chapter label="sqlfunctions.xml" id="sqlfunctions">
<title>SQL Functions Guide</title>
<bridgehead>Virtuoso Functions Guide</bridgehead>
<abstract>
<para>Virtuoso SQL Functions Guide comprises a list of the Virtuoso native functions, their syntax and how to use with examples.
</para></abstract>
<!-- ======================================== -->
<sect1 id="StringFunctions">
<title>String Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>Length</title>
<funcsynopsis>
<funcdef>integer <function>length</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> string or object id or array or blob or NULL</paramdef>
</funcsynopsis>
<para>
Returns the length of its argument.
</para>
<para>
With ordinary strings the length of the string without the terminating zero byte is returned.
</para>
<para>
With object ids, the length of whole object id is returned, including the four byte class specifier.
</para>
<para>
If the argument is NULL, zero is returned.
</para>
<para>
If the argument is a blob and its length is known, then that length is returned. If the length of the blob is not yet known (e.g. it is supplied
directly from the client with SQLPutData) effects are unpredictable (for example an eternal loop), or zero is returned.
</para>
<screen>
length('Abacus') -> 6
length('') -> 0
length(NULL) -> 0
select max(length(CHARCOL)) from TEST;
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>aref</title>
<funcsynopsis>
<funcdef>
<function>aref</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> array or string</paramdef>
<paramdef>
<parameter>nth</parameter> integer</paramdef>
</funcsynopsis>
<para>aref returns nth element of an array or string, where nth is a zero-
based index. If the first argument is a string, the ASCII value of the
nth character is returned as an integer. If the first argument is an
array of other elements, then the corresponding element is returned.
</para>
<screen>aref('Abacus',0) -> 65
aref(vector('Primero',2,3.333),2) -> 3.333000
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Aset</title>
<funcsynopsis>
<funcdef>
<function>aset</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> string</paramdef>
<paramdef>
<parameter>nth</parameter> integer</paramdef>
<paramdef>
<parameter>elem</parameter> integer</paramdef>
</funcsynopsis>
<para> aset sets the nth element of a string, where nth is a zero-based
index. If the first argument is a string, the nth character of
string is replaced with the ASCII value given in the third argument elem.
</para>
<para> Currently the first argument should be a string, not any other type
of an array. This will be changed in future releases, when it will be
possible to modify arrays also (created for example with vector).
</para>
<para> aset returns back the elem inserted, which indeed is quite
unnecessary, but is required by the current implementation.
</para>
<screen>create procedure revstr(in str varchar)
{ -- E.g. revstr('repaid') -> 'diaper'
-- does this in place and modifies str!
declare len,inx1,inx2,tmp integer;
if(str is null) return(str);
len := length(str);
if(len < 2) return(str); -- Remains same.
inx1 := 0; -- Index from the left.
inx2 := len-1; -- Index from the right.
len := len/2; -- Upper limit for inx1.
while(inx1 < len)
{
tmp := aref(str,inx1);
aset(str,inx1,aref(str,inx2));
aset(str,inx2,tmp);
inx1 := inx1 + 1;
inx2 := inx2 - 1;
}
return(str);
};
select revstr(CHARCOL) from TEST;
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>ascii</title>
<funcsynopsis>
<funcdef>
<function>ascii</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> string or object id</paramdef>
</funcsynopsis>
<para> ascii returns the ASCII value of the first character of a string or an
object id. If an empty string is given, then zero is returned.
</para>
<screen>ascii('Zardoz') -> 90
</screen>
</formalpara>
<note>
<title>Note:</title>
<para>
ascii(str) is equal to aref(str,0)
</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>chr</title>
<funcsynopsis>
<funcdef>
<function>chr</function>
</funcdef>
<paramdef>
<parameter>asciivalue</parameter> integer</paramdef>
</funcsynopsis>
<para> chr returns a new one character long string, with the character whose
ASCII value is asciivalue as its first character and only character.
</para>
<screen>chr(33) -> '!'
</screen>
</formalpara>
<note>
<title>Note:</title>
<para>
ascii(chr(val)) is equal to val.</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Repeat</title>
<funcsynopsis>
<funcdef>
<function>repeat</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>count</parameter> integer</paramdef>
</funcsynopsis>
<para>
repeat returns a new string, composed of the string str repeated count
times. If count is zero, an empty string '' is returned.
</para>
<screen>
repeat('bar',2) -> 'barbar'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>space</title>
<funcsynopsis>
<funcdef>
<function>space</function>
</funcdef>
<paramdef>
<parameter>count</parameter> integer</paramdef>
</funcsynopsis>
<para> space returns a new string, composed of count spaces. If count is zero,
an empty string '' is returned.
</para>
<screen>space(5) -> ' '
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> space(count) is equal to repeat(' ',count),
and space(1) is equal to chr(32).</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>make_string</title>
<funcsynopsis>
<funcdef>
<function>make_string</function>
</funcdef>
<paramdef>
<parameter>count</parameter> integer</paramdef>
</funcsynopsis>
<para>make_string returns a new string of length count, filled with zeros.
</para>
<para>
If count is zero, an empty string '' is returned.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Concat</title>
<funcsynopsis>
<funcdef>
<function>concat</function>
</funcdef>
<paramdef>
<parameter>str1</parameter> string</paramdef>
<paramdef>
<parameter>str2</parameter> string</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
<paramdef>
<parameter>strn</parameter> string</paramdef>
</funcsynopsis>
<para>concat returns a new string, concatenated from a variable number of
strings given as arguments.
</para>
<para>
concat(str) just copies the string str.
</para>
<para>
concat() returns an empty string.
</para>
<screen>concat('Muuli','aasi') -> 'Muuliaasi'
</screen>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>concatenate</title>
<funcsynopsis>
<funcdef>string <function>concatenate</function>
</funcdef>
<paramdef>
in <parameter>arg_1</parameter> any</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
</funcsynopsis>
<para>
This function returns the concatenation of its arguments, which
must all be strings or null. A null argument
is ignored in the concatenation. If at least one
of the arguments is wide the result will be wide.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>replace</title>
<funcsynopsis>
<funcdef>string <function>replace</function>
</funcdef>
<paramdef>
in <parameter>string</parameter> varchar</paramdef>
<paramdef>
in <parameter>what</parameter> varchar</paramdef>
<paramdef>
in <parameter>repl_with</parameter> varchar</paramdef>
</funcsynopsis>
<para>
This replaces every occurrence of the second argument in the first argument
with the third argument. The arguments can be narrow or wide strings.
</para>
<example>
<title>Example:</title>
<programlisting>
SQL> select replace ('12345512345', '23', '-----');
= 1-----4551-----45
</programlisting>
</example>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Sprintf</title>
<funcsynopsis>
<funcdef>
<function>sprintf</function>
</funcdef>
<paramdef>
<parameter>format</parameter> string</paramdef>
<paramdef>
<parameter>arg1</parameter> anything</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
<paramdef>
<parameter>arg8</parameter> anything</paramdef>
</funcsynopsis>
<para> sprintf returns a new string formed by "printing" a variable number (max.
eight) of arguments arg1 - arg8 according to the format string format,
that is, exactly the same way as with "sprintf" function of C language.
</para>
<screen>sprintf('Int=%d/%o/%x, String=%s, Character=%c',
42798,42798,42798,'la cadena',65)
-> 'Int=42798/123456/a72e, String=la cadena, Character=A'
</screen>
</formalpara>
<note>
<title>Note</title>
<para>Currently, if sprintf detects that the internal temporary buffer of
two thousand characters has overflowed it will shutdown the whole
Virtuoso. As this is a little bit too drastic it will be certainly
changed in the future releases.
</para>
<para>
The floats and doubles are not output from sprintf correctly (i.e. %f and %g).
</para>
</note>
<tip>
<title>See Also:</title>
<para>dbg_printf in <link linkend="DEBUGGINGFUNCTIONS">Debugging Functions</link></para>
</tip>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>String_output</title>
<funcsynopsis>
<funcdef>
<function>string_output</function>
</funcdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>string_output_string</function>
</funcdef>
<paramdef>
in <parameter>string_out</parameter> anything</paramdef>
</funcsynopsis>
<para>These functions provide a means for buffering output into a string output
stream. Output can be appended to the stream with the http output functions.
</para>
<para>
The output accumulated into the stream can be retrieved as one string by
the string_output_string returns the accumulated data as a single varchar. The
function http_rewrite can be used to empty the data from a string output stream.
The same string can be obtained several times with string_output_string.
</para>
<para>
If a string output stream is passed to the result function the text stored in it is
sent to the client.
</para>
<para>
The string output object cannot be copied. It cannot therefore be assigned
between two variables or passed as a value (IN) parameter. It can be passed as a
reference (OUT, INOUT) parameter.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Strchr, Strrchr</title>
<funcsynopsis>
<funcdef>
<function>strchr</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>char</parameter> string or integer</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>strrchr</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>char</parameter> string or integer</paramdef>
</funcsynopsis>
<para>
strchr returns a zero-based index to the point of string str where the
character char occurs first time. If char is not found from the string the
NULL is returned. char can be given either as an integer ASCII value or a
string, in which case the first character of that string is searched for
from str.
</para>
<para>
strrchr is otherwise similar, except that it returns an index to the last
occurrence of char.
</para>
<screen>
strchr('AbracadabrA','A')
-> 0 (Found as the first character).
strrchr('AbracadabrA',65)
-> 10 (Found as the eleventh character)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Strchr, Strcasestr</title>
<funcsynopsis>
<funcdef>
<function>strstr</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>sub</parameter> string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>strcasestr</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>sub</parameter> string</paramdef>
</funcsynopsis>
<para>
strstr returns a zero-based index to the point of string str where the
substring sub occurs first time. If sub is not found from the string the
NULL is returned.
</para>
<para>
strcasestr is otherwise similar, except that it performs the
case-insensitive substring search.
</para>
<screen>strstr('AbracadabrA','abrA')
-> 7 (Found from the eighth character onwards)
strcasestr('AbracadabrA','abrA')
-> 0 (Found from the beginning of string)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>subseq</title>
<funcsynopsis>
<funcdef>
<function>subseq</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string or object id</paramdef>
<paramdef>
<parameter>from</parameter> integer</paramdef>
<paramdef>
<optional>
<parameter>to</parameter> integer or NULL</optional>
</paramdef>
</funcsynopsis>
<para> subseq returns a copy of subsequence of string str using zero-based
indices from (inclusive) and to (exclusive) to delimit the substring
extracted.
</para>
<para>
If to is omitted or is NULL, then it equals by default to the length of
str, i.e. everything from from to the end of str is returned.
</para>
<para>
If to and from are equal, an empty string '' is returned.
</para>
<para>
If from is greater than to or length of str an error is generated.
</para>
<para>
If str itself is given as NULL then NULL is returned.
</para>
<screen>
subseq('AbracadabrA',0,4) -> 'Abra'
subseq('AbracadabrA',4,8) -> 'cada'
subseq('AbracadabrA',7) -> 'abrA'
subseq(string,0,strchr(string,'/'))
</screen>
<para>
The last one returns a copy of the string cut from the first slash,
leaving it and everything following out, and in the case where there
are no slashes present, returns a copy of the whole string.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Substring</title>
<funcsynopsis>
<funcdef>
<function>substring</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>from</parameter> integer</paramdef>
<paramdef>
<parameter>sublen</parameter> integer</paramdef>
</funcsynopsis>
<para>
substring returns a copy of subsequence of string str using one-based
index from, and substring length sublen to delimit the substring
extracted.
</para>
<para>
This function is provided for the compatibility with more standard SQL
dialects.
</para>
<screen>
substring('AbracadabrA',1,4) -> 'Abra'
substring('AbracadabrA',5,4) -> 'cada'
substring('AbracadabrA',8,4) -> 'abrA'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Left, Right</title>
<funcsynopsis>
<funcdef>
<function>left</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>count</parameter> integer</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>right</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>count</parameter> integer</paramdef>
</funcsynopsis>
<para> left returns a subsequence of string str, taking count characters from the
beginning of string.
</para>
<para>
right returns a subsequence of string str, taking count characters from the
end of string.
</para>
<para>
If count is zero an empty string '' is returned.
</para>
<para>
If length of str is less than count then a copy of the whole str is
returned.
</para>
<screen>left('AbracadabrA',4) -> 'Abra'
right('AbracadabrA',4) -> 'abrA'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>ltrim, rtrim, trim</title>
<funcsynopsis>
<funcdef>
<function>ltrim</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<optional>
<parameter>trimchars</parameter> string</optional>
</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>rtrim</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<optional>
<parameter>trimchars</parameter> string</optional>
</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>trim</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<optional>
<parameter>trimchars</parameter> string</optional>
</paramdef>
</funcsynopsis>
<para> ltrim returns a copy of subsequence of string str with all the characters
present in trimchars trimmed off from the beginning. If the second
argument is omitted, it is a space ' ' by default.
</para>
<para>
rtrim is similar except that it trims from the right.
</para>
<para>
trim trims from both ends.
</para>
<screen>concat('*',trim(' SIMURG '),'*') -> '*SIMURG*'
ltrim('AbracadabrA','bAr') -> 'acadabrA'
rtrim('AbracadabrA','bAr') -> 'Abracada'
trim('AbracadabrA','bAr') -> 'acada'
</screen>
</formalpara>
<note>
<title>Note:</title>
<para>
The trimming functions will never modify the original string given as their
argument, instead, they always return a new copy of the string.
</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Lcase, Lower</title>
<funcsynopsis>
<funcdef>
<function>lcase</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>lower</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<para>
lcase returns a copy of string str with all the uppercase alphabetical
characters converted to corresponding lowercase letters. This includes
also the diacritic letters present in the ISO 8859/1 standard in range
192 - 222 decimal, excluding the character 223, German double-s which
stays the same.
</para>
<para>
lower is just an alias for lcase.
</para>
<screen>lcase('AbracadabrA') -> 'abracadabra'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Ucase, Upper</title>
<funcsynopsis>
<funcdef>
<function>ucase</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>upper</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<para> ucase returns a copy of string str with all the lowercase alphabetical
characters converted to corresponding uppercase letters. This includes
also the diacritic letters present in the ISO 8859/1 standard in range
224 - 254 decimal, excluding the character 255, y diaeresis, which is not
converted to a German double-s.
</para>
<para>
upper is just an alias for ucase.
</para>
<screen>ucase('AbracadabrA') -> 'ABRACADABRA'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>initcap</title>
<funcsynopsis>
<funcdef>
<function>initcap</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<para> initcap returns a copy of string str with the first character, if it is a
lowercase letter, converted to the corresponding uppercase letter.
Otherwise, an identical copy of the string is returned. Notes about ucase
apply also here.
</para>
<screen>initcap('simurg!') -> 'Simurg!'
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> The case conversion functions initcap, lcase (lower) and ucase (upper)
never modify the original string given as their argument, instead, they
always return a new copy of the string.
</para>
<para>
These functions work equally well with all the standard ISO 8859/x Baltic,
Central European, Greek and Turkish characters sets, as well as with the
Cyrillic set, except in the last case the last character of the cyrillic
alphabet, 'JA', is left unconverted. Also, in the Turkish character set
the dotted and dotless letter I's and i's are not converted correctly.
</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>matches_like</title>
<funcsynopsis>
<funcdef>
<function>matches_like</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
<paramdef>
<parameter>pattern</parameter> string</paramdef>
</funcsynopsis>
<para> matches_like returns either one or zero, depending whether string str
matches with the pattern. The test performed is the same as done with the
query operand str LIKE pattern.
</para>
<screen>
matches_like('AbracadabrA','%ca[ld]a%')
-> 1 (matches)
matches_like('AbracadabrA','%%abraca')
-> 1 (matches)
</screen>
</formalpara>
<tip>
<title>See Also:</title>
<para>The <link linkend="LikePredicate">LIKE Predicate and Wild Cards</link> to learn all the intricacies of the pattern matching.</para>
</tip>
</listitem>
<listitem>
<formalpara>
<title>string_output_flush</title>
<funcsynopsis>
<funcdef>
<function>string_output_flush</function>
</funcdef>
<paramdef>
in <parameter>string_output</parameter> any</paramdef>
</funcsynopsis>
<para>
This function resets the state of the string output object.
The string associated with the string output is dropped and is of 0 characters
after this call.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>blob_to_string</title>
<funcsynopsis>
<funcdef>
<function>blob_to_string</function>
</funcdef>
<paramdef>
in <parameter>blob</parameter> any</paramdef>
</funcsynopsis>
<para>
This should be replaced by
</para>
<programlisting>
cast (xxxx as varchar).
</programlisting>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>locate</title>
<funcsynopsis>
<funcdef>integer <function>LOCATE</function>
</funcdef>
<paramdef>
in <parameter>string_exp1</parameter> varchar</paramdef>
<paramdef>
in <parameter>string_exp2</parameter> varchar</paramdef>
<paramdef>
<optional>
in <parameter>start</parameter> integer</optional>
</paramdef>
</funcsynopsis>
<para>
Returns the starting position of the first occurrence of
string_exp1 within string_exp2. The search for the first occurrence
of string_exp1 begins with the first character position in string_exp2
unless the optional argument, start, is specified.
If start is specified, the search begins with the character
position indicated by the value of start.
The first character position in string_exp2 is indicated by the value 1.
If string_exp1 is not found within string_exp2, the value 0 is returned.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>initcap</title>
<funcsynopsis>
<funcdef>string <function>initcap</function>
</funcdef>
<paramdef>
in <parameter>str</parameter> varchar</paramdef>
</funcsynopsis>
<para>
Returns its a copy of its argument with the first alphabetic character
in upper case.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara><title>regexp_match, regexp_substr, regexp_parse</title>
<funcsynopsis>
<funcdef>string <function>regexp_match</function></funcdef>
<paramdef>in <parameter>pattern</parameter> string</paramdef>
<paramdef>inout <parameter>target_string</parameter> string</paramdef>
</funcsynopsis>
<para>
The regexp_match function returns copy of substring of string target_str matches regular expression pattern.
The first symbols of target_str are cut until end of matched substring. So target_str could be passed to
this function again to find another occurrence of substring which matches the regular expression.
</para>
<funcsynopsis>
<funcdef>string <function>regexp_substr</function></funcdef>
<paramdef>in <parameter>pattern</parameter> string</paramdef>
<paramdef>in <parameter>matched_string</parameter> string</paramdef>
<paramdef>in <parameter>index</parameter> integer</paramdef>
</funcsynopsis>
<para>
The regexp_substr function returns single captured substring from matched substring. The matched substring
could be obtained from regexp_match function.
</para>
<funcsynopsis>
<funcdef>index_vector <function>regexp_parse</function></funcdef>
<paramdef>in <parameter>pattern</parameter> string</paramdef>
<paramdef>in <parameter>target_string</parameter> string</paramdef>
<paramdef>in <parameter>offset</parameter> integer</paramdef>
</funcsynopsis>
<para>
The regexp_parse function is more efficient than the other two. It applies regular expression to target_str
with offset. This function returns vector of index pairs. Two elements for matched substring and each captured
substring are set: the index of start and end of substring.
</para>
<example>
<title>Examples</title>
<programlisting>
CREATE PROCEDURE all_tokens(IN pattern VARCHAR, IN str VARCHAR)
{
DECLARE wrd VARCHAR;
DECLARE ans VARCHAR;
DECLARE str_i VARCHAR;
ans:='';
str_i := str;
wrd := regexp_match(pattern,str_i);
WHILE (wrd IS NOT NULL)
{
ans := concat(ans,',',wrd);
wrd := regexp_match(pattern,str_i);
};
RETURN ans;
};
</programlisting>
<programlisting>
CREATE PROCEDURE all_tokens2 (IN pattern VARCHAR,IN str VARCHAR, IN offs INTEGER)
{
DECLARE vec ANY;
DECLARE i INTEGER;
DECLARE out_str VARCHAR;
vec:=regexp_parse(pattern,str,offs);
IF ((vec IS NOT NULL) AND (length(vec)>1))
{
out_str:='';
i:=0;
WHILE ( (length(vec)/2) > i )
{
out_str:=concat(out_str,'/',subseq(str,aref(vec,(i)*2),aref(vec,(i)*2+1)));
i:=i+1;
};
RETURN concat(out_str,test_parsing(pattern,str,aref(vec,1)+1));
}
return NULL;
};
</programlisting>
</example>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="GENCOMPAREFUNCTIONS">
<title>Generic Comparison Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>lt, lte, ge, gte, equ, neq</title>
<funcsynopsis>
<funcdef>
<function>lt</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>lte</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>ge</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>gte</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>equ</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>neq</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> numeric or string</paramdef>
<paramdef>
<parameter>arg2</parameter> numeric or string</paramdef>
</funcsynopsis>
<para> lt returns either one or zero, depending whether its first argument is
less than its second argument. The arguments can be of types integer,
float, double precision, varchar or NULL. If they are not same of the same
type, then an appropriate type coercion is done for them before
comparison.
</para>
<para>
Similarly work the functions lte (less than or equivalent),
gt (greater than), gte (greater than or equivalent), equ (equivalent) and
neq (not equivalent). Indeed, these correspond to SQL query
operators <, <=, >, >=, = and <> and would be totally
unnecessary if the syntax allowed the latter operators to be used also on
the left side of from keyword in select statement.
</para>
<screen>
lt('pata','pato') -> 1 (Yes, 'pata' is less than 'pato')
gt('barbar','bar') -> 1 (Yes, 'barbar' is greater than 'bar')
equ(17,17) -> 1 (seventeen is seventeen)
equ(17,17.0) -> 1 (regardless of number format)
equ(atof('17.0'),17.0)) -> 1 (as it seems be)
equ(atof('17.1'),17.1)) -> 0 (But not always! Beware!)
gte(1234,NULL) -> 0 (No, 1234 is not "greater"
than or equal to NULL)
lt(1234,NULL) -> 1 (Instead, it is "less" than NULL)
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> SQL NULL is equal to another NULL, greater than everything else, and
everything else is less than NULL. Strings are compared to each other as
they were composed of unsigned bytes, that is, words beginning with
diacritic letters (in the end of ISO-8859/1 character range) "come later"
than words beginning with "normal" ascii letters.
</para>
</note>
<tip>
<title>See Also:</title>
<para>matches_like in <link linkend="StringFunctions">String Functions</link></para>
</tip>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>iszero</title>
<funcsynopsis>
<funcdef>
<function>iszero</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> iszero returns one if its argument is an integer 0, a float 0.0 or a
double 0.0 For any other arguments, of whatever type, it will return zero.
</para>
<screen>
iszero(0) -> 1 (Yes it is)
iszero(0.0) -> 1 (Double precision zero also
is a zero)
iszero(atof('0.0')) -> 1 (As well as single
precision floating point)
iszero(1) -> 0 (No, it's not)
iszero('Cifra') -> 0 (neither is this one)
iszero(NULL) -> 0 (nor this one)
</screen>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="TYPEFUNCTIONS">
<title>Type Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>Isinteger</title>
<funcsynopsis>
<funcdef>
<function>isinteger</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isinteger returns one if its argument is of type integer, zero otherwise.
</para>
<screen>
isinteger(0) -> 1 (Yes it is)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Isfloat</title>
<funcsynopsis>
<funcdef>
<function>isfloat</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isfloat returns one if its argument is of type single float, zero otherwise.
</para>
<screen>
isfloat(0.0) -> 0 (No it is not, because decimal
literals are by default
converted to double precision
numbers)
isfloat(atof('0.0')) -> 1 (Only with explicit atof we get
a single float)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>isdouble</title>
<funcsynopsis>
<funcdef>
<function>isdouble</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isdouble returns one if its argument is of type double precision float,
zero otherwise.
</para>
<screen>
isdouble(0.0) -> 1 (Decimal literals are by
default converted to
double precision numbers)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>isnumeric</title>
<funcsynopsis>
<funcdef>
<function>isnumeric</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isnumeric returns one if its argument is of type integer, single float or
double precision floating point number, zero otherwise.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>isnull</title>
<funcsynopsis>
<funcdef>
<function>isnull</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isnull returns one if its argument is NULL, zero otherwise.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>isstring</title>
<funcsynopsis>
<funcdef>
<function>isstring</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isstring returns one if its argument is of type VARCHAR, zero otherwise.
</para>
<screen>
isstring('Cadena de los patos amarillos')
-> 1 (Yes it is a string)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>isblob</title>
<funcsynopsis>
<funcdef>
<function>isblob</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> isblob returns one if its argument is a handle to an object of the type
LONG VARCHAR, zero otherwise.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>either</title>
<funcsynopsis>
<funcdef>
<function>either</function>
</funcdef>
<paramdef>
<parameter>condition</parameter> anything</paramdef>
<paramdef>
<parameter>then</parameter> anything</paramdef>
<paramdef>
<parameter>else</parameter> anything</paramdef>
</funcsynopsis>
<para> either returns either a copy of then if its first argument is anything
else than an integer zero, or a copy of else if its first argument is 0.
</para>
<screen>
either(mod(X,2),'odd','even') -> (Where X is an integer)
either(isnull(strstr('Simurg','imu')),
'there is no imu','imu is there')
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>internal_type</title>
<funcsynopsis>
<funcdef>
<function>internal_type</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> anything</paramdef>
</funcsynopsis>
<para> internal_type returns an integer value representing the internal type of
its argument. These values are the same as what Virtuoso uses in the
column COL_DTP of the system table SYS_COLS for keeping the track of the
default types of each column of each table.
</para>
<screen>
internal_type(space(5)) -> 182 (A long string)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>internal_to_sql_type</title>
<funcsynopsis>
<funcdef>
<function>internal_to_sql_type</function>
</funcdef>
<paramdef>
<parameter>internal_type</parameter> integer</paramdef>
</funcsynopsis>
<para> internal_to_sql_type returns an integer value representing the standard
SQL type converted from internal_type given as its argument.
</para>
<screen>
internal_to_sql_type(182) -> 12 (VARCHAR)
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> There is no one-to-one mapping between internal Virtuoso types and
external SQL types used by SQL/CLI and ODBC APIs. E.g. Virtuoso uses two
types of strings, short string (181) and long string (182) for storing the
character data, and these both types are always presented as VARCHAR (12)
data for the clients.</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>internal_type_name</title>
<funcsynopsis>
<funcdef>
<function>internal_type_name</function>
</funcdef>
<paramdef>
<parameter>internal_type</parameter> integer</paramdef>
</funcsynopsis>
<para> internal_type_name returns a string which is a human-readable name for an
internal_type integer given as its argument.
</para>
<screen>
internal_type_name(internal_type('kumikala'))
-> 'SHORT_STRING'
select internal_type_name(COL_DTP) from SYS_COLS;
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> Many of these names differ from the names of the corresponding SQL types,
e.g. we got BLOB instead of LONG VARCHAR, SHORT_STRING or LONG_STRING
instead of VARCHAR, etc, and not even Virtuoso will understand these
names in table definitions. That is, currently they are just for
human consumption. However, this might be changed in future releases.</para>
</note>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="ARITHMETICFUNCTIONS">
<title>Arithmetic Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>atof</title>
<funcsynopsis>
<funcdef>
<function>atof</function>
</funcdef>
<paramdef>
<parameter>arg</parameter> string</paramdef>
</funcsynopsis>
<para> atof returns a single precision floating point which it has converted from
the string given as its argument. It returns 0.0 if the string does not
contain a valid floating point number.
</para>
<screen>
atof('1.23456789') -> 1.234568
atof('Cadena de los patos amarillos')
-> 0.0 (It is a string not a float)
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>abs</title>
<funcsynopsis>
<funcdef>
<function>abs</function>
</funcdef>
<paramdef>
<parameter>num</parameter> numeric</paramdef>
</funcsynopsis>
<para> abs returns the absolute value of its numeric argument, that is, gives a
value negated to positive if the argument is negative.
</para>
<screen>
abs(-12) -> 12
abs(0) -> 0
abs(910) -> 910
abs(atof('-1.23456789')) -> 1.234568
abs(-0.1) -> 0.1
</screen>
</formalpara>
<note>
<title>Note:</title>
<para>abs(x) is equivalent to (x * sign(x)).</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>sign</title>
<funcsynopsis>
<funcdef>
<function>sign</function>
</funcdef>
<paramdef>
<parameter>num</parameter> numeric</paramdef>
</funcsynopsis>
<para> sign returns either -1, 0 or 1 depending whether its numeric argument is
negative, zero or positive.
</para>
<screen>
sign(-12) -> -1
sign(0) -> 0
sign(910) -> 1
sign(atof('-1.23456789')) -> -1
sign(0.0) -> 0
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>mod</title>
<funcsynopsis>
<funcdef>
<function>mod</function>
</funcdef>
<paramdef>
<parameter>dividend</parameter> integer</paramdef>
<paramdef>
<parameter>divisor</parameter> integer</paramdef>
</funcsynopsis>
<para> mod returns the modulus (i.e. remainder) of the division dividend/divisor.
If the divisor is zero the SQL error 22012 "Division by zero" is generated.
</para>
<screen>
mod(35,3) -> 2
mod(35,-3) -> 2
mod(-35,3) -> -2
mod(-35,-3) -> -2
mod(3,35) -> 3
mod(0,7) -> 0
mod(60,3) -> 0
</screen>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>Trigonometric & Logarithmic functions</title>
<funcsynopsis>
<funcdef>
<function>acos</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>asin</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>atan</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>cos</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>sin</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>tan</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>cot</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>degrees</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>radians</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>exp</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>log</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>log10</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>sqrt</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>atan2</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
<paramdef>
in <parameter>y</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>power</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
<paramdef>
in <parameter>y</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>ceiling</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>floor</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> double precision</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>pi</function>
</funcdef>
</funcsynopsis>
<para>
All these functions work with double precision floating point numbers.
They convert their argument to an IEEE 64-bit float and return a result of that
type, except for floor and ceiling, which return a 32-bit integer.
</para>
<programlisting>
: acos arc cosine
: asin arc sine
: atan arc tangent
: cos cosine
: sin sine
: tan tangent
: cot cotangent
: degrees convert an angle in radians to degrees.
: radians convert an angle in radians to degrees.
: exp raise e to the xth power.
: log e based logarithm
: log10 10 based logarithm
: sqrt square root
: atan2 arc tangent with x and y coordinates, can return an angle in any quadrant.
: power raise x to the yth power
: ceiling round to positive infinity
: floor round to negative infinity
: pi return pi.
</programlisting>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="OBJECTIDFUNCTIONS">
<title>Object ID Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>make_oid</title>
<funcsynopsis>
<funcdef>
<function>make_oid</function>
</funcdef>
<paramdef>
<parameter>string_part</parameter> string</paramdef>
<paramdef>
<parameter>class_specifier</parameter> integer</paramdef>
</funcsynopsis>
<para> make_oid returns an object id formed from the string string_part and the
four-byte integer class_specifier, by concatenating the latter in binary
format to the end of the former.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>oid_class_spec</title>
<funcsynopsis>
<funcdef>
<function>oid_class_spec</function>
</funcdef>
<paramdef>
<parameter>oid </parameter> object id</paramdef>
</funcsynopsis>
<para> oid_class_spec returns as an integer the four-byte integer class specifier
from the end of its object id argument.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="DATETIMEFUNCTIONS">
<title>Date and Time Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>now</title>
<funcsynopsis>
<funcdef>
<function>now</function>
</funcdef>
</funcsynopsis>
<para> now returns the timestamp associated with the current transaction in the
internal date time format. Use datestring to convert it to human-readable
string.
</para>
<screen>
datestring(now()) -> '1997.02.23 02:28.33 000000'
update TABLE_X set TIME_CHANGED = now();
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>get_timestamp</title>
<funcsynopsis>
<funcdef>
<function>get_timestamp</function>
</funcdef>
</funcsynopsis>
<para> get_timestamp is merely an alias for now and is provided for backward
compatibility.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>dateadd</title>
<funcsynopsis>
<funcdef>
<function>dateadd</function>
</funcdef>
<paramdef>
<parameter>unit</parameter> string</paramdef>
<paramdef>
<parameter>number</parameter> integer</paramdef>
<paramdef>
<parameter>date</parameter> timestamp</paramdef>
</funcsynopsis>
<para> dateadd adds a positive or negative quantity of units to a date (in the
internal date time format), and returns a new date so formed. The unit is
specified as a string and can be one of the following: 'second', 'minute',
'hour', 'day', 'month', or 'year'. Use datestring to convert the result to
a human-readable string.
</para>
<screen>
datestring(dateadd('day', 10, stringdate ('1996.10.10')))
-> '1996.10.20 0:0.0 000000'
</screen>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>datediff</title>
<funcsynopsis>
<funcdef>
<function>datediff</function>
</funcdef>
<paramdef>
<parameter>unit</parameter> string</paramdef>
<paramdef>
<parameter>date1</parameter> timestamp</paramdef>
<paramdef>
<parameter>date2</parameter> timestamp</paramdef>
</funcsynopsis>
<para> datediff subtracts date1 from date2 and returns the difference as an
integer in the specified units. The unit is specified as a string and can
be one of the following: 'second', 'minute', 'hour', 'day', 'month', or
'year'.
</para>
<screen>
datediff ('hour', stringdate ('1996.10.10'),
stringdate ('1996.10.11')) -> 24
</screen>
</formalpara>
<note>
<title>Note:</title>
<para>Beware of the daylight saving time.</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>Datestring</title>
<funcsynopsis>
<funcdef>
<function>datestring</function>
</funcdef>
<paramdef>
<parameter>date</parameter> timestamp</paramdef>
</funcsynopsis>
<para> datestring converts timestamps from the internal to external date- time
representations. The internal representation is an 8 byte binary string
(of the special type TIMESTAMP_OBJ, documented elsewhere) and the external
representation is a human-readable ASCII string of up to 30 characters.
</para>
<para>
The external format is: YYYY.MM.DD hh:mm.ss uuuuuu where uuuuuu
represents the number of microseconds.
</para>
<screen>
datestring(now()) -> '1997.02.23 02:28.33 000000'
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> If you are using select in isql and if you do not explicitly convert dates
and timestamps to strings with datestring they may be converted to strings
by the ODBC driver/SQL CLI interface, in which case the format is a little
bit different. This will be harmonized in the future releases.
</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>stringdate</title>
<funcsynopsis>
<funcdef>
<function>stringdate</function>
</funcdef>
<paramdef>
<parameter>str</parameter> string</paramdef>
</funcsynopsis>
<para> stringdate converts dates and timestamps from the external to internal
date-time representations.
</para>
<para>
The external format is: YYYY.MM.DD hh:mm.ss uuuuuu
where uuuuuu represents the number of microseconds.
</para>
<para>
If trailing parts are omitted from the string given to stringdate,
they are assumed to be zero. The three first parts are mandatory.
</para>
<screen>
update XX set DATE_COL = stringdate ('1996.10.20 14:55.00');
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> The internal time is the GMT system time. The local system timezone is
taken into account when converting dates to strings and vice versa.
</para>
</note>
</listitem>
<listitem>
<formalpara>
<title>curdate, curtime, curdatetime</title>
<funcsynopsis>
<funcdef>date <function>curdate</function>
</funcdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>time <function>curtime</function>
</funcdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>datetime <function>curdatetime</function>
</funcdef>
</funcsynopsis>
<para>
These functions return the current as date or time as a date, time or datetime, respectively.
Internally these all return the same value but the data type reported to the
client differs.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>stringtime</title>
<funcsynopsis>
<funcdef>time <function>stringtime</function>
</funcdef>
<paramdef>
in <parameter>str</parameter> varchar</paramdef>
</funcsynopsis>
<para>
Converts the argument to a time. Same as
</para>
<programlisting>
cast (x as time)
</programlisting>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>datestring_GMT</title>
<funcsynopsis>
<funcdef>ODBC datetime <function>datestring_GMT</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<para>
Converts the local datetime to GMT and returns that in the standard
ODBC datetime syntax.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>datetime decomposition functions</title>
<funcsynopsis>
<funcdef>
<function>dayname</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>monthname</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>dayofmonth</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>dayofweek</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>dayofyear</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>quarter</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>week</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>month</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>year</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>hour</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>minute</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>second</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>timezone</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
</funcsynopsis>
<para>
These functions decompose a datetime to its components. These can be used on
timestamps, datetimes, dates and times, these all being the same internal data type.
</para>
<programlisting>
: dayname name of day
: monthname name of month
: dayofmonth day of month
: dayofweek day of week
: dayofyear day since start of year
: quarter quarter number,
: week week number
: month month number, starting at 1 for January
: year year
: hour hour
: minute minute
: second second
: timezone offset from UTC in minutes
</programlisting>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>dt_set_tz</title>
<funcsynopsis>
<funcdef>
<function>dt_set_tz</function>
</funcdef>
<paramdef>
in <parameter>dt</parameter> datetime</paramdef>
<paramdef>
in <parameter>tz</parameter> integer</paramdef>
</funcsynopsis>
<para>
This modifies the timezone component of a datetime. The value remains equal
for purposes of comparison but will look different when converted to
a string. The timezone component is an offset from UTC in minutes.
It can be retrieved with the timezone function.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="VECARRAYFUNCTIONS">
<title>Array & Vector Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>vector</title>
<funcsynopsis>
<funcdef>
<function>vector</function>
</funcdef>
<paramdef>
<parameter>elem1</parameter> anything</paramdef>
<paramdef>
<parameter>elem2</parameter> anything</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
<paramdef>
<parameter>elem-n</parameter> anything</paramdef>
</funcsynopsis>
<para> vector returns a new vector (one-dimensional array) constructed of the
variable number of arguments given.
</para>
<screen>dbg_obj_print(vector (1, 2.34, 'A string', atof('3.14')))
length(vector ('Abracadabra', NULL, now())) -> 3
</screen>
</formalpara>
<note>
<title>Note:</title>
<para> Currently you cannot directly use in the client the value returned by
vector. If you type e.g. select vector(col1,col2,col3) from test; in isql
you will get unpredictable or spurious results. However, this will
change in the future releases when we will publish more sophisticated
client interfaces than just standard SQL CLI/ODBC libraries.
</para>
</note>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>make_array</title>
<funcsynopsis>
<funcdef>array <function>make_array</function>
</funcdef>
<paramdef>
in <parameter>length</parameter> integer </paramdef>
<paramdef>
in <parameter>content</parameter> varchar </paramdef>
</funcsynopsis>
<para>
This returns an array of length elements with the content element
type. The content is a string with the possible values:
</para>
<para>'long', 'float', 'double' or 'any'.</para>
<para>
These correspond respectively to the C types long (32 bit signed),
float (IEEE 32-bit), double (IEEE 64-bit) and untyped. The untyped array may
hold a heterogeneous collection of any Virtuoso data types, including other arrays.
The initial content of the array is undefined.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>lvector, fvector, dvector</title>
<funcsynopsis>
<funcdef>array <function>lvector</function>
</funcdef>
<paramdef>
<parameter>elt1</parameter>
</paramdef>
<paramdef>
<parameter>....</parameter>
</paramdef>
<paramdef>
<parameter>elt-n</parameter>
</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>array <function>fvector</function>
</funcdef>
<paramdef>
<parameter>elt1</parameter>
</paramdef>
<paramdef>
<parameter>....</parameter>
</paramdef>
<paramdef>
<parameter>elt-n</parameter>
</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>array <function>dvector</function>
</funcdef>
<paramdef>
<parameter>elt1</parameter>
</paramdef>
<paramdef>
<parameter>....</parameter>
</paramdef>
<paramdef>
<parameter>elt-n</parameter>
</paramdef>
</funcsynopsis>
<para>
These functions are like vector but return an array of either long, float or double whereas
vector returns a generic, untyped array.
</para>
<example>
<title>Examples:</title>
<programlisting>
aref (lvector (1, 2), 1) = 1 is true.
</programlisting>
</example>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>get_keyword</title>
<funcsynopsis>
<funcdef>
<function>get_keyword</function>
</funcdef>
<paramdef>
<parameter>item</parameter> anything</paramdef>
<paramdef>
<parameter>vector</parameter> vector</paramdef>
<paramdef>
<parameter>default</parameter> anything</paramdef>
</funcsynopsis>
<para> get_keyword seeks item from each even position of vector, and if it finds
it from there then returns the corresponding value from the right of the
said item (from odd position). Otherwise, if item is not found returns
default.
</para>
<screen>get_keyword(2,vector(1,'primero',2,'segundo',
3,'tercero'),NULL) -> segundo
get_keyword('tercero',vector('primero',1,'segundo',
2,'tercero',3), 'NOT FOUND!')) -> 3
</screen>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="DEBUGGINGFUNCTIONS">
<title>Debugging Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>dbg_obj_print</title>
<funcsynopsis>
<funcdef>
<function>dbg_obj_print</function>
</funcdef>
<paramdef>
<parameter>arg1</parameter> anything</paramdef>
<paramdef>
<parameter>arg2</parameter> anything</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
<paramdef>
<parameter>argn</parameter> anything</paramdef>
</funcsynopsis>
<para> dbg_obj_print prints a variable number of arguments to the system console
of Virtuoso server, each argument in its own native format, on the same
line, which is followed by one newline.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>dbg_printf</title>
<funcsynopsis>
<funcdef>
<function>dbg_printf</function>
</funcdef>
<paramdef>
<parameter>format</parameter> string</paramdef>
<paramdef>
<parameter>arg1</parameter> anything</paramdef>
<paramdef>
<parameter>...</parameter>
</paramdef>
<paramdef>
<parameter>arg8</parameter> anything</paramdef>
</funcsynopsis>
<para> dbg_printf prints a variable number (max. eight) of arguments to the
system console of Virtuoso server, each argument formatted in C "printf"
style, according to the format string specified in the first argument.
</para>
<tip>
<title>See Also:</title>
<para>sprintf in <link linkend="StringFunctions">String Functions</link></para>
</tip>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>isarray, isentity</title>
<funcsynopsis>
<funcdef>boolean <function>isarray</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> any</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>boolean <function>isentity</function>
</funcdef>
<paramdef>
in <parameter>x</parameter> any</paramdef>
</funcsynopsis>
<para>
isarray is true if the argument is a valid argument to aref.
This is the case for any string or vector.
</para>
<para>
isentity is true if the argument is an XML entity object. Such are returned from
XPATH expressions etc.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="BACKUPFUNC">
<title>Back Up Functions</title>
<para>
These functions allow making a full or selective backup of a database
without obstructing on-line operations or causing locks.
The database state seen in the backup is the database state after the last
transaction to commit before the last checkpoint. The first transaction not
seen in the backup is the first transaction in the current transaction log.
</para>
<para>
These functions produce a file in the transaction log format. A backup can be restored by
replaying a backup file as a transaction log.
</para>
<para>
A database can be fully restored up to the last committed transaction by
taking the file produced by the backup function and any transaction logs
created since the backup was taken, including the one current at the time of the backup.
</para>
<para>
If the database file or files are lost, the database server can be started with no
database files. This will create the file or files specified in the configuration. To restore the
backup, one can log into the fresh database and use the replay function to first replay the backup and
then successive transaction logs in the order of creation.
</para>
<para>
If no backup has been made but the complete history of transaction logs exists, the
logs can be replayed for recreating the database.
</para>
<note>
<title>Note:</title>
<para>Files generated by the +crashdump command line switch are in a format similar to those created by
the backup functions or the backup command and thus all points mentioned here apply to these as well.</para>
<para>Only the first crash dump file contains the schema, hence it must be the first to be replayed.</para>
</note>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>backup, backup_prepare, backup_row, backup_flush, backup_close</title>
<funcsynopsis>
<funcdef>
<function>backup</function>
</funcdef>
<paramdef>in <parameter>file</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>backup_prepare</function>
</funcdef>
<paramdef>in <parameter>file</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>backup_row</function>
</funcdef>
<paramdef>in <parameter>row</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>backup_flush</function>
</funcdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>backup_close</function>
</funcdef>
</funcsynopsis>
<para>
All backup files, whether complete (created with backup) or partial (created with backup_prepare and backup_row
of selected rows), begin with the complete schema that was effective at the time of the backup.
</para>
<para>
Backup and log files contain assumptions about the schema and row layout of the database. Hence
it is not possible to use these for transferring data between databases. Attempt to do so
will result in unpredictable results. Thus a log or backup may only be replayed on
the same database, an empty database or a copy of the database which has had no schema changed since
it was made.
</para>
<para>
The backup function takes a file name as argument. The file in in the log format and will
recreate the database as it was at the time of the last checkpoint when replayed on an empty
database. Such a file cannot be replayed on anything except an empty database. Logs made after
the backup can be replayed over the database resulting from the backup file's replay. No schema operations are
allowed between replays.
</para>
<para>
The backup_prepare, backup_row and backup_close operations allow making
specific partial backups.
</para>
<para>
backup_prepare initiates the backup. This must be the first statement to execute in its transaction. The
rest of the transaction will be a read only snapshot view of the state as of the last checkpoint.
Checkpoints are disabled for the time between backup_prepare and backup_close. The backup transaction being
lock-free, it cannot die of deadlock and hence will stay open for the duration of the backup.
</para>
<para>
The backup_close function terminates the backup and closes the file. The transaction remains
a read only snapshot of the last checkpoint but checkpoints are now re-enabled. The transaction should
be committed or rolled back after backup_close.
</para>
<para>
backup_row writes the row given as parameter into the backup file that was associated to
the current transaction by a prior backup_prepare. The row can be anything obtained
by selecting the pseudo column _ROW from any table.
</para>
<para>
The backup_flush function will insert a transaction boundary into the backup log. All rows
backup up between two backup_flush calls will be replayed as a single transaction by replay. Having
long intervals between backup_flush calls will cause significant memory consumption at replay time for
undo logs.
</para>
<para>
backup_close will terminate the backup transaction and re-enable checkpoints.
</para>
</formalpara>
<note>
<title>Note:</title>
<para>Any client-server SQL operation following a backup prepare in the same transaction will see the
last checkpoint state and will be lock free but will not be allowed to updated the database.</para>
</note>
</listitem>
<listitem>
<formalpara>
<title>replay</title>
<funcsynopsis>
<funcdef>
<function>replay</function>
</funcdef>
<paramdef>
in <parameter>log_file</parameter> varchar</paramdef>
</funcsynopsis>
<para>
This starts a roll forward of the given log. The log may have been
produced by normal transaction logging, backup or crash dump. Logs
may not be transferred between databases and thus cannot be rolled forward
anywhere except on the database that generated them.
</para>
<para>
This function is for example useful after restoring a backup. It should be called
for each archived transaction log produced since the backup, including and
starting with the one that was current when the backup was made.
</para>
<para>
The operation blocks until the roll forward is complete. Other clients
are not affected.
</para>
<example>
<title>Example:</title>
<programlisting>
create procedure t1_back (in f varchar)
{
declare c integer;
backup_prepare (f);
select count (*) into c from T1 where backup_row (_ROW) = 0;
backup_flush ();
backup_close ();
return c;
}
This procedure writes the contents of the T1
table into a backup log.
</programlisting>
</example>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>checkpoint_interval</title>
<funcsynopsis>
<funcdef>
<function>checkpoint_interval</function>
</funcdef>
<paramdef>
in <parameter>minutes</parameter> integer</paramdef>
</funcsynopsis>
<para>
This sets the automatic checkpoint interval setting in the virtuoso.ini file.
The setting is effective immediately.
</para>
<para>
This is intended for use when making a backup of a database. Setting the
checkpoint interval to -1 will persistently disable checkpoints.
This setting will persist and also block any automatic checkpoints if the server
should crash, restart, roll forward or do any other such operations
during the period the value is -1. Normal operation resumes after the interval is
reset to a positive value. A value of 0 means that checkpoints are not
made but an automatic checkpoint after restart may still occur with the 0 setting.
Hence -1 should be used when doing backups.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="TRANSLOGFUNC">
<title>Transaction & Log Control Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>log_enable, log_text</title>
<funcsynopsis>
<funcdef>
<function>log_enable</function>
</funcdef>
<paramdef>
in <parameter>flag</parameter> integer</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>log_text</function>
</funcdef>
<paramdef>
in <parameter>text</parameter> varchar</paramdef>
<paramdef>
<optional>
<parameter>arg_1</parameter>
</optional>
</paramdef>
<paramdef>
<optional>
<parameter>...</parameter>
</optional>
</paramdef>
</funcsynopsis>
<para>
The log_enable function allows turning regular transaction logging off or on.
A value of 0 terminates logging of DML statements inside the calling
transaction. A value of 1 resumes logging of DML statements. Using
this function can create situations where a transaction's outcome
would be different from the outcome of doing a roll forward of the transaction log.
There are rare cases where it is more efficient to log an action in the form
of a procedure call instead of logging the effects of the procedure on
a row by row bases. This is similar in concept to replicating
procedure calls but applies to roll forward instead.
</para>
<para>
The log_text function can be used to insert a SQL statement into the
roll forward log.
The effects of log_enable are reset at the next commit or rollback.
</para>
<para>
The log_text function causes the SQL text given as first argument to
be executed at roll forward time with the following arguments as parameters,
bound from left to right to the parameter markers in the statement ('?').
There can be a maximum of 8 parameters but these can be arrays.
</para>
<para>
To log a procedure call instead of its effects one can write:
</para>
<programlisting>
create procedure xx ()
{
log_text ('xx (?)', arg);
log_enable (0);
... action code
log_enable (1);
}
</programlisting>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>txn_error</title>
<funcsynopsis>
<funcdef>
<function>txn_error</function>
</funcdef>
<paramdef>
in <parameter>code</parameter> integer</paramdef>
</funcsynopsis>
<para>
Calling this function will poison the current transaction. This means that
it is forced to roll back at when committed. The code can be
in integer that selects the error message generated when trying to commit.
This is useful before signalling application errors from SQL code that runs
in manual commit mode. This can ensure that even if the client attempts
a commit after getting the error signalled by the application the transaction
will not commit.
</para>
<para>
The code should be the constant 6, resulting the in the 'transaction
rolled back due to previous SQL Error'.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>txn_killall</title>
<funcsynopsis>
<funcdef>
<function>txn_killall</function>
</funcdef>
<paramdef>
in <parameter>code</parameter> integer</paramdef>
</funcsynopsis>
<para>
This function will terminate all pending transactions. This can be used
for resetting infinite loops in stored procedures etc.
</para>
<para>
The code determines the error reported to the client. Number 6 is preferable,
corresponding to the 'transaction rolled back due to previous SQL error'.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>txn_killall function</title>
<funcsynopsis>
<funcdef>
<function>txn_killall</function>
</funcdef>
<paramdef>
in <parameter>code</parameter> integer</paramdef>
</funcsynopsis>
<para>
Thus function kills all pending transactions. This is useful for resetting
stuck states such as procedures in infinite loops.
</para>
<para>
Once any SQL statement or procedure notices that its transaction is dead,
e.g. deadlocked, it signals the error and takes appropriate action, which is typically
to signal the error to the caller and ultimately to the client.
</para>
<example>
<title>Examples:</title>
<programlisting>
txn_killall (1);
</programlisting>
</example>
<para>
-- kills all transactions with the S1T00 'timed out' error.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="DIGESTS">
<title>Digest Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>md5, tree_md5</title>
<funcsynopsis>
<funcdef>checksum <function>md5</function>
</funcdef>
<paramdef>
in <parameter>str</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>checksum <function>tree_md5</function>
</funcdef>
<paramdef>in <parameter>tree</parameter> any</paramdef>
</funcsynopsis>
<para>
These functions calculate the MD5 checksum of their argument. The tree_md5 will
accept any heterogeneous array and will serialize it in a proprietary
manner and return the checksum of that. This is mainly useful for comparing
trees of arrays. MD5 requires the argument to be a string.
</para>
<para>
Both functions return a string of 32 lower case hex digits.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>serialize, deserialize</title>
<funcsynopsis>
<funcdef>binary string <function>serialize</function>
</funcdef>
<paramdef>
in <parameter>tree</parameter> any</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>binary string <function>deserialize</function>
</funcdef>
<paramdef>
in <parameter>str</parameter> varchar</paramdef>
</funcsynopsis>
<para>
These functions will convert any heterogeneous
array or tree of arrays into a binary string and back. The format
is platform independent.
</para>
<programlisting>
deserialize (serialize (x))
</programlisting>
<para>
is the identity function.
</para>
<para>
These functions are useful for persisting heterogeneous arrays.
</para>
<note>
<title>Note:</title>
<para>The serialization can be stored as a blob, so that there is no practical
length limit. The string length is however limited to 16 MB.
</para>
</note>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>split_and_decode</title>
<funcsynopsis>
<funcdef>vector or string <function>split_and_decode</function>
</funcdef>
<paramdef>
in <parameter>coded_str</parameter> varchar</paramdef>
<paramdef>
<optional>
in <parameter>case_mode</parameter> integer</optional>
</paramdef>
<paramdef>
<optional>
in <parameter>str</parameter> varchar</optional>
</paramdef>
</funcsynopsis>
<para>
split_and_decode converts the escaped var=val pair inputs text to a
corresponding vector of string elements. If the optional third
argument is a string of less than three characters, then does only
the decoding (but no splitting) and returns back a string.
</para>
<para>
The optional second argument, if present should be an integer
either 0, 1 or 2, which tells whether "variable name"-parts
(those at the left side of the fourth character given in
third argument (or = if using the default URL-decoding))
are converted to UPPERCASE (1), lowercase (2) or left intact
(0 or when the second argument is not given).
</para>
<note>
<title>Note:</title>
<para>This avoids all hard-coded limits for the length
of elements, by scanning the inputs string three times.
First for the total number of elements (the length of vector
to allocate), then calculating the length of each string element
to be allocated, and finally transferring the characters of elements
to the allocated string elements.
</para>
</note>
<example>
<title>Example:</title>
<programlisting>
split_and_decode("Tulipas=Taloon+kumi=kala&Joka=haisi
+pahalle&kuin&%E4lymystporkkana=ilman ruuvausta",1)
produces a vector:
("TULIPAS" "Taloon kumi=kala" "JOKA" "haisi pahalle" "KUIN" NULL
"LYMYSTPORKKANA" "ilman ruuvausta")
</programlisting>
</example>
<programlisting>
split_and_decode(NULL) => NULL
split_and_decode("") => NULL
split_and_decode("A") => ("A" NULL)
split_and_decode("A=B") => ("A" "B")
split_and_decode("A&B") => ("A" NULL "B" NULL)
split_and_decode("=") => ("" "")
split_and_decode("&") => ("" NULL "" NULL)
split_and_decode("&=") => ("" NULL "" "")
split_and_decode("&=&") => ("" NULL "" "" "" NULL)
split_and_decode("%") => ("%" NULL)
split_and_decode("%%") => ("%" NULL)
split_and_decode("%41") => ("A" NULL)
split_and_decode("%4") => ("%4" NULL)
split_and_decode("%?41") => ("%?41" NULL)
</programlisting>
<para>
Can also work like Perl's split function (we define the escape prefix
and space escape character as NUL-characters, so that they will not be
encountered at all:
</para>
<programlisting>
split_and_decode('Un,dos,tres',0,'\0\0,') => ("Un" "dos" "tres")
split_and_decode("Un,dos,tres",1,'\0\0,') => ("UN" "DOS" "TRES")
split_and_decode("Un,dos,tres",2,'\0\0,') => ("un" "dos" "tres")
</programlisting>
<para>
Can also be used as replace and ucase (or lcase) together,
for example, here we use the comma as space-escape instead of
element-separator: (not recommended, use replace and ucase instead.
</para>
<programlisting>
split_and_decode("Un,dos,tres",0,'\0,') => "Un dos tres"
split_and_decode("Un,dos,tres",1,'\0,') => "UN DOS TRES"
</programlisting>
<para>
Can be also used for decoding (some of) MIME-encoded mail-headers:
</para>
<programlisting>
split_and_decode('=?ISO-8859-1?Q?Tiira_lent=E4=E4_taas?=',0,'=_')
=> "=?ISO-8859-1?Q?Tiira lent taas?="
split_and_decode('Message-Id: <199511141036.LAA06462@correo.unet.ar>\n
From: "=?ISO-8859-1?Q?Jorge_Mo=F1as?=" <jorgem@unet.ar>\n
To: "Jore Carvajal" <carvajal@wanabee.fr>\nSubject: RE: Um-pah-pah\n
Date: Wed, 12 Nov 1997 11:28:51 +0100\n
X-MSMail-Priority: Normal\nX-Priority: 3\n
X-Mailer: Molosoft Internet Mail 4.70.1161\nMIME-Version: 1.0\n
Content-Type: text/plain; charset=ISO-8859-1\n
Content-Transfer-Encoding: 8bit\nX-Mozilla-Status: 0011',
1,'=_\n:');
=> ('MESSAGE-ID' ' <199511141036.LAA06462@correo.unet.ar>'
'FROM' ' "=?ISO-8859-1?Q?Jorge Moas?=" <jorgem@unet.ar>'
'TO' ' "Jore Carvajal" <carvajal@wanabee.fr>'
'SUBJECT' ' RE: Um-pah-pah'
'DATE' ' Wed, 12 Nov 1997 11:28:51 +0100'
'X-MSMAIL-PRIORITY' ' Normal'
'X-PRIORITY' ' 3'
'X-MAILER' ' Molosoft Internet Mail 4.70.1161'
'MIME-VERSION' ' 1.0'
'CONTENT-TYPE' ' text/plain; charset=ISO-8859-1'
'CONTENT-TRANSFER-ENCODING' ' 8bit'
'X-MOZILLA-STATUS' ' 0011')
</programlisting>
<para>
Same, but let's use space, not colon as a variable=value separator:
</para>
<programlisting>
split_and_decode('Message-Id: <199511141036.LAA06462@correo.unet.ar>\n
From: "=?ISO-8859-1?Q?Jorge_Mo=F1as?=" <jorgem@unet.ar>\n
To: "Jore Carvajal" <carvajal@wanabee.fr>\nSubject: RE: Um-pah-pah\n
Date: Wed, 12 Nov 1997 11:28:51 +0100\n
X-MSMail-Priority: Normal\nX-Priority: 3\n
X-Mailer: Molosoft Internet Mail 4.70.1161\nMIME-Version: 1.0\n
Content-Type: text/plain; charset=ISO-8859-1\n
Content-Transfer-Encoding: 8bit\nX-Mozilla-Status: 0011',
1,'=_\n ')
=> ('MESSAGE-ID:' '<199511141036.LAA06462@correo.unet.ar>'
'FROM:' '"=?ISO-8859-1?Q?Jorge Moas?=" <jorgem@unet.ar>'
'TO:' '"Jore Carvajal" <carvajal@wanabee.fr>'
'SUBJECT:' 'RE: Um-pah-pah'
'DATE:' 'Wed, 12 Nov 1997 11:28:51 +0100'
'X-MSMAIL-PRIORITY:' 'Normal'
'X-PRIORITY:' '3'
'X-MAILER:' 'Molosoft Internet Mail 4.70.1161'
'MIME-VERSION:' '1.0'
'CONTENT-TYPE:' 'text/plain; charset=ISO-8859-1'
'CONTENT-TRANSFER-ENCODING:' '8bit'
'X-MOZILLA-STATUS:' '0011')
</programlisting>
<para>
Of course this approach does not work with multiline headers, except
somewhat kludgously.
If the lines are separated by CR+LF, there is left one trailing
CR at the end of each value part string.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="xmlvsp">
<title>XML, HTTP & VSP Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>xml_tree</title>
<funcsynopsis>
<funcdef>
<function>xml_tree</function>
</funcdef>
<paramdef>in <parameter>document</parameter> varchar</paramdef>
<paramdef><optional>in <parameter>parser_mode</parameter> integer</optional></paramdef>
<paramdef><optional>in <parameter>base_uri</parameter> varchar</optional></paramdef>
<paramdef><optional>in <parameter>content_encoding</parameter> varchar</optional></paramdef>
</funcsynopsis>
<para>
This parses the argument, which is expected to be a well formed XML
fragment and returns a parse tree as a structure of nested heterogeneous vectors.
</para>
<para>Parameters:</para>
<simplelist>
<member>document (mandatory) - well formed XML or HTML document </member>
<member>parser_mode (optional) - 0 or 1; 0 - XML parser mode 1 - HTML parser mode</member>
<member>base_uri (optional) - in HTML parser mode change all absolute references to relative from given base_uri (http://<host>:<port>/<path>)</member>
<member>content_encoding (optional) - string with content encoding type of <document> valid is 'ASCII', 'ISO', 'UTF8', 'ISO8859-1', 'LATIN-1'.</member>
</simplelist>
<example>
<title>Examples:</title>
<programlisting>
declare tree any;
tree := xml_tree (file_to_string ('doc.html'), 1,
'http://localhost.localdomain/', 'ISO');
...
tree := xml_tree (file_to_string ('doc.xml'));
</programlisting>
</example>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>xml_tree_doc</title>
<funcsynopsis>
<funcdef>
<function>xml_tree_doc</function>
</funcdef>
<paramdef>in <parameter>tree</parameter> any</paramdef>
</funcsynopsis>
<para>
This returns an entity object given a tree of the form returned by xml_tree.
</para>
<para>
If it is given a string as an argument, it will automatically generate
the parse tree and use it to make the entity instead requiring you to run the string through
xml_tree first.
</para>
<para>
Any other type of argument is illegal.
</para>
</formalpara>
</listitem>
<!-- #~#~# -->
<listitem>
<formalpara>
<title>http_request_status</title>
<funcsynopsis>
<funcdef>
<function>http_request_status</function>
</funcdef>
<paramdef>
in <parameter>status_line</parameter> varchar</paramdef>
</funcsynopsis>
<para>
This allows a VSP page to control the status sent to the client in the HTTP response.
The argument will be presented as the first line of the reply instead of the default
"HTTP/1.1 200 OK". The string should not contain a CR or LF at the end.
</para>
<para>
This allows a page to issue redirects, authentication challenges etc.
</para>
<para>
Use this with http_headers to control the content of the HTTP reply headers.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara><title>http_header</title>
<funcsynopsis>
<funcdef><function>http_header</function></funcdef>
<paramdef>in <parameter>head</parameter> varchar</paramdef>
</funcsynopsis>
<para>
Adds the string specified to the request response headers to be sent
when the processing of the current calling request terminates.
The string should end with a cr/lf and if it consists of multiple
lines these should be delimited by cr/lf's.
A Content-Type or Media-Type header specified as a part of the headers given with
this function will override the default.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara><title>http_header_get</title>
<funcsynopsis>
<funcdef><function>http_header_get</function></funcdef>
</funcsynopsis>
<para>
Returns a header associated with the current http request. The header
must previously have been stored with http_header.
</para>
<para>
This is useful for incrementally modifying response headers during processing
of a URL.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara><title>http_file</title>
<funcsynopsis>
<funcdef>varchar <function>http_file</function></funcdef>
<paramdef>in <parameter>path</parameter> varchar</paramdef>
</funcsynopsis>
<para>
This function causes the contents of the file specified by
path to be sent as the response of the calling request.
The file is not sent until the code calling this returns.
Content types etc. are defaulted based on the file's extension.
If this function is called, other output to the HTTP client
by the caller is discarded.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara><title>xml_uri_get & xml_uri_merge</title>
<funcsynopsis>
<funcdef>varchar <function>DB.DBA.xml_uri_get</function></funcdef>
<paramdef>in <parameter>base</parameter> varchar</paramdef>
<paramdef>in <parameter>ref</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>varchar <function>DB.DBA.xml_uri_merge</function></funcdef>
<paramdef>in <parameter>base</parameter> varchar</paramdef>
<paramdef>in <parameter>ref</parameter> varchar</paramdef>
</funcsynopsis>
<para>
These functions combine a base URI and a relative URI and return the combined URI (xml_uri_merge( or
the referenced resource (xml_uri_get).
</para>
<para>
The supported protocol identifiers are http: file: and virt:. The virt: allows
referencing data stored in local Virtuoso tables without passing through HTTP. See
'Entity References in Stored XML' for details.
</para>
<para>
The effective URI will be the reference if the URI of the reference is absolute. Otherwise it will
be the base URI modified by the relative reference.
</para>
<para>
Authorization is derived from the SQL or DAV identification of the caller. The DAV
identification is used if processing DAV content in response to a DAV request. The SQL user
account is used otherwise.
</para>
<para>
xml_uri_get returns the text of the requested resource. If specific encodings
or special authentication schemes are desired one may use
http_get directly.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="statsfunc">
<title>Statistics and Status Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>username</title>
<funcsynopsis>
<funcdef>string <function>username</function>
</funcdef>
</funcsynopsis>
<para>
Returns the login name of the user of the connection.
</para>
<programlisting>
select username ();
</programlisting>
<para>
is the same as
</para>
<programlisting>
select user;
</programlisting>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>dbname</title>
<funcsynopsis>
<funcdef>string <function>dbname</function>
</funcdef>
</funcsynopsis>
<para>
Returns the current qualifier. This can be altered with the USE
statement.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
<!-- ======================================== -->
<sect1 id="OSI">
<title>File System & Operating System Functions</title>
<itemizedlist mark="bullet">
<listitem><formalpara><title>system</title>
<funcsynopsis>
<funcdef><function>system</function></funcdef>
<paramdef>in <parameter>command</parameter> varchar</paramdef>
</funcsynopsis>
<para>
The system function will run a shell command from SQL. The shell command is executed
in the server's current directory as the user that owns the database server process.
</para>
<para>
This function is available to dba users only. Since this is a security
risk this feature is normally disabled. It can be enabled by setting the
AllowOSCalls setting in virtuoso.ini to 1.
</para>
</formalpara>
</listitem>
<listitem><formalpara><title>file_to_string</title>
<funcsynopsis>
<funcdef>varchar <function>file_to_string</function></funcdef>
<paramdef>in <parameter>path</parameter> varchar</paramdef>
</funcsynopsis>
<para>
file_to_string returns the contents of a file as a varchar value. The file's length is
limited to 16 MB. The path is relative to the working directory of the database server.
</para>
</formalpara>
</listitem>
<listitem><formalpara><title>string_to_file</title>
<funcsynopsis>
<funcdef><function>string_to_file</function></funcdef>
<paramdef>in <parameter>path</parameter> varchar</paramdef>
<paramdef>in <parameter>string</parameter> varchar</paramdef>
<paramdef>in <parameter>mode</parameter> integer</paramdef>
</funcsynopsis>
<para>
string_to_file writes a varchar value to a file. The path is relative to the server's
working directory. The mode is an integer value interpreted as a position. A mode of
0 writes the content starting at offset 0. A mode of -1 appends to the end of the file.
The append option is probably the most useful since it allows maintaining
an application level log of events detected in PL.
</para>
<para>
The string argument can also be a string output object. In this case the
content is used as the string.
</para>
<para>
If the mode is -2, the new content supersedes the old. This is different from 0
in that the file will be truncated if the new content is shorter than
the old.
</para>
</formalpara>
</listitem>
<listitem><formalpara><title>file_to_string_output</title>
<funcsynopsis>
<funcdef><function>file_to_string_output</function></funcdef>
<paramdef>in <parameter>file</parameter> varchar</paramdef>
</funcsynopsis>
<para>
This returns a string output initialized to contain the text of
the file, a local file system path relative to the
server's working directory.
</para>
<para>
This can handle longer files than file_to_string and the resulting
string output, while too long to be converted into a varchar , can be
stored inside a blob.
</para>
</formalpara>
</listitem>
</itemizedlist>
<sect2 id="FsPrivsACL">
<title>Virtuoso ACL's</title>
<para>
Access Control Lists (ACL) are used to restrict file system access.
</para>
<para>
These lists are maintained in the Virtuoso INI file under the Parameters section with entries such as:
</para>
<programlisting>
DirsAllowed = <path> [, <path>]
DirsDenied = <path> [, <path>]
<path> := <absolute_path> or <relative_path>
</programlisting>
<note><title>Note:</title>
<para>A relative path is counted from servers current working directory.</para></note>
<tip><title>See Also:</title>
<para><link linkend="VIRTINI">Virtuoso INI File Configuration</link></para></tip>
<para>
ACL's work in the following way:
</para>
<simplelist>
<member>All paths are converted from relative to absolute paths.</member>
<member>The path beginning with <http_root> is always allowed.</member>
<member>All DB files are always access denied (.db, db segments, .trx, log segments, .ini specified in INI file etc.)</member>
<member>If a path is not allowed or exists as denied then access to the file is rejected. </member>
<member>If a requested path is allowed and not in denied then access is allowed.</member>
<member>ACL's are inherited. If a directory allows access so does its subdirectories.</member>
</simplelist>
<para>
The following functions are restricted by file Access Control Lists (ACL) in the virtuoso.ini file:
</para>
<simplelist>
<member>file_to_string</member>
<member>file_to_string_output</member>
<member>sys_mkdir</member>
<member>sys_mkpath</member>
<member>sys_dirlist</member>
<member>string_to_file</member>
<member>cfg_write</member>
</simplelist>
<note><title>Note:</title>
<para>the cfg_write function have restrictions against changing file access control lists in ini file</para>
</note>
</sect2>
</sect1>
<!-- ======================================== -->
<sect1 id="MISCFUNC">
<title>Miscellaneous Functions</title>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>disconnect_user</title>
<funcsynopsis>
<funcdef>
<function>disconnect_user</function>
</funcdef>
<paramdef>
<parameter>username_pattern</parameter>string</paramdef>
</funcsynopsis>
<para> disconnect_user disconnects the connections of all those clients whose
username matches to the username_pattern string given as an argument, and
returns an integer value giving the number of clients disconnected.
This can be used after DELETE USER or REVOKE statement to make sure that
the affected user has no open connections.
</para>
<screen>
disconnect_user('smith') -> Disconnects user smith's clients.
disconnect_user('@smith') -> Disconnects all users whose name
vaguely resembles 'smith'
disconnect_user('%') -> Disconnects all users including
the administrator itself (dba).
</screen>
</formalpara>
<tip>
<title>See Also:</title>
<para><link linkend="UserGroupPriv">Users and Security</link> section in Server Administration</para>
</tip>
</listitem>
<listitem>
<formalpara>
<title>exec SQL function</title>
<funcsynopsis>
<funcdef>
<function>exec</function>
</funcdef>
<paramdef>
in <parameter>string</parameter> varchar</paramdef>
<paramdef>
<parameter>out state</parameter> varchar</paramdef>
<paramdef>
<parameter>out message</parameter> varchar</paramdef>
<paramdef>
in <parameter>params</parameter> any</paramdef>
<paramdef>
in <parameter>maxrows</parameter> integer</paramdef>
<paramdef>
<parameter>out metadata</parameter> any</paramdef>
<paramdef>
<parameter>out rows</parameter> any</paramdef>
</funcsynopsis>
<para>
This function provides dynamic SQL capabilities in Virtuoso PL.
The first argument is an arbitrary SQL string, which may use parameters.
The function returns in output parameters a SQL state, error message and
columns descriptions and result set rows if the statement is a select.
</para>
<itemizedlist mark="bullet">
<listitem>
<formalpara>
<title>string</title>
<para>An arbitrary SQL string, using ?'s for parameter markers.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>state</title>
<para>The 5 character SQL state, if an error occurs. If there is no error, this argument is not set.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>message</title>
<para>The SQL error message associated with a possible error. If there is no error this is not set.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>params</title>
<para>A vector of parameters, element 0 corresponding to the first ? etc.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>maxrows</title>
<para>The maximum number of rows to retrieve in the case of a select statement.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>metadata</title>
<para>A description of the statement, including column names and types. See comments.</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>rows</title>
<para>An array with one element per result row of a select statement.
Each element is an array with the leftmost column at index 0 and so on.</para>
</formalpara>
</listitem>
</itemizedlist>
<para>
Comments
</para>
<para>
The metadata is an array with the following elements:
</para>
<itemizedlist>
<listitem>
<para>0 columns - This is an array with one element per result column. </para>
</listitem>
</itemizedlist>
<para>
Each column is described as an array with:
</para>
<itemizedlist>
<listitem>
<para>0 name</para>
</listitem>
<listitem>
<para>1 type</para>
</listitem>
<listitem>
<para>2 scale</para>
</listitem>
<listitem>
<para>3 precision</para>
</listitem>
<listitem>
<para>4 nullable</para>
</listitem>
<listitem>
<para>5 updatable</para>
</listitem>
<listitem>
<para>6 searchable.</para>
</listitem>
</itemizedlist>
<para>
1 type of statement, 1 means select, 0 means DML.
</para>
<para>
Other elements may appear as trailing elements.
</para>
<para>
The type codes are internal, corresponding but not equal to the ODBC SQL type codes.
</para>
<para>
A stored procedure can be invoked by exec but a procedure's result set
will not be received in the rows output parameter but rather sent to the client.
</para>
<example>
<title>Examples:</title>
<programlisting>
To write a procedure that checks if a given table is empty:
create procedure tb_is_empty (in tb varchar)
{
declare state, msg, 1, descs, ros any;
state := '00000';
exec (sprintf ('select 1 from %s', tb), state,
msg, vector (), 1, descs, rows);
if (state <> '00000')
signal (state, msg);
if (length (rows) = 0)
return 1;
else
return 0;
}
</programlisting>
</example>
<para>
if there is an error, e.g. timeout or deadlock, the error is reported
back to the caller as an exception. exec always returns, no matter the
type of exception. Thus exec is also useful as a universal error catcher.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>explain SQL function</title>
<funcsynopsis>
<funcdef>
<function>explain</function>
</funcdef>
<paramdef>
in <parameter>text</parameter> varchar</paramdef>
<paramdef>[in <parameter>cursor_type</parameter> integer]</paramdef>
</funcsynopsis>
<para>
The explain function compiles a SQL statement and returns
a description of the compilation as a result set. The set consists
of one column, a varchar, which corresponds to each line of the description but may be long,
several hundred characters.
</para>
<para>
The explain output is mostly useful for determining join order or the
splitting of a distributed VDB query over the different data sources.
</para>
<para>
The output is not a complete disassembly of the query graph but is detailed
enough to show the join order, subquery structure and the order of evaluation
of predicates.
</para>
<para>
The optional cursor type can be one of the SQL_CURSOR_<xx> constants.
The default is 0, for forward only. If the statement is a SELECT and
the cursor type is not forward only, the auxiliary SQL statements used by the
cursor implementation are shown.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>gz_compress, gz_uncompress, string_output_gz_compress</title>
<funcsynopsis>
<funcdef>gz_string <function>gz_compress</function>
</funcdef>
<paramdef>
in <parameter>string</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>any <function>gz_uncompress</function>
</funcdef>
<paramdef>
in <parameter>gz_string</parameter> varchar</paramdef>
<paramdef>
<parameter>inout string_output</parameter> any</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>gz_string <function>string_output_gz_compress</function>
</funcdef>
<paramdef>
in <parameter>string_output</parameter> output</paramdef>
</funcsynopsis>
<para>
The gz_compress returns its argument compressed with the gzip
algorithm. The argument and return values are arbitrary strings,
possibly including any 8 bit characters.
</para>
<para>
gz_uncompress accepts a string produced by gz_compress and uncompresses it.
The uncompressed data is appended to the string output object given as second
argument. The string_output_string can function can be used to retrieve the actual string given
the string output object.
</para>
<para>
The string_output_gz_compress returns a string with the compressed content of
the string in the string output object given as parameter.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>encode_base64, decode_base64</title>
<funcsynopsis>
<funcdef>base64_string <function>encode_base64</function>
</funcdef>
<paramdef>
in <parameter>string</parameter> varchar</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>string <function>decode_base64</function>
</funcdef>
<paramdef>
in <parameter>string</parameter> varchar</paramdef>
</funcsynopsis>
<para>
These functions respectively encode and decode strings in base 64.
The return value is the argument either encoded or decoded.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>row_count</title>
<funcsynopsis>
<funcdef>integer <function>row_count</function>
</funcdef>
</funcsynopsis>
<para>
This function returns the count of rows affected by the previous DML statement
in a procedure body. The scope is local to the procedure. Calling
this from ODBC will always return 0. This is the PL equivalent of the
SQLRowCount ODBC function.
</para>
</formalpara>
</listitem>
<listitem>
<formalpara>
<title>rnd, randomize</title>
<funcsynopsis>
<funcdef>number <function>rnd</function>
</funcdef>
<paramdef>
in <parameter>n</parameter> integer</paramdef>
</funcsynopsis>
<funcsynopsis>
<funcdef>
<function>randomize</function>
</funcdef>
<paramdef>
in <parameter>seed</parameter> integer</paramdef>
</funcsynopsis>
<para>
The rnd function returns a random number between zero and n - 1, inclusive.
</para>
<para>
randomize initializes the random number generator.
</para>
<para>
The random number generator is initialized after the clock at first usage, so the
produced sequences will be different each time unless
specifically initialized.
</para>
</formalpara>
</listitem>
</itemizedlist>
</sect1>
</chapter>
|