ผู้เขียน หัวข้อ: ขอคำแนะนำเกี่ยวกับ substring หน่อยครับ  (อ่าน 8772 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ neopalm

  • Full Member
  • ***
  • กระทู้: 102
  • Respect: +1
    • ดูรายละเอียด
ขอคำแนะนำเกี่ยวกับ substring หน่อยครับ
« เมื่อ: เมษายน 10, 2009, 20:31:45 PM »
0
หากมีข้อมูลใน Record ดังนี้    'aaaa bbbb cccc'
เราจะใช้คำสั่งตัด string ยังไง ให้เหลือ  แต่  bbbb ครับ โดย เอา ช่องว่าง เป็น index อ่ะครับ
เพราะว่า ใน ตาราง มีหลาย record และความยาว ไม่เท่ากัน แต่ มีช่องว่าง เหมือนกันทุก record
ต้องการข้อความตรงกลาง อ่ะครับ
เอกภาพ  ศรีเจริญ (อั้ง)
นักวิชาการคอมพิวเตอร์ (ลูกจ้างชั่วคราว) โรงพยาบาลชุมชน ท่าอุเทน จ.นครพนม

ขึ้นระบบเอง เริ่มใช้ HOSxP 1 มกราคม 2552 ปัจจุบันใช้ HOSxP V.3.52.6.4
Module
OPD  :   ห้องบัตร ซักประวัติ ห้องตรวจ ห้องยา LAB ห้องฟัน ห้องฉุกเฉิน PCU X-Ray นวดแผนไทย
 IPD  :   Ward ห้องคลอด
Main   :  Server OS Linux CentOS 5.2  MySQL 5.1.30  IBM System x3650 Server
            Intel Xeon Quadcore 2.0 Ghz  SAS Drive 3x146Gb 15000rpm Ram 2x1Gb  667Mhz

doramon

  • บุคคลทั่วไป
Re: ขอคำแนะนำเกี่ยวกับ substring หน่อยครับ
« ตอบกลับ #1 เมื่อ: เมษายน 10, 2009, 21:12:59 PM »
0
LOCATE(substr,str), LOCATE(substr,str,pos)

The first syntax returns the position of the first occurrence of substring substr in string str. The second syntax returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str.

mysql> SELECT LOCATE('bar', 'foobarbar');
        -> 4
mysql> SELECT LOCATE('xbar', 'foobar');
        -> 0
mysql> SELECT LOCATE('bar', 'foobarbar', 5);
        -> 7


------------------------------
SUBSTRING(str,pos), SUBSTRING(str  FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str  FROM pos FOR len)

The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are standard SQL syntax. It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning. A negative value may be used for pos in any of the forms of this function.

For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.

mysql> SELECT SUBSTRING('Quadratically',5);
        -> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM 4);
        -> 'barbar'
mysql> SELECT SUBSTRING('Quadratically',5,6);
        -> 'ratica'       
mysql> SELECT SUBSTRING('Sakila', -3);
        -> 'ila'       
mysql> SELECT SUBSTRING('Sakila', -5, 3);
        -> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
        -> 'ki'
-------------------------------------------------------

สองอัน ใช้ด้วยกันก็ได้แล้วครับ

ออฟไลน์ howtodo

  • Hero Member
  • *****
  • กระทู้: 646
  • Respect: 0
    • ดูรายละเอียด
    • สื่อน้ำท่วม
Re: ขอคำแนะนำเกี่ยวกับ substring หน่อยครับ
« ตอบกลับ #2 เมื่อ: เมษายน 10, 2009, 22:10:57 PM »
0
หาช่องว่างตำแหน่งที่ 1
และตำแหน่งที่  2  แล้วใช้
substring
ขึ้นระบบ 2549  เข้ามารับช่วงต่อ ต.ค.50 - ส.ค.53 ไม่ครบ 3 ปี ขอบคุณสำหรับความรู้ ความเมตตา ความกรุณา ที่มีให้กับตัวข้าผู้ด้อยปัญญาด้วยดีตลอดมา

ออฟไลน์ howtodo

  • Hero Member
  • *****
  • กระทู้: 646
  • Respect: 0
    • ดูรายละเอียด
    • สื่อน้ำท่วม
Re: ขอคำแนะนำเกี่ยวกับ substring หน่อยครับ
« ตอบกลับ #3 เมื่อ: เมษายน 10, 2009, 22:13:52 PM »
0
document.getElementById("icd10").value = text; //รับค่าจากคลิก
           var  result;
              result = text.search("#");
       document.getElementById("post_diag").value = text.substring(0,result);//count code 
ขึ้นระบบ 2549  เข้ามารับช่วงต่อ ต.ค.50 - ส.ค.53 ไม่ครบ 3 ปี ขอบคุณสำหรับความรู้ ความเมตตา ความกรุณา ที่มีให้กับตัวข้าผู้ด้อยปัญญาด้วยดีตลอดมา