xorg touchscreen: absolute position ignored - x11

I'm trying to use an EETI EXC7200 touchscreen with X (1.14.7). The touchscreen is recognized and events are processed. TS sends absolute coordinates and evdev driver is used (mode absolute). However when I move to the edge of the screen (and X or Y reaches 0) the pointer is snapped to center of the window. Afterwards any movement has an offset (depending on the difference between real position and corner).
To test this I draw pointer on the screen with coordinates from XQueryPointer.
Here is the output from evtest:
~# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "EETI EXC7200 Touch Screen"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 330 (BTN_TOUCH)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 1928
Min 0
Max 2047
Event code 1 (ABS_Y)
Value 1825
Min 0
Max 2047
Event code 47 (ABS_MT_SLOT)
Value 0
Min 0
Max 1
Event code 53 (ABS_MT_POSITION_X)
Value 0
Min 0
Max 2047
Event code 54 (ABS_MT_POSITION_Y)
Value 0
Min 0
Max 2047
Event code 57 (ABS_MT_TRACKING_ID)
Value 0
Min 0
Max 65535
Properties:
Testing ... (interrupt to exit)
Event: time 6435.172526, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 39
Event: time 6435.172535, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 75
Event: time 6435.172537, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 775
Event: time 6435.172542, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 6435.172546, type 3 (EV_ABS), code 0 (ABS_X), value 75
Event: time 6435.172548, type 3 (EV_ABS), code 1 (ABS_Y), value 775
Event: time 6435.172550, -------------- EV_SYN ------------
Event: time 6435.236468, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 77
Event: time 6435.236472, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 776
Event: time 6435.236477, type 3 (EV_ABS), code 0 (ABS_X), value 77
Event: time 6435.236479, type 3 (EV_ABS), code 1 (ABS_Y), value 776
Event: time 6435.236481, -------------- EV_SYN ------------
Event: time 6435.290502, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 79
Event: time 6435.290510, type 3 (EV_ABS), code 0 (ABS_X), value 79
Event: time 6435.290513, -------------- EV_SYN ------------
Event: time 6435.354553, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 778
Event: time 6435.354571, type 3 (EV_ABS), code 1 (ABS_Y), value 778
Event: time 6435.354573, -------------- EV_SYN ------------
Event: time 6435.376630, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 78
Event: time 6435.376637, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 781
Event: time 6435.376644, type 3 (EV_ABS), code 0 (ABS_X), value 78
Event: time 6435.376646, type 3 (EV_ABS), code 1 (ABS_Y), value 781
Event: time 6435.376648, -------------- EV_SYN ------------
Event: time 6435.397552, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 76
Event: time 6435.397556, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 783
Event: time 6435.397561, type 3 (EV_ABS), code 0 (ABS_X), value 76
Event: time 6435.397563, type 3 (EV_ABS), code 1 (ABS_Y), value 783
Event: time 6435.397565, -------------- EV_SYN ------------
Event: time 6435.408593, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 74
Event: time 6435.408599, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 784
Event: time 6435.408606, type 3 (EV_ABS), code 0 (ABS_X), value 74
Event: time 6435.408608, type 3 (EV_ABS), code 1 (ABS_Y), value 784
Event: time 6435.408610, -------------- EV_SYN ------------
Event: time 6435.419598, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 70
Event: time 6435.419603, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 785
Event: time 6435.419609, type 3 (EV_ABS), code 0 (ABS_X), value 70
Event: time 6435.419611, type 3 (EV_ABS), code 1 (ABS_Y), value 785
Event: time 6435.419613, -------------- EV_SYN ------------
Event: time 6435.429599, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 64
Event: time 6435.429602, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 786
Event: time 6435.429608, type 3 (EV_ABS), code 0 (ABS_X), value 64
Event: time 6435.429610, type 3 (EV_ABS), code 1 (ABS_Y), value 786
Event: time 6435.429612, -------------- EV_SYN ------------
Event: time 6435.440599, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 54
Event: time 6435.440604, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 787
Event: time 6435.440610, type 3 (EV_ABS), code 0 (ABS_X), value 54
Event: time 6435.440611, type 3 (EV_ABS), code 1 (ABS_Y), value 787
Event: time 6435.440613, -------------- EV_SYN ------------
Event: time 6435.451595, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 43
Event: time 6435.451602, type 3 (EV_ABS), code 0 (ABS_X), value 43
Event: time 6435.451605, -------------- EV_SYN ------------
Event: time 6435.462619, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 32
Event: time 6435.462623, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 786
Event: time 6435.462629, type 3 (EV_ABS), code 0 (ABS_X), value 32
Event: time 6435.462631, type 3 (EV_ABS), code 1 (ABS_Y), value 786
Event: time 6435.462633, -------------- EV_SYN ------------
Event: time 6435.472642, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 22
Event: time 6435.472648, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 785
Event: time 6435.472654, type 3 (EV_ABS), code 0 (ABS_X), value 22
Event: time 6435.472656, type 3 (EV_ABS), code 1 (ABS_Y), value 785
Event: time 6435.472658, -------------- EV_SYN ------------
Event: time 6435.483646, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 14
Event: time 6435.483651, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 783
Event: time 6435.483657, type 3 (EV_ABS), code 0 (ABS_X), value 14
Event: time 6435.483658, type 3 (EV_ABS), code 1 (ABS_Y), value 783
Event: time 6435.483660, -------------- EV_SYN ------------
Event: time 6435.494684, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 8
Event: time 6435.494689, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 782
Event: time 6435.494697, type 3 (EV_ABS), code 0 (ABS_X), value 8
Event: time 6435.494699, type 3 (EV_ABS), code 1 (ABS_Y), value 782
Event: time 6435.494701, -------------- EV_SYN ------------
Event: time 6435.504820, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 4
Event: time 6435.504829, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 781
Event: time 6435.504837, type 3 (EV_ABS), code 0 (ABS_X), value 4
Event: time 6435.504839, type 3 (EV_ABS), code 1 (ABS_Y), value 781
Event: time 6435.504841, -------------- EV_SYN ------------
Event: time 6435.515636, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 2
Event: time 6435.515640, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 780
Event: time 6435.515646, type 3 (EV_ABS), code 0 (ABS_X), value 2
Event: time 6435.515648, type 3 (EV_ABS), code 1 (ABS_Y), value 780
Event: time 6435.515650, -------------- EV_SYN ------------
Event: time 6435.537672, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 0
Event: time 6435.537683, type 3 (EV_ABS), code 0 (ABS_X), value 0
Event: time 6435.537686, -------------- EV_SYN ------------
Event: time 6435.600755, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 777
Event: time 6435.600766, type 3 (EV_ABS), code 1 (ABS_Y), value 777
Event: time 6435.600768, -------------- EV_SYN ------------
Event: time 6435.601836, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 6435.601844, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 6435.601847, -------------- EV_SYN ------------
And (at the same time) translated output via xinput:
~# xinput test 6
motion a[0]=75 a[1]=775
button press 1 a[0]=75 a[1]=775
motion a[0]=77 a[1]=776
motion a[0]=79 a[1]=776
motion a[0]=79 a[1]=778
motion a[0]=78 a[1]=781
motion a[0]=76 a[1]=783
motion a[0]=74 a[1]=784
motion a[0]=70 a[1]=785
motion a[0]=64 a[1]=786
motion a[0]=54 a[1]=787
motion a[0]=43 a[1]=787
motion a[0]=32 a[1]=786
motion a[0]=22 a[1]=785
motion a[0]=14 a[1]=783
motion a[0]=1024 a[1]=1024
motion a[0]=8 a[1]=782
motion a[0]=1024 a[1]=1024
motion a[0]=4 a[1]=781
motion a[0]=1024 a[1]=1024
motion a[0]=2 a[1]=780
motion a[0]=1024 a[1]=1024
motion a[0]=0 a[1]=780
motion a[0]=1024 a[1]=1024
motion a[0]=0 a[1]=777
button release 1 a[0]=0 a[1]=777
motion a[0]=1024 a[1]=1024
xinput is outputting extra motion events positioned at the center. But only when I get near the edge of touchscreen.
What am I doing wrong? What should I be looking at?
Thank you for any help or hints.

The cause was in SDL 1.2.15 which was used at the same time. By default it uses relative mode for mouse/touch events and apparently sends own X11 mouse events for corrections it makes ("see motion a[0]=1024 a[1]=1024").
Setting environment variable SDL_MOUSE_RELATIVE=0 fixed this behavior.

Related

[]uint8 inteface from UUID database data type to STRING or UUID GOLANG

I have problem when return uuid type from database using interface, I geeting back []uint8 not uuid or string,
here []uint8 interface data,
id: [53 102 53 56 99 101 99 98 45 101 48 52 49 45 52 54 52 57 45 98 54 49 55 45 100 53 55 56 102 49 97 50 53 53 51 56]
expected
id: 5f58cecb-e041-4649-b617-d578f1a25538
how to convert back []uint8 interface to UUID or string
thanks
If it's just a []uint8 then string(buf) will convert it. You seem to be implying that it's an interface{} though. In that case you would do string(buf.([]uint8)).

how to sort the numbers 1, ... n lexicographically without converting the numbers to string?

Assume I have input n how I can print this sequence without convert the number to string?
i.e:-
n = 100
Output :- 1 10 100 11 12 13 14 15 16 17 18 19 2 20 ...
n = 15 Output :- 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9
n = 20 Output :- 1 10 11 12 13 15 15 16 17 18 19 2 20 3 4 5 6 7 8 9
What is the main factor here?
My initial solution that will print the 1's followed by 0's or 2's followed by 0's
int n = 100;
for (int i = 1; i <= n; i++) {
int x = i;
while (x <= n) {
System.out.println(x);
x *= 10;
}
}
I figured out the solution:-
You can call it with initial k = 1
for example printnum(15, 1
void printnums(int n, int k) {
if (k > n) {
return;
}
for (int i = 0; i < 10; i++) {
if (k <= n) {
System.out.println(k);
k *= 10;
printnums(n, k);
k /= 10;
k++;
if (k % 10 == 0) return;
}
}
}
I don't know if there are more optimized one?
Here a condensed solution in Python based on the OP's own answer:
def genRangeLexiSorted(n, k=1):
for i in range(k, min(k+10-k%10, n+1)):
yield i
for j in genRangeLexiSorted(n, 10*i):
yield j
def printnums(n):
print(*list(genRangeLexiSorted(n)))
Then the calls
printnums(1)
printnums(9)
printnums(11)
printnums(20)
printnums(100)
give the following outputs:
1
1 2 3 4 5 6 7 8 9
1 10 11 2 3 4 5 6 7 8 9
1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9
1 10 100 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 41 42 43 44 45 46 47 48 49 5 50 51 52 53 54 55 56 57 58 59 6 60 61 62 63 64 65 66 67 68 69 7 70 71 72 73 74 75 76 77 78 79 8 80 81 82 83 84 85 86 87 88 89 9 90 91 92 93 94 95 96 97 98 99

Suave "Hello World!" program doesn't work with visual studio for Mac

I got runtime errors trying to execute the "Hello World!" program from Suave web page:
open Suave.Web
open Suave.Successful
[<EntryPoint>]
let main argv =
startWebServer defaultConfig (OK "Hello, Suave!")
0
With this errors:
Loaded assembly: /Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/bin/Debug/SuaveRestApi.exe
Loaded assembly: /Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/bin/Debug/FSharp.Core.dll
[External] Loaded assembly: /Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/bin/Debug/Suave.dll
[External] Loaded assembly:
/Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
[External] Loaded assembly:
/Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
[External] Method idx 6984 is greater than number of rows (6984) in
PPDB MethodDebugInformation table, for method
.$YoLo:.cctor in
'/Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/bin/Debug/Suave.pdb'.
Likely a malformed PDB file. Stacktrace:
at <0xffffffff> at (wrapper managed-to-native)
object.__icall_wrapper_mono_generic_class_init (intptr) [0x00007] in
<699ddfd029d348d1a69fb1f9fc28d7cb>:0 at YoLo/UTF8.get_utf8 ()
[0x00000] in
/Users/ademar/Projects/release/suave/src/Suave/Utils/YoLo.fs:447 at
Suave.Successful.OK (string) [0x00000] in
/Users/ademar/Projects/release/suave/src/Suave/Combinators.fs:136 at
App.main (string[]) [0x00000] in /Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/App.fs:6
at (wrapper runtime-invoke) .runtime_invoke_int_object
(object,intptr,intptr,intptr) [0x00057] in
<5c0abea33afd9276a7450383a3be0a5c>:0 Memory around native instruction
pointer (0x7fff71ccc23e): 0x7fff71ccc22e ff ff c3 90 90 90 b8 48 01
00 02 49 89 ca 0f 05 .......H...I.... 0x7fff71ccc23e 73 08 48 89 c7
e9 6f a1 ff ff c3 55 48 89 e5 41 s.H...o....UH..A 0x7fff71ccc24e 57
41 56 41 55 41 54 53 48 81 ec 88 00 00 00 49 WAVAUATSH......I
0x7fff71ccc25e 89 f4 48 8d 05 01 c3 cb 32 48 8b 00 48 8d 9d 60
..H.....2H..H..`
Native stacktrace:
0 mono 0x000000010ba29842
mono_dump_native_crash_info + 898 1 mono
0x000000010b9cd303 mono_handle_native_crash + 195 2
libsystem_platform.dylib 0x00007fff71d77b3d _sigtramp + 29
3 mono 0x000000010bcdf008
simple_lower_case_mapping_higharea_table0 + 20296 4
libsystem_c.dylib 0x00007fff71c351c9 abort + 127 5
mono 0x000000010bbf9c5f
mono_log_write_logfile + 351 6 mono
0x000000010bc15dac monoeg_g_log + 204 7 mono
0x000000010bac9e68 mono_ppdb_get_seq_points + 1112 8 mono
0x000000010b93492f mono_method_to_ir + 1151 9 mono
0x000000010b91ade7 mini_method_compile + 3479 10 mono
0x000000010b91e32c mono_jit_compile_method_inner + 76 11 mono
0x000000010b921cc9 mono_jit_compile_method_with_opt + 2665 12 mono
0x000000010b925d8e mono_jit_runtime_invoke + 526 13 mono
0x000000010bb241d4 do_runtime_invoke + 84 14 mono
0x000000010bb201a8 mono_runtime_class_init_full + 872 15 mono
0x000000010b97a69c mono_generic_class_init + 28 16 ???
0x000000010beb7e2c 0x0 + 4494949932 17 mono
0x000000010b9261d3 mono_jit_runtime_invoke + 1619 18 mono
0x000000010bb241d4 do_runtime_invoke + 84 19 mono
0x000000010bb27cac do_exec_main_checked + 156 20 mono
0x000000010b98d19d mono_jit_exec + 349 21 mono
0x000000010b99037f mono_main + 11615 22 mono
0x000000010b915078 main + 264 23 libdyld.dylib
0x00007fff71b8ced9 start + 1 Pkilling 0x70000ed57000 from 0x1115795c0
Pkilling 0x70000eb54000 from 0x1115795c0 Entering thread summarizer
pause from 0x1115795c0 Finished thread summarizer pause from
0x1115795c0.
Waiting for dumping threads to resume
Debug info from gdb:
(lldb) command source -s 0 '/tmp/mono-gdb-commands.UoI26p' Executing
commands in '/tmp/mono-gdb-commands.UoI26p'. (lldb) process attach
--pid 1457 Process 1457 stopped
* thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00007fff71ccb2d2 libsystem_kernel.dylib__wait4 + 10 libsystem_kernel.dylib__wait4:
-> 0x7fff71ccb2d2 <+10>: jae 0x7fff71ccb2dc ; <+20>
0x7fff71ccb2d4 <+12>: movq %rax, %rdi
0x7fff71ccb2d7 <+15>: jmp 0x7fff71cc6381 ; cerror
0x7fff71ccb2dc <+20>: retq Target 0: (mono) stopped.
Executable module set to
"/Library/Frameworks/Mono.framework/Versions/5.18.0/bin/mono".
Architecture set to: x86_64h-apple-macosx. (lldb) thread list Process
1457 stopped
* thread #1: tid = 0xd6f5, 0x00007fff71ccb2d2 libsystem_kernel.dylib__wait4 + 10, name = 'tid_307', queue =
'com.apple.main-thread', stop reason = signal SIGSTOP thread #2: tid
= 0xd6f6, 0x00007fff71cc97de libsystem_kernel.dylib__psynch_cvwait + 10, name = 'SGen worker' thread #3: tid = 0xd6f8, 0x00007fff71cc61b6
libsystem_kernel.dylibsemaphore_wait_trap + 10, name = 'Finalizer'
thread #4: tid = 0xd6f9, 0x00007fff71cc93e6
libsystem_kernel.dylib__recvfrom + 10, name = 'Debugger agent'
thread #5: tid = 0xd700, 0x00007fff71cc7b6a
libsystem_kernel.dylib__workq_kernreturn + 10 thread #6: tid =
0xd701, 0x00007fff71cc7b6a libsystem_kernel.dylib__workq_kernreturn +
10 (lldb) thread backtrace all
* thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP * frame #0: 0x00007fff71ccb2d2
libsystem_kernel.dylib__wait4 + 10
frame #1: 0x000000010ba299b6 monomono_dump_native_crash_info at mini-posix.c:1079 [opt]
frame #2: 0x000000010ba29862 monomono_dump_native_crash_info(signal="SIGABRT",
ctx=0x00007ffee42eb0f0, info=<unavailable>) at mini-posix.c:1102 [opt]
frame #3: 0x000000010b9cd303 monomono_handle_native_crash(signal="SIGABRT",
ctx=0x00007ffee42eb0f0, info=0x00007ffee42eb088) at
mini-exceptions.c:3197 [opt]
frame #4: 0x00007fff71d77b3d libsystem_platform.dylib_sigtramp + 29
frame #5: 0x00007fff71ccc23f libsystem_kernel.dylib__pthread_kill + 11
frame #6: 0x00007fff71d82c1c libsystem_pthread.dylibpthread_kill + 285
frame #7: 0x00007fff71c351c9 libsystem_c.dylibabort + 127
frame #8: 0x000000010bbf9c5f monomono_log_write_logfile(log_domain=<unavailable>,
level=<unavailable>, hdr=<unavailable>, message="Method idx 6984 is
greater than number of rows (6984) in PPDB MethodDebugInformation
table, for method <StartupCode$Suave>.$YoLo:.cctor in
'/Users/[myUserName]/Library/Mobile
Documents/com~apple~CloudDocs/Projects/SuaveRestApi/SuaveRestApi/bin/Debug/Suave.pdb'.
Likely a malformed PDB file.") at mono-log-common.c:135 [opt]
frame #9: 0x000000010bc15dac monomonoeg_g_log [inlined] monoeg_g_logstr(log_domain=0x0000000000000000,
log_level=G_LOG_LEVEL_ERROR, msg=) at goutput.c:117 [opt]
frame #10: 0x000000010bc15d83 monomonoeg_g_log [inlined] monoeg_g_logv_nofree(format=<unavailable>, args=<unavailable>) at
goutput.c:128 [opt]
frame #11: 0x000000010bc15d70 monomonoeg_g_log [inlined] monoeg_g_logv(format=, args=) at
goutput.c:135 [opt]
frame #12: 0x000000010bc15d70 monomonoeg_g_log(log_domain=0x0000000000000000,
log_level=G_LOG_LEVEL_ERROR, format=<unavailable>) at goutput.c:144
[opt]
frame #13: 0x000000010bac9e68 monomono_ppdb_get_seq_points(minfo=,
source_file=, source_file_list=,
source_files=, seq_points=0x00007ffee42eb730,
n_seq_points=) at debug-mono-ppdb.c:427 [opt]
frame #14: 0x000000010b93492f monomono_method_to_ir(cfg=<unavailable>, method=<unavailable>,
start_bblock=0x0000000000000000, end_bblock=0x0000000000000000,
return_var=0x0000000000000000, inline_args=0x0000000000000000,
inline_offset=<unavailable>, is_virtual_call=<unavailable>) at
method-to-ir.c:6674 [opt]
frame #15: 0x000000010b91ade7 monomini_method_compile(method=, opts=374434303,
domain=0x00007fbc91f02f00, flags=JIT_FLAG_RUN_CCTORS, parts=0,
aot_method_index=-1) at mini.c:3455 [opt]
frame #16: 0x000000010b91e32c monomono_jit_compile_method_inner(method=0x00007fbc94832ea8,
target_domain=0x00007fbc91f02f00, opt=<unavailable>,
error=0x00007ffee42ebd60) at mini.c:4043 [opt]
frame #17: 0x000000010b921cc9 monomono_jit_compile_method_with_opt(method=0x00007fbc94832ea8,
opt=, jit_only=1, error=0x00007ffee42ebd60) at
mini-runtime.c:2411 [opt]
frame #18: 0x000000010b925d8e monomono_jit_runtime_invoke [inlined] mono_jit_compile_method_jit_only(method=<unavailable>,
error=0x00007ffee42ebd60) at mini-runtime.c:2471 [opt]
frame #19: 0x000000010b925d6e monomono_jit_runtime_invoke(method=, obj=,
params=0x0000000000000000, exc=,
error=0x00007ffee42ebd60) at mini-runtime.c:3011 [opt]
frame #20: 0x000000010bb241d4 monodo_runtime_invoke(method=0x00007fbc94832ea8,
obj=0x0000000000000000, params=0x0000000000000000,
exc=0x00007ffee42ebd08, error=0x00007ffee42ebd60) at object.c:2960
[opt]
frame #21: 0x000000010bb201a8 monomono_runtime_class_init_full [inlined] mono_runtime_try_invoke(method=,
obj=, params=, error=0x00007ffee42ebd60) at
object.c:3069 [opt]
frame #22: 0x000000010bb20167 monomono_runtime_class_init_full(vtable=0x00007fbc9402ee60,
error=0x00007ffee42ebd60) at object.c:526 [opt]
frame #23: 0x000000010b97a69c monomono_generic_class_init(vtable=) at
jit-icalls.c:1511 [opt]
frame #24: 0x000000010beb7e2c
frame #25: 0x000000010b9261d3 monomono_jit_runtime_invoke(method=<unavailable>, obj=<unavailable>,
params=0x00007ffee42ec148, exc=0x00007fbc9402ee60,
error=<unavailable>) at mini-runtime.c:3148 [opt]
frame #26: 0x000000010bb241d4 monodo_runtime_invoke(method=0x00007fbc91f04798,
obj=0x0000000000000000, params=0x00007ffee42ec148,
exc=0x0000000000000000, error=0x00007ffee42ec180) at object.c:2960
[opt]
frame #27: 0x000000010bb27cac monodo_exec_main_checked [inlined] mono_runtime_invoke_checked(method=<unavailable>, obj=<unavailable>,
params=<unavailable>, error=0x00007ffee42ec180) at object.c:3128 [opt]
frame #28: 0x000000010bb27c9d monodo_exec_main_checked(method=0x00007fbc91f04798,
args=, error=0x00007ffee42ec180) at object.c:4949 [opt]
frame #29: 0x000000010b98d19d monomono_jit_exec at driver.g.c:1236 [opt]
frame #30: 0x000000010b98d18f monomono_jit_exec(domain=, assembly=,
argc=1, argv=0x00007ffee42ec550) at driver.g.c:1195 [opt]
frame #31: 0x000000010b99037f monomono_main [inlined] main_thread_handler at driver.g.c:1313 [opt]
frame #32: 0x000000010b990348 monomono_main(argc=4, argv=) at driver.g.c:2483 [opt]
frame #33: 0x000000010b915078 monomain [inlined] mono_main_with_options(argc=<unavailable>, argv=<unavailable>) at
main.c:50 [opt]
frame #34: 0x000000010b915064 monomain(argc=4, argv=) at main.c:405 [opt]
frame #35: 0x00007fff71b8ced9 libdyld.dylibstart + 1
frame #36: 0x00007fff71b8ced9 libdyld.dylibstart + 1 thread #2, name = 'SGen worker'
frame #0: 0x00007fff71cc97de libsystem_kernel.dylib__psynch_cvwait + 10
frame #1: 0x00007fff71d83593 libsystem_pthread.dylib_pthread_cond_wait + 724
frame #2: 0x000000010bbf10ee monothread_func [inlined] mono_os_cond_wait(mutex=<unavailable>) at mono-os-mutex.h:173 [opt]
frame #3: 0x000000010bbf10db monothread_func at sgen-thread-pool.c:165 [opt]
frame #4: 0x000000010bbf10cd monothread_func(data=0x0000000000000000) at sgen-thread-pool.c:196
[opt]
frame #5: 0x00007fff71d80305 libsystem_pthread.dylib_pthread_body + 126
frame #6: 0x00007fff71d8326f libsystem_pthread.dylib_pthread_start + 70
frame #7: 0x00007fff71d7f415 libsystem_pthread.dylibthread_start + 13 thread #3, name = 'Finalizer'
frame #0: 0x00007fff71cc61b6 libsystem_kernel.dylibsemaphore_wait_trap + 10
frame #1: 0x000000010bb9e9aa monofinalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at
mono-os-semaphore.h:90 [opt]
frame #2: 0x000000010bb9e99f monofinalizer_thread at mono-coop-semaphore.h:43 [opt]
frame #3: 0x000000010bb9e985 monofinalizer_thread(unused=) at gc.c:918 [opt]
frame #4: 0x000000010bb49e13 monostart_wrapper [inlined] start_wrapper_internal at threads.c:1151 [opt]
frame #5: 0x000000010bb49d83 monostart_wrapper(data=0x00007fbc91f34850) at threads.c:1211 [opt]
frame #6: 0x00007fff71d80305 libsystem_pthread.dylib_pthread_body + 126
frame #7: 0x00007fff71d8326f libsystem_pthread.dylib_pthread_start + 70
frame #8: 0x00007fff71d7f415 libsystem_pthread.dylibthread_start + 13 thread #4, name = 'Debugger agent'
frame #0: 0x00007fff71cc93e6 libsystem_kernel.dylib__recvfrom + 10
frame #1: 0x000000010ba7e45e monosocket_transport_recv(buf=2001-01-01 00:00:00 UTC, len=11) at
debugger-agent.c:1108 [opt]
frame #2: 0x000000010ba6f296 monodebugger_thread [inlined] transport_recv(len=11) at debugger-agent.c:1518 [opt]
frame #3: 0x000000010ba6f27c monodebugger_thread(arg=<unavailable>) at debugger-agent.c:9484 [opt]
frame #4: 0x000000010bb49e13 monostart_wrapper [inlined] start_wrapper_internal at threads.c:1151 [opt]
frame #5: 0x000000010bb49d83 monostart_wrapper(data=0x00007fbc91f389a0) at threads.c:1211 [opt]
frame #6: 0x00007fff71d80305 libsystem_pthread.dylib_pthread_body + 126
frame #7: 0x00007fff71d8326f libsystem_pthread.dylib_pthread_start + 70
frame #8: 0x00007fff71d7f415 libsystem_pthread.dylibthread_start + 13 thread #5
frame #0: 0x00007fff71cc7b6a libsystem_kernel.dylib__workq_kernreturn + 10
frame #1: 0x00007fff71d7f630 libsystem_pthread.dylib_pthread_wqthread + 446
frame #2: 0x00007fff71d7f405 libsystem_pthread.dylibstart_wqthread + 13 thread #6
frame #0: 0x00007fff71cc7b6a libsystem_kernel.dylib__workq_kernreturn + 10
frame #1: 0x00007fff71d7f630 libsystem_pthread.dylib_pthread_wqthread + 446
frame #2: 0x00007fff71d7f405 libsystem_pthread.dylibstart_wqthread + 13 (lldb) detach
================================================================= Got a SIGABRT while executing native code. This usually indicates a fatal
error in the mono runtime or one of the native libraries used by your
application.
(lldb) quit Process 1457 detached
It seems an issue with Visual Studio for Mac and Suave. I did the same test in Visual Studio Code (for mac also) and worked fine.

Row sum in PIVOT query

Please Help me i am trying to create pivot but not success.
query
select
t.g_no,
t.sz,
t.DT,
t.Qty
from gp123 t
Result
4480 46 4/24/2017 30
4480 42 4/24/2017 28
4480 40 4/24/2017 37
4480 44 4/24/2017 26
4480 50 4/24/2017 17
4480 48 4/24/2017 2
Required result
Gate Pass No. Date 40 42 44 46 48 50 Total
4480 24-Apr-17 37 28 26 30 2 17 140
4500 25-Apr-17 187 140 155 127 99 85 793
4537 25-Apr-17 141 97 139 172 141 159 849
4538 26-Apr-17 90 141 122 148 172 151 824
4542 26-Apr-17 1 60 118 63 32 3 277
Use the SUM() OVER () analytic function to get the total and then use PIVOT to convert the rows to columns:
SELECT *
FROM ( SELECT g_no AS "Gate Pass No.",
sz,
DT AS "Date",
Qty,
SUM( qty ) OVER ( PARTITION BY g_no, DT ) AS Total
FROM gp123
)
PIVOT ( SUM( qty ) FOR sz IN ( 40, 42, 44, 46, 48, 50 ) )
... or simply:
select g_no, dt, "40", "42", "44", "46", "48", "50",
"40" + "42" + "44" + "46" + "48" + "50" total
from gp123 t
pivot (sum(qty) for sz in (40, 42, 44, 46, 48, 50));

return resultset from function

I need to return a resultset from function and work with this resultset just like with an ordinary table.
So I need something like following:
select * from table(querydb('select * from dual'))
The querydb function should return a resultset of a query passed to it.
Can it be implemented in oracle?
Would be grateful for any information.
If you need a result set and a ref cursor won't do with a datatype called sys.anydataset. i.e what you seem to want is a pipelined function, but of course with a regular pipelined function you need to define the output structure, which in your case isn't static.
Enter anydataset. this type allows us to dynamically generate types on the fly (at hard parse time only) to allow us to define pipelined functions with varying outputs.
The coding is a bit complex unfortunately.
To start with, we define a type that will do the processing of the passed in SQL statement.
SQL> create type dyn_pipeline as object
2 (
3 atype anytype,
4
5 static function ODCITableDescribe(rtype out anytype,
6 stmt in varchar2)
7 return number,
8
9 static function ODCITablePrepare(sctx out dyn_pipeline,
10 tf_info in sys.ODCITabfuncinfo,
11 stmt in varchar2)
12 return number,
13
14 static function ODCITableStart(sctx in out dyn_pipeline,
15 stmt in varchar2)
16 return number,
17
18 member function ODCITablefetch(self in out dyn_pipeline,
19 nrows in number,
20 rws out anydataset)
21 return number,
22
23 member function ODCITableClose(self in dyn_pipeline)
24 return number
25 );
26 /
Next up, we create a package spec that will be basically your querydb function call:
SQL> create package pkg_pipeline
2 as
3
4 /*
5 * Global Types
6 */
7 -- Describe array.
8 type dynamic_sql_rec is record(cursor integer,
9 column_cnt pls_integer,
10 description dbms_sql.desc_tab2,
11 execute integer);
12 -- Meta data for the ANYTYPE.
13 type anytype_metadata_rec is record(precision pls_integer,
14 scale pls_integer,
15 length pls_integer,
16 csid pls_integer,
17 csfrm pls_integer,
18 schema varchar2(30),
19 type anytype,
20 name varchar2(30),
21 version varchar2(30),
22 attr_cnt pls_integer,
23 attr_type anytype,
24 attr_name varchar2(128),
25 typecode pls_integer);
26
27
28 /*
29 * Global Variables
30 */
31 -- SQL descriptor.
32 r_sql dynamic_sql_rec;
33
34 /*
35 * function will run the given SQL
36 */
37 function querydb(p_stmt in varchar2)
38 return anydataset pipelined using dyn_pipeline;
39
40 end pkg_pipeline;
41 /
Package created.
the types there will just hold some info about the SQL structure itself (we will be using DBMS_SQL to describe the input SQL as it has functions to get the number of columns, data types etc out of any given SQL statement.
The main type body is where the processing occurs:
SQL> create type body dyn_pipeline
2 as
3
4 /*
5 * DESC step. this will be called at hard parse and will create
6 * a physical type in the DB Schema based on the select columns.
7 */
8 static function ODCITableDescribe(rtype out anytype,
9 stmt in varchar2)
10 return number
11 is
12
13 /* Variables */
14 -- Type to hold the dbms_sql info (description)
15 r_sql pkg_pipeline.dynamic_sql_rec;
16 -- Type to create (has all the columns) of the sql query.
17 t_anyt anytype;
18 -- SQL query that will be made up from the 2 passed in queries.
19 v_sql varchar2(32767);
20
21 begin
22
23 /*
24 * Parse the SQL and describe its format and structure.
25 */
26 v_sql := replace(stmt, ';', null);
27
28 -- open, parse and discover all info about this SQL.
29 r_sql.cursor := dbms_sql.open_cursor;
30 dbms_sql.parse( r_sql.cursor, v_sql, dbms_sql.native );
31 dbms_sql.describe_columns2( r_sql.cursor, r_sql.column_cnt, r_sql.description );
32 dbms_sql.close_cursor( r_sql.cursor );
33
34 -- Start to create the physical type.
35 anytype.BeginCreate( DBMS_TYPES.TYPECODE_OBJECT, t_anyt );
36
37 -- Loop through each attribute and add to the type.
38 for i in 1 .. r_sql.column_cnt
39 loop
40
41 t_anyt.AddAttr(r_sql.description(i).col_name,
42 case
43 when r_sql.description(i).col_type in (1,96,11,208)
44 then dbms_types.typecode_varchar2
45 when r_sql.description(i).col_type = 2
46 then dbms_types.typecode_number
47 when r_sql.description(i).col_type in (8,112)
48 then dbms_types.typecode_clob
49 when r_sql.description(i).col_type = 12
50 then dbms_types.typecode_date
51 when r_sql.description(i).col_type = 23
52 then dbms_types.typecode_raw
53 when r_sql.description(i).col_type = 180
54 then dbms_types.typecode_timestamp
55 when r_sql.description(i).col_type = 181
56 then dbms_types.typecode_timestamp_tz
57 when r_sql.description(i).col_type = 182
58 then dbms_types.typecode_interval_ym
59 when r_sql.description(i).col_type = 183
60 then dbms_types.typecode_interval_ds
61 when r_sql.description(i).col_type = 231
62 then dbms_types.typecode_timestamp_ltz
63 end,
64 r_sql.description(i).col_precision,
65 r_sql.description(i).col_scale,
66 r_sql.description(i).col_max_len,
67 r_sql.description(i).col_charsetid,
68 r_sql.description(i).col_charsetform );
69 end loop;
70
71 t_anyt.EndCreate;
72
73 -- set the output type to our built type.
74 ANYTYPE.BeginCreate(dbms_types.TYPECODE_TABLE, rtype);
75 rtype.SetInfo(null, null, null, null, null, t_anyt,
76 dbms_types.TYPECODE_OBJECT, 0);
77 rtype.EndCreate();
78
79 return ODCIConst.Success;
80
81 end ODCITableDescribe;
82
83
84 /*
85 * PREPARE step. Initialise our type.
86 */
87 static function ODCITableprepare(sctx out dyn_pipeline,
88 tf_info in sys.ODCITabfuncinfo,
89 stmt in varchar2)
90 return number
91 is
92
93 /* Variables */
94 -- Meta data.
95 r_meta pkg_pipeline.anytype_metadata_rec;
96
97 begin
98
99 r_meta.typecode := tf_info.rettype.getattreleminfo(
100 1, r_meta.precision, r_meta.scale, r_meta.length,
101 r_meta.csid, r_meta.csfrm, r_meta.type, r_meta.name
102 );
103
104 sctx := dyn_pipeline(r_meta.type);
105 return odciconst.success;
106
107 end;
108
109
110 /*
111 * START step. this is where we execute the cursor prior to fetching from it.
112 */
113 static function ODCITablestart(sctx in out dyn_pipeline,
114 stmt in varchar2)
115 return number
116 is
117
118 /* Variables */
119 r_meta pkg_pipeline.anytype_metadata_rec;
120 v_sql varchar2(32767);
121 begin
122
123 v_sql := replace(stmt, ';', null);
124 pkg_pipeline.r_sql.cursor := dbms_sql.open_cursor;
125 dbms_sql.parse(pkg_pipeline.r_sql.cursor, v_sql, dbms_sql.native);
126 dbms_sql.describe_columns2(pkg_pipeline.r_sql.cursor,
127 pkg_pipeline.r_sql.column_cnt,
128 pkg_pipeline.r_sql.description);
129
130 -- define all the columns found to let Oracle know the datatypes.
131 for i in 1..pkg_pipeline.r_sql.column_cnt
132 loop
133
134 r_meta.typecode := sctx.atype.GetAttrElemInfo(
135 i, r_meta.precision, r_meta.scale, r_meta.length,
136 r_meta.csid, r_meta.csfrm, r_meta.type, r_meta.name
137 );
138
139 case r_meta.typecode
140 when dbms_types.typecode_varchar2
141 then
142 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, '', 32767);
143 when dbms_types.typecode_number
144 then
145 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as number));
146 when dbms_types.typecode_date
147 then
148 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as date));
149 when dbms_types.typecode_raw
150 then
151 dbms_sql.define_column_raw(pkg_pipeline.r_sql.cursor, i, cast(null as raw), r_meta.length);
152 when dbms_types.typecode_timestamp
153 then
154 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as timestamp));
155 when dbms_types.typecode_timestamp_tz
156 then
157 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as timestamp with time zone));
158 when dbms_types.typecode_timestamp_ltz
159 then
160 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as timestamp with local time zone));
161 when dbms_types.typecode_interval_ym
162 then
163 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as interval year to month));
164 when dbms_types.typecode_interval_ds
165 then
166 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as interval day to second));
167 when dbms_types.typecode_clob
168 then
169 case pkg_pipeline.r_sql.description(i).col_type
170 when 8
171 then
172 dbms_sql.define_column_long(pkg_pipeline.r_sql.cursor, i);
173 else
174 dbms_sql.define_column(pkg_pipeline.r_sql.cursor, i, cast(null as clob));
175 end case;
176 end case;
177 end loop;
178
179 -- execute the SQL.
180 pkg_pipeline.r_sql.execute := dbms_sql.execute(pkg_pipeline.r_sql.cursor);
181
182 return odciconst.success;
183
184 end ODCITablestart;
185
186
187 /*
188 * FETCH step.
189 */
190 member function ODCITablefetch(self in out dyn_pipeline,
191 nrows in number,
192 rws out anydataset)
193 return number
194 is
195
196 /* Variables */
197 -- Buffers to hold values.
198 v_vc_col varchar2(32767);
199 v_num_col number;
200 v_date_col date;
201 v_raw_col raw(32767);
202 v_raw_error number;
203 v_raw_len integer;
204 v_int_ds_col interval day to second;
205 v_int_ym_col interval year to month;
206 v_ts_col timestamp;
207 v_tstz_col timestamp with time zone;
208 v_tsltz_col timestamp with local time zone;
209 v_clob_col clob;
210 v_clob_offset integer := 0;
211 v_clob_len integer;
212 -- Metadata
213 r_meta pkg_pipeline.anytype_metadata_rec;
214
215 begin
216
217 if dbms_sql.fetch_rows( pkg_pipeline.r_sql.cursor ) > 0
218 then
219
220 -- Describe to get number and types of columns.
221 r_meta.typecode := self.atype.getinfo(
222 r_meta.precision, r_meta.scale, r_meta.length,
223 r_meta.csid, r_meta.csfrm, r_meta.schema,
224 r_meta.name, r_meta.version, r_meta.attr_cnt
225 );
226
227 anydataset.begincreate(dbms_types.typecode_object, self.atype, rws);
228 rws.addinstance();
229 rws.piecewise();
230
231 -- loop through each column extracting value.
232 for i in 1..pkg_pipeline.r_sql.column_cnt
233 loop
234
235 r_meta.typecode := self.atype.getattreleminfo(
236 i, r_meta.precision, r_meta.scale, r_meta.length,
237 r_meta.csid, r_meta.csfrm, r_meta.attr_type,
238 r_meta.attr_name
239 );
240
241 case r_meta.typecode
242 when dbms_types.typecode_varchar2
243 then
244 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_vc_col);
245 rws.setvarchar2(v_vc_col);
246 when dbms_types.typecode_number
247 then
248 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_num_col);
249 rws.setnumber(v_num_col);
250 when dbms_types.typecode_date
251 then
252 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_date_col);
253 rws.setdate(v_date_col);
254 when dbms_types.typecode_raw
255 then
256 dbms_sql.column_value_raw(pkg_pipeline.r_sql.cursor, i, v_raw_col,
257 v_raw_error, v_raw_len);
258 rws.setraw(v_raw_col);
259 when dbms_types.typecode_interval_ds
260 then
261 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_int_ds_col);
262 rws.setintervalds(v_int_ds_col);
263 when dbms_types.typecode_interval_ym
264 then
265 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_int_ym_col);
266 rws.setintervalym(v_int_ym_col);
267 when dbms_types.typecode_timestamp
268 then
269 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_ts_col);
270 rws.settimestamp(v_ts_col);
271 when dbms_types.typecode_timestamp_tz
272 then
273 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_tstz_col);
274 rws.settimestamptz(v_tstz_col);
275 when dbms_types.typecode_timestamp_ltz
276 then
277 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_tsltz_col);
278 rws.settimestampltz(v_tsltz_col);
279 when dbms_types.typecode_clob
280 then
281 case pkg_pipeline.r_sql.description(i).col_type
282 when 8
283 then
284 loop
285 dbms_sql.column_value_long(pkg_pipeline.r_sql.cursor, i, 32767, v_clob_offset,
286 v_vc_col, v_clob_len);
287 v_clob_col := v_clob_col || v_vc_col;
288 v_clob_offset := v_clob_offset + 32767;
289 exit when v_clob_len < 32767;
290 end loop;
291 else
292 dbms_sql.column_value(pkg_pipeline.r_sql.cursor, i, v_clob_col);
293 end case;
294 rws.setclob(v_clob_col);
295 end case;
296 end loop;
297
298 rws.endcreate();
299
300 end if;
301
302 return ODCIConst.Success;
303
304 end;
305
306 /*
307 * CLOSE step. close the cursor.
308 */
309 member function ODCITableClose(self in dyn_pipeline)
310 return number
311 is
312
313
314 begin
315 dbms_sql.close_cursor( pkg_pipeline.r_sql.cursor );
316 pkg_pipeline.r_sql := null;
317 return odciconst.success;
318 end ODCITableClose;
319
320 end;
321 /
Type body created.
once this is done, you can query like:
SQL> select * from table(pkg_pipeline.querydb('select * from dual'));
D
-
X
SQL> select * from table(pkg_pipeline.querydb('select * from v$mystat where rownum <= 2'));
SID STATISTIC# VALUE
---------- ---------- ----------
230 0 1
230 1 1
If I understand you correctly, you want to do this:
select * from (select * from dual)
...with the caveat that the subquery is in some way dynamic? You can do this using a PL/SQL block, using a reference cursor:
declare
subQuery varchar2(1000);
mainQuery varchar2(1000) := 'select * from (';
type myRefCursor is ref cursor;
myResultset myRefCursor;
myField1 FIELDTYPE;
...
myFieldN FIELDTYPE;
begin
-- Generate this dynamically
subQuery := 'select * from dual';
-- Create main query and open cursor
mainQuery := mainQuery || subQuery || ')';
open myResultset for mainQuery;
-- Loop through records
loop
fetch myResultset into myField1, ..., myFieldN;
exit when myResultset%NOTFOUND;
-- Do something with the record data
dbms_output.put_line(myField1 || ' ... ' || myFieldN);
end loop;
close myResultset;
end;
/
Note that rather than using fetch into with individual variables, you can populate an entire record at once, provided you can define the record's field types. That is, if you have created a custom type or your record's type matches a table you already have in your schema. For the latter, you can use:
myRecord someTable%ROWTYPE;
...in the declaration block, then change the fetch into statement to:
fetch myResultset into myRecord;
...and access record fields using dot notation (e.g., myRecord.some_field_name).
You say in your comments that the dynamic SQL bit is from the results of some other query. Therefore, in my example code, you could use a regular cursor to loop over these data to create the subQuery variable in each instance... Although, incidentally, is there any reason why what you're trying to achieve can't be done with a simple join?

Resources