Вопрос

So, i need to use php in order to extract some information out of my database through a procedure. There's a problem in my code and i can't get to it.

I have the following procedure:

    CREATE OR REPLACE PROCEDURE example(
    input IN varchar2, 
    p1 OUT SYS_REFCURSOR)
    AS
     BEGIN
      OPEN p1 FOR
      SELECT title
      FROM book 
      WHERE gen LIKE '_' + input + '%'
     ORDER BY gen;
    END;

and here is my php code:

$curs = oci_new_cursor($con); 
$stmt = oci_parse($con, "begin example(:input, :data); end;");

$word = 'S';
oci_bind_by_name($stmt, "input", $word);
oci_bind_by_name($stmt, "data", $curs, -1, OCI_B_CURSOR); 

oci_execute($stmt); 
oci_execute($curs);

$nr_rows = oci_fetch_all($curs, $data, null, null, OCI_FETCHSTATEMENT_BY_COLUMN);

I think the code is well written but for some odd reasons i get this error

"Warning: oci_fetch_all(): ORA-01722: invalid number in C:.."

I've tried to use cast in the procedure but the error still occures.

The select that i'm looking for is the following:

     SELECT title
      FROM book 
      WHERE gen LIKE '_S%'
     ORDER BY gen;

Any ideas?

Это было полезно?

Решение

So I have done some more research and found out that the WHERE gen LIKE '_' + input + '%' statement is invalid so i have changed the code into:

CREATE OR REPLACE PROCEDURE example(
input IN varchar2, 
p1 OUT SYS_REFCURSOR)
AS
 BEGIN
  OPEN p1 FOR
  SELECT title
  FROM book 
  WHERE gen LIKE input
 ORDER BY gen;
END;

and I've edited the php code to $word = 'S%', further more I made a POST method and wrote $word = ''.$_POST[word].'%';

Другие советы

Just to add a note here, I think under Oracle

'_' + input + '%'

would be interpreted as a numerical addition.

I think what it is complaining about would be fixed by:

'_' || input || '%'

as the || operator is string concatenation.

Any chance you come from a SQL Server background where the former is correct for appending strings?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top