Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: why I can not select form Pro*c?
In article <8b6puj$f09$1_at_nnrp1.deja.com>,
jing shen <shenjing_at_my-deja.com> wrote:
> Hi all:
>
> I am now trying to select some record form oracle db in Pro*c
program.
> But every time I tried it select nothing .
>
> Can you give me some help?
>
> Thanks in advance .
>
> jing Shen
> jshen_at_cad.zju.edu.cn
>
Have you tried to do the same select with the same parameters using sqlplus?
the following is the pro*c program:
>
> ---------------------------
>
> #include <sys/types.h>
> #include <sys/stat.h>
>
> #if !(defined(FD_SET) || defined(linux))
> #include <sys/select.h>
> #endif /* FD_SET */
>
> #if defined(sys5)
> #include <sys/sysmacros.h>
> #endif /*sys5*/
>
> #ifdef SVR4
> #include <sys/systeminfo.h>
> #endif /*SVR4*/
>
> #include <sys/param.h>
> #include <sys/socket.h>
> #include <sys/time.h>
> #include <sys/file.h>
> #include <sys/wait.h>
> #include <net/if.h>
> #include <netinet/in.h>
> #ifdef SVR4
> #include <sys/systeminfo.h>
> #endif /*SVR4*/
>
> #include <sys/param.h>
> #include <sys/socket.h>
> #include <sys/time.h>
> #include <sys/file.h>
> #include <sys/wait.h>
> #include <net/if.h>
> #include <netinet/in.h>
>
> #include <signal.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <netdb.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <memory.h>
> #include <unistd.h>
> #include <syslog.h>
>
> /* Oracle OCI head file */
>
> #include <sqlca.h>
>
> VARCHAR username[20];
> VARCHAR password[20];
> VARCHAR s_username[8];
> VARCHAR s_password[12];
>
> struct
>
> struct
> {
> VARCHAR username[8];
> VARCHAR password[12];
> } emprec ;
>
> struct
> {
> short username_ind;
> short password_ind;
>
> } emprec_ind;
>
> int emp_number;
> VARCHAR q_name[8];
> float salary;
> float commission;
> char temp_char[32];
> char s_name[10];
> char s_pass[20];
>
> void sql_error();
>
> main()
>
> {
>
> /* start up as a daemon */
>
> /* open the socket to receive request */
>
> /* connect to Database server *
>
> strncpy ((char*)username.arr , "sj",20);
> username.len = strlen((char*)username.arr);
> strncpy((char*)password.arr,"fxltsbl",20);
> password.len = strlen((char*)password.arr);
>
> EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n") ;
>
> EXEC SQL CONNECT :username IDENTIFIED BY :password ;
>
> /* wait for request and verify the result */
>
> printf (" \n Connected to ORACLE as user : %s \n", username.arr);
> printf (" \n Enter emplyee name : ");
> gets(temp_char);
>
> strncpy ((char*)q_name.arr , temp_char,strlen(temp_char));
>
> printf ("\n the user name copied is %s \n", q_name.arr);
> q_name.len = strlen((char*)q_name.arr);
>
> printf("the name input is : %s\n",q_name.arr);
> printf("the name length input is : %d\n",q_name.len);
>
> EXEC SQL WHENEVER NOT FOUND GOTO bad;
>
> EXEC SQL SELECT username, password INTO :s_username, :s_password
> FROM RAD
> WHERE username = :q_name ;
>
> printf("emp name selected is %s\n",s_username.arr);
> printf("emp pass selected is %s\n",s_password.arr);
> printf("emp name length selected is %d\n",strlen(s_username.arr));
> printf("emp pass length selected is %d\n",strlen(s_password.arr));
> printf(" \n\n Employee \t Salary \t Commission \n");
> printf(" --------------------------------------------------\n");
> printf("%-8s \t %-8s",s_username.arr, s_password.arr);
>
> EXEC SQL COMMIT WORK RELEASE;
>
> printf(" \nHave a good day! \n");
>
> bad:
> printf("Ohh bad!here am i\n");
>
> exit(0);
>
> }
>
> void
> sql_error(msg)
> char *msg;
> {
>
> char err_msg[128];
> int buf_len , msg_len;
>
> EXEC SQL WHENEVER SQLERROR CONTINUE;
>
> printf("\n%s\n",msg);
> buf_len=sizeof(err_msg);
> sqlglm(err_msg,&buf_len,&msg_len);
>
> EXEC SQL ROLLBACK RELEASE;
> exit(1);
> }
>
> -------------------
>
> Database desc.
>
> ---------
>
> SQL> describe rad;
> Name Null? Type
> ------------------------------- -------- ----
> USERNAME NOT NULL VARCHAR2(8)
> PASSWORD VARCHAR2(20)
>
> SQL> select * from rad;
>
> USERNAME PASSWORD
> -------- --------------------
> sj fxltsbl
> dd12334
> dd
>
> fs fstes
> test test23
>
> SQL>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Mar 20 2000 - 22:05:22 CST
![]() |
![]() |